2 This patch should fix (not tested) the recycling bug #1106 when using
3 two autochangers. There is a much smaller chance that it also fixes
4 bug #1103 where a volume is recycled when it is full.
6 Apply the patch to version 2.4.0 with:
9 patch -p0 <2.4.0-recycle.patch
10 ./configure <your-options>
17 Index: src/dird/autoprune.c
18 ===================================================================
19 --- src/dird/autoprune.c (revision 7178)
20 +++ src/dird/autoprune.c (working copy)
22 POOL_MEM query(PM_MESSAGE);
25 - char ed1[50], ed2[100];
26 + char ed1[50], ed2[100], ed3[50];
29 Dmsg1(050, "Prune volumes PoolId=%d\n", jcr->jr.PoolId);
31 * RecyclePoolId is the current pool or the scratch pool
33 const char *select = "SELECT DISTINCT MediaId,LastWritten FROM Media WHERE "
34 - "(PoolId=%s OR RecyclePoolId IN (%s)) AND MediaType='%s' "
35 + "(PoolId=%s OR RecyclePoolId IN (%s)) AND MediaType='%s' %s"
36 "ORDER BY LastWritten ASC,MediaId";
38 - Mmsg(query, select, ed1, ed2, mr->MediaType);
41 + /* Ensure it is in this autochanger */
42 + bsnprintf(changer, sizeof(changer), "AND InChanger=1 AND StorageId=%s ",
43 + edit_int64(mr->StorageId, ed3));
44 + Mmsg(query, select, ed1, ed2, mr->MediaType, changer);
46 + Mmsg(query, select, ed1, ed2, mr->MediaType, "");
49 Dmsg1(050, "query=%s\n", query.c_str());
50 if (!db_get_query_dbids(ua->jcr, ua->db, query, ids)) {
51 Index: src/dird/recycle.c
52 ===================================================================
53 --- src/dird/recycle.c (revision 7178)
54 +++ src/dird/recycle.c (working copy)
57 "SELECT MediaId,LastWritten FROM Media "
58 "WHERE PoolId=%s AND Recycle=1 AND VolStatus='Purged' "
59 - "AND Enabled=1 AND MediaType='%s' "
60 + "AND Enabled=1 AND MediaType='%s' %s"
61 "ORDER BY LastWritten ASC,MediaId LIMIT 1";
63 Dmsg0(100, "Enter recycle_oldest_purged_volume\n");
65 - Mmsg(query, select, edit_int64(mr->PoolId, ed1), mr->MediaType);
68 + bsnprintf(changer, sizeof(changer), "AND InChanger=1 AND StorageId=%s ",
69 + edit_int64(mr->StorageId, ed1));
70 + Mmsg(query, select, edit_int64(mr->PoolId, ed1), mr->MediaType, changer);
72 + Mmsg(query, select, edit_int64(mr->PoolId, ed1), mr->MediaType, "");
75 if (!db_sql_query(jcr->db, query, oldest_handler, (void *)&oldest)) {
76 Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));