]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/2.4.0-recycle.patch
ebl Backport of the btraceback script that keeps trace file on working dir
[bacula/bacula] / bacula / patches / 2.4.0-recycle.patch
1
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.    
5
6  Apply the patch to version 2.4.0 with:
7
8  cd <bacula-source>
9  patch -p0 <2.4.0-recycle.patch
10  ./configure <your-options>
11  make
12  ...
13  make install
14
15   
16
17 Index: src/dird/autoprune.c
18 ===================================================================
19 --- src/dird/autoprune.c        (revision 7178)
20 +++ src/dird/autoprune.c        (working copy)
21 @@ -96,7 +96,7 @@
22     POOL_MEM query(PM_MESSAGE);
23     UAContext *ua;
24     bool ok = false;
25 -   char ed1[50], ed2[100];
26 +   char ed1[50], ed2[100], ed3[50];
27     POOL_DBR spr;
28  
29     Dmsg1(050, "Prune volumes PoolId=%d\n", jcr->jr.PoolId);
30 @@ -138,10 +138,18 @@
31      *  RecyclePoolId is the current pool or the scratch pool
32      */
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";
37  
38 -   Mmsg(query, select, ed1, ed2, mr->MediaType);
39 +   if (InChanger) {
40 +      char changer[100];
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);
45 +   } else {
46 +      Mmsg(query, select, ed1, ed2, mr->MediaType, "");
47 +   }
48  
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)
55 @@ -83,12 +83,19 @@
56     const char *select =
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";
62  
63     Dmsg0(100, "Enter recycle_oldest_purged_volume\n");
64     oldest.MediaId = 0;
65 -   Mmsg(query, select, edit_int64(mr->PoolId, ed1), mr->MediaType);
66 +   if (InChanger) {
67 +      char changer[100];
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);
71 +   } else {
72 +      Mmsg(query, select, edit_int64(mr->PoolId, ed1), mr->MediaType, "");
73 +   }
74  
75     if (!db_sql_query(jcr->db, query, oldest_handler, (void *)&oldest)) {
76        Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));