[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bacula-devel] Multiple storage daemons - multiple scratch pools?


Hello,

Using bacula-2.2.8 (though I've had a brief look at SVN, and it seems the
same)...

I configured bacula with a single storage daemon, using disk file volumes.
I configured my pools to have RecyclePool = Scratch, with the intention that
the volumes would be recycled throughout all of the pools.

Eventually, I got this working, so I went on to the next step - having multiple
storage daemons in different locations.

I found that volumes would go through the Scratch pool, and be shared out
among all the different storage daemons. The effect would be that a file
would be left on disk in one location, whilst a new version of it would appear
in another.
This was clearly because I was using a global Scratch pool.

What I would like to do is set up an individual Scratch pool for each
of my storage devices, so that the media in one location stays in that
location.

After looking at the bacula code, it seems to me as if the configurable
Scratch pool feature was planned and it has nearly been implemented.
It is possible to set 'Pool Type = Scratch' in a Pool, and 'ScratchPoolId' is
a database field on Pools and Media - though it is always set to 0.
The current 'RecyclePoolId' tells media where they should go when they are
recycled, but Media are only drawn from the Pool specifically named 'Scratch'.
I've even come up with patches to the (2.2.8) code that seem to have the
ScratchPoolId working in the way that I assume it was intended.

So, my question is whether I am right in assuming that the ScratchPoolId on
Pools was intended to be used this way (to indicate a pool to draw media from),
or whether there is a reason (or reasons) that the implementation was not
finished. It seems more elegant than needing to give a different Media Type for
every different storage.

Graham.
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/cats/cats.h bacula-2.2.8.new/src/cats/cats.h
--- bacula-2.2.8.orig/src/cats/cats.h	2008-02-27 17:13:24.000000000 +0000
+++ bacula-2.2.8.new/src/cats/cats.h	2008-11-20 16:21:22.000000000 +0000
@@ -767,6 +767,7 @@
    uint32_t MaxVolJobs;               /* Max Jobs on Volume */
    uint32_t MaxVolFiles;              /* Max files on Volume */
    uint64_t MaxVolBytes;              /* Max bytes on Volume */
+   DBId_t ScratchPoolId;              /* ScratchPool source */
    DBId_t RecyclePoolId;              /* RecyclePool destination when media is purged */
    char PoolType[MAX_NAME_LENGTH];
    char LabelFormat[MAX_NAME_LENGTH];
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/cats/sql_create.c bacula-2.2.8.new/src/cats/sql_create.c
--- bacula-2.2.8.orig/src/cats/sql_create.c	2008-02-27 17:13:25.000000000 +0000
+++ bacula-2.2.8.new/src/cats/sql_create.c	2008-11-20 16:32:48.000000000 +0000
@@ -194,8 +194,8 @@
    Mmsg(mdb->cmd,
 "INSERT INTO Pool (Name,NumVols,MaxVols,UseOnce,UseCatalog,"
 "AcceptAnyVolume,AutoPrune,Recycle,VolRetention,VolUseDuration,"
-"MaxVolJobs,MaxVolFiles,MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId) "
-"VALUES ('%s',%u,%u,%d,%d,%d,%d,%d,%s,%s,%u,%u,%s,'%s',%d,'%s',%s)",
+"MaxVolJobs,MaxVolFiles,MaxVolBytes,PoolType,LabelType,LabelFormat,ScratchPoolId,RecyclePoolId) "
+"VALUES ('%s',%u,%u,%d,%d,%d,%d,%d,%s,%s,%u,%u,%s,'%s',%d,'%s',%s,%s)",
                   pr->Name,
                   pr->NumVols, pr->MaxVols,
                   pr->UseOnce, pr->UseCatalog,
@@ -206,6 +206,7 @@
                   pr->MaxVolJobs, pr->MaxVolFiles,
                   edit_uint64(pr->MaxVolBytes, ed3),
                   pr->PoolType, pr->LabelType, pr->LabelFormat,
+                  edit_int64(pr->ScratchPoolId,ed4),
                   edit_int64(pr->RecyclePoolId,ed4));
    Dmsg1(200, "Create Pool: %s\n", mdb->cmd);
    if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/cats/sql_get.c bacula-2.2.8.new/src/cats/sql_get.c
--- bacula-2.2.8.orig/src/cats/sql_get.c	2008-02-27 17:13:25.000000000 +0000
+++ bacula-2.2.8.new/src/cats/sql_get.c	2008-11-21 10:02:21.000000000 +0000
@@ -582,13 +582,13 @@
       Mmsg(mdb->cmd,
 "SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,"
 "AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId FROM Pool WHERE Pool.PoolId=%s", 
+"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId,ScratchPoolId FROM Pool WHERE Pool.PoolId=%s", 
          edit_int64(pdbr->PoolId, ed1));
    } else {                           /* find by name */
       Mmsg(mdb->cmd,
 "SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,"
 "AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId FROM Pool WHERE Pool.Name='%s'", 
+"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId,ScratchPoolId FROM Pool WHERE Pool.Name='%s'", 
          pdbr->Name);
    }
 
@@ -622,6 +622,7 @@
             pdbr->LabelType = str_to_int64(row[15]);
             bstrncpy(pdbr->LabelFormat, row[16]!=NULL?row[16]:"", sizeof(pdbr->LabelFormat));
             pdbr->RecyclePoolId = str_to_int64(row[17]);
+            pdbr->ScratchPoolId = str_to_int64(row[18]);
             ok = true;
          }
       }
@@ -637,6 +638,7 @@
          pdbr->NumVols = NumVols;
          db_update_pool_record(jcr, mdb, pdbr);
       }
+      Mmsg(mdb->errmsg, _("Pool %s: %d %d\n"), pdbr->Name, pdbr->RecyclePoolId, pdbr->ScratchPoolId);
    } else {
       Mmsg(mdb->errmsg, _("Pool record not found in Catalog.\n"));
    }
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/cats/sql_update.c bacula-2.2.8.new/src/cats/sql_update.c
--- bacula-2.2.8.orig/src/cats/sql_update.c	2008-11-20 14:37:16.000000000 +0000
+++ bacula-2.2.8.new/src/cats/sql_update.c	2008-11-20 16:27:45.000000000 +0000
@@ -278,7 +278,7 @@
 int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 {
    int stat;
-   char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50];
+   char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50], ed6[50];
 
    db_lock(mdb);
    Mmsg(mdb->cmd, "SELECT count(*) from Media WHERE PoolId=%s",
@@ -290,14 +290,16 @@
 "UPDATE Pool SET NumVols=%u,MaxVols=%u,UseOnce=%d,UseCatalog=%d,"
 "AcceptAnyVolume=%d,VolRetention='%s',VolUseDuration='%s',"
 "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s,Recycle=%d,"
-"AutoPrune=%d,LabelType=%d,LabelFormat='%s',RecyclePoolId=%s WHERE PoolId=%s",
+"AutoPrune=%d,LabelType=%d,LabelFormat='%s',ScratchPoolId=%s,RecyclePoolId=%s WHERE PoolId=%s",
       pr->NumVols, pr->MaxVols, pr->UseOnce, pr->UseCatalog,
       pr->AcceptAnyVolume, edit_uint64(pr->VolRetention, ed1),
       edit_uint64(pr->VolUseDuration, ed2),
       pr->MaxVolJobs, pr->MaxVolFiles,
       edit_uint64(pr->MaxVolBytes, ed3),
       pr->Recycle, pr->AutoPrune, pr->LabelType,
-      pr->LabelFormat, edit_int64(pr->RecyclePoolId,ed5),
+      pr->LabelFormat,
+      edit_int64(pr->ScratchPoolId,ed5),
+      edit_int64(pr->RecyclePoolId,ed6),
       ed4);
 
    stat = UPDATE_DB(jcr, mdb, mdb->cmd);
@@ -422,30 +424,32 @@
 db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
 {
    int stat;
-   char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50];
+   char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50], ed6[50];
 
 
    db_lock(mdb);
    if (mr->VolumeName[0]) {
       Mmsg(mdb->cmd, "UPDATE Media SET "
            "Recycle=%d,VolRetention=%s,VolUseDuration=%s,"
-           "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s,RecyclePoolId=%s"
+           "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s,ScratchPoolId=%s,RecyclePoolId=%s"
            " WHERE VolumeName='%s'",
            mr->Recycle,edit_uint64(mr->VolRetention, ed1),
            edit_uint64(mr->VolUseDuration, ed2),
            mr->MaxVolJobs, mr->MaxVolFiles,
            edit_uint64(mr->MaxVolBytes, ed3),
+           edit_uint64(mr->ScratchPoolId, ed6),
            edit_uint64(mr->RecyclePoolId, ed4),
            mr->VolumeName);
    } else {
       Mmsg(mdb->cmd, "UPDATE Media SET "
            "Recycle=%d,VolRetention=%s,VolUseDuration=%s,"
-           "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s,RecyclePoolId=%s"
+           "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s,ScratchPoolId=%s,RecyclePoolId=%s"
            " WHERE PoolId=%s",
            mr->Recycle,edit_uint64(mr->VolRetention, ed1),
            edit_uint64(mr->VolUseDuration, ed2),
            mr->MaxVolJobs, mr->MaxVolFiles,
            edit_uint64(mr->MaxVolBytes, ed3),
+           edit_int64(mr->ScratchPoolId, ed6),
            edit_int64(mr->RecyclePoolId, ed4),
            edit_int64(mr->PoolId, ed5));
    }
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/dird/autoprune.c bacula-2.2.8.new/src/dird/autoprune.c
--- bacula-2.2.8.orig/src/dird/autoprune.c	2008-11-18 17:28:47.000000000 +0000
+++ bacula-2.2.8.new/src/dird/autoprune.c	2008-11-21 14:03:06.000000000 +0000
@@ -96,7 +96,7 @@
    POOL_MEM query(PM_MESSAGE);
    UAContext *ua;
    bool ok = false;
-   char ed1[50], ed2[100], ed3[50];
+   char ed1[50], ed2[100], ed3[50], ed4[50];
    POOL_DBR spr;

    Dmsg1(050, "Prune volumes PoolId=%d\n", jcr->jr.PoolId); 
@@ -134,6 +134,13 @@
     */
    bstrncat(ed2, ed1, sizeof(ed2));
 
+   /* Also include the ScratchPoolId indicated */
+   if(mr->ScratchPoolId) {
+        edit_int64(mr->ScratchPoolId, ed4);
+        bstrncat(ed2, ",", sizeof(ed2));
+   	bstrncat(ed2, ed4, sizeof(ed2));
+   }
+
    /*
     * Get the List of all media ids in the current Pool or whose
     *  RecyclePoolId is the current pool or the scratch pool
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/dird/catreq.c bacula-2.2.8.new/src/dird/catreq.c
--- bacula-2.2.8.orig/src/dird/catreq.c	2008-02-27 17:13:25.000000000 +0000
+++ bacula-2.2.8.new/src/dird/catreq.c	2008-11-21 11:55:36.000000000 +0000
@@ -141,6 +141,7 @@
       ok = db_get_pool_record(jcr, jcr->db, &pr);
       if (ok) {
          mr.PoolId = pr.PoolId;
+         mr.ScratchPoolId = pr.ScratchPoolId;
          mr.StorageId = jcr->wstore->StorageId;
          ok = find_next_volume_for_append(jcr, &mr, index, fnv_create_vol, fnv_prune);
          Dmsg3(050, "find_media ok=%d idx=%d vol=%s\n", ok, index, mr.VolumeName);
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/dird/dird.c bacula-2.2.8.new/src/dird/dird.c
--- bacula-2.2.8.orig/src/dird/dird.c	2008-11-20 14:37:16.000000000 +0000
+++ bacula-2.2.8.new/src/dird/dird.c	2008-11-21 14:23:30.000000000 +0000
@@ -900,9 +900,10 @@
          create_pool(NULL, db, pool, POOL_OP_UPDATE);  /* update request */
       }
 
-      /* Loop over all pools for updating RecyclePool */
+      /* Loop over all pools for updating ScratchPool and RecyclePool */
       foreach_res(pool, R_POOL) {
          update_pool_recyclepool(NULL, db, pool);
+         update_pool_scratchpool(NULL, db, pool);
       }
 
       STORE *store;
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/dird/dird_conf.c bacula-2.2.8.new/src/dird/dird_conf.c
--- bacula-2.2.8.orig/src/dird/dird_conf.c	2008-02-27 17:13:25.000000000 +0000
+++ bacula-2.2.8.new/src/dird/dird_conf.c	2008-11-20 17:11:14.000000000 +0000
@@ -371,6 +371,7 @@
    {"autoprune",     store_bool,      ITEM(res_pool.AutoPrune), 0, ITEM_DEFAULT, true},
    {"recycle",       store_bool,      ITEM(res_pool.Recycle),   0, ITEM_DEFAULT, true},
    {"recyclepool",   store_res,       ITEM(res_pool.RecyclePool), R_POOL, 0, 0},
+   {"scratchpool",   store_res,       ITEM(res_pool.ScratchPool), R_POOL, 0, 0},
    {"copypool",      store_alist_res, ITEM(res_pool.CopyPool), R_POOL, 0, 0},
    {"catalog",       store_res,       ITEM(res_pool.Catalog), R_CATALOG, 0, 0},
    {NULL, NULL, {0}, 0, 0, 0}
@@ -883,6 +884,9 @@
       if (res->res_pool.RecyclePool) {
          sendit(sock, _("      RecyclePool=%s\n"), res->res_pool.RecyclePool->name());
       }
+      if (res->res_pool.ScratchPool) {
+         sendit(sock, _("      ScratchPool=%s\n"), res->res_pool.ScratchPool->name());
+      }
       if (res->res_pool.Catalog) {
          sendit(sock, _("      Catalog=%s\n"), res->res_pool.Catalog->name());
       }
@@ -1301,6 +1305,7 @@
          /* Explicitly copy resource pointers from this pass (res_all) */
          res->res_pool.NextPool = res_all.res_pool.NextPool;
          res->res_pool.RecyclePool = res_all.res_pool.RecyclePool;
+         res->res_pool.ScratchPool = res_all.res_pool.ScratchPool;
          res->res_pool.storage    = res_all.res_pool.storage;
          break;
       case R_CONSOLE:
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/dird/dird_conf.h bacula-2.2.8.new/src/dird/dird_conf.h
--- bacula-2.2.8.orig/src/dird/dird_conf.h	2008-02-27 17:13:25.000000000 +0000
+++ bacula-2.2.8.new/src/dird/dird_conf.h	2008-11-20 16:01:23.000000000 +0000
@@ -535,6 +535,7 @@
    bool  AutoPrune;                   /* default for pool auto prune */
    bool  Recycle;                     /* default for media recycle yes/no */
    POOL  *RecyclePool;                /* RecyclePool destination when media is purged */
+   POOL  *ScratchPool;                /* ScratchPool */
    alist *CopyPool;                   /* List of copy pools */
    CAT *Catalog;                      /* Catalog to be used */
    /* Methods */
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/dird/next_vol.c bacula-2.2.8.new/src/dird/next_vol.c
--- bacula-2.2.8.orig/src/dird/next_vol.c	2008-11-18 17:28:47.000000000 +0000
+++ bacula-2.2.8.new/src/dird/next_vol.c	2008-11-21 14:11:11.000000000 +0000
@@ -342,6 +342,9 @@
     */
    memset(&spr, 0, sizeof(spr));
    bstrncpy(spr.Name, "Scratch", sizeof(spr.Name));
+   spr.PoolId=mr->ScratchPoolId;
+
+   /* db_get_pool_record will first try ScratchPoolId, and then try the pool named Scratch */
    if (db_get_pool_record(jcr, jcr->db, &spr)) {
       memset(&smr, 0, sizeof(smr));
       smr.PoolId = spr.PoolId;
@@ -397,10 +400,11 @@
          /*
           * set_pool_dbr_defaults_in_media_dbr set VolStatus to Append,
           *   we could have Recycled media, also, we retain the old
-          *   RecyclePoolId.
+          *   RecyclePoolId and ScratchPoolId.
           */
          bstrncpy(mr->VolStatus, smr.VolStatus, sizeof(smr.VolStatus));
          mr->RecyclePoolId = smr.RecyclePoolId;
+         mr->ScratchPoolId = smr.ScratchPoolId;
 
          if (!db_update_media_record(jcr, jcr->db, mr)) {
             Jmsg(jcr, M_WARNING, 0, _("Failed to move Scratch Volume. ERR=%s\n"),
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/dird/protos.h bacula-2.2.8.new/src/dird/protos.h
--- bacula-2.2.8.orig/src/dird/protos.h	2008-02-27 17:13:25.000000000 +0000
+++ bacula-2.2.8.new/src/dird/protos.h	2008-11-20 16:46:05.000000000 +0000
@@ -186,8 +186,10 @@
 };
 int create_pool(JCR *jcr, B_DB *db, POOL *pool, e_pool_op op);
 void set_pool_dbr_defaults_in_media_dbr(MEDIA_DBR *mr, POOL_DBR *pr);
+bool set_pooldbr_scratchpoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool);
 bool set_pooldbr_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool);
 void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op);
+int update_pool_scratchpool(JCR *jcr, B_DB *db, POOL *pool);
 int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool);
 
 /* ua_input.c */
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/dird/ua_cmds.c bacula-2.2.8.new/src/dird/ua_cmds.c
--- bacula-2.2.8.orig/src/dird/ua_cmds.c	2008-02-27 17:13:25.000000000 +0000
+++ bacula-2.2.8.new/src/dird/ua_cmds.c	2008-11-21 13:58:43.000000000 +0000
@@ -201,6 +201,7 @@
    mr->Recycle = pr->Recycle;
    mr->VolRetention = pr->VolRetention;
    mr->VolUseDuration = pr->VolUseDuration;
+   mr->ScratchPoolId = pr->ScratchPoolId;
    mr->RecyclePoolId = pr->RecyclePoolId;
    mr->MaxVolJobs = pr->MaxVolJobs;
    mr->MaxVolFiles = pr->MaxVolFiles;
@@ -512,6 +513,8 @@
  *
  * Caution : RecyclePoolId isn't setup in this function.
  *           You can use set_pooldbr_recyclepoolid();
+ * Caution : ScratchPoolId isn't setup in this function.
+ *           You can use set_pooldbr_scratchpoolid();
  *
  */
 void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op)
@@ -546,6 +549,34 @@
    }
 }
 
+/* set/update Pool.ScratchPoolId in Catalog */
+int update_pool_scratchpool(JCR *jcr, B_DB *db, POOL *pool)
+{
+   POOL_DBR  pr;
+
+   if (!pool->ScratchPool) {
+      return 1;
+   }
+
+   memset(&pr, 0, sizeof(POOL_DBR));
+   bstrncpy(pr.Name, pool->name(), sizeof(pr.Name));
+
+   if (!db_get_pool_record(jcr, db, &pr)) {
+      return -1;                       /* not exists in database */
+   }
+
+   set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE);
+
+   if (!set_pooldbr_scratchpoolid(jcr, db, &pr, pool)) {
+      return -1;                      /* error */
+   }
+
+   if (!db_update_pool_record(jcr, db, &pr)) {
+      return -1;                      /* error */
+   }
+   return 1;
+}
+
 /* set/update Pool.RecyclePoolId in Catalog */
 int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool)
 {
@@ -574,6 +605,34 @@
    return 1;
 }
 
+/* set POOL_DBR.ScratchPoolId from Pool resource 
+ * works with set_pooldbr_from_poolres
+ */
+bool set_pooldbr_scratchpoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool)
+{
+   POOL_DBR rpool;
+   bool ret = true;
+
+   if (pool->ScratchPool) {
+      memset(&rpool, 0, sizeof(POOL_DBR));
+
+      bstrncpy(rpool.Name, pool->ScratchPool->name(), sizeof(rpool.Name));
+      if (db_get_pool_record(jcr, db, &rpool)) {
+        pr->ScratchPoolId = rpool.PoolId;
+      } else {
+        Jmsg(jcr, M_WARNING, 0,
+        _("Can't set %s ScratchPool to %s, %s is not in database.\n" \
+          "Try to update it with 'update pool=%s'\n"),
+        pool->name(), rpool.Name, rpool.Name,pool->name());
+
+        ret = false;
+      }
+   } else {                    /* no ScratchPool used, set it to 0 */
+      pr->ScratchPoolId = 0;
+   }
+   return ret;
+}
+
 /* set POOL_DBR.RecyclePoolId from Pool resource 
  * works with set_pooldbr_from_poolres
  */
@@ -623,12 +682,16 @@
       /* Pool Exists */
       if (op == POOL_OP_UPDATE) {  /* update request */
          set_pooldbr_from_poolres(&pr, pool, op);
+	 update_pool_scratchpool(jcr, db, pool);
+	 update_pool_recyclepool(jcr, db, pool);
          db_update_pool_record(jcr, db, &pr);
       }
       return 0;                       /* exists */
    }
 
    set_pooldbr_from_poolres(&pr, pool, op);
+   update_pool_scratchpool(jcr, db, pool);
+   update_pool_recyclepool(jcr, db, pool);
 
    if (!db_create_pool_record(jcr, db, &pr)) {
       return -1;                      /* error */
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/dird/ua_output.c bacula-2.2.8.new/src/dird/ua_output.c
--- bacula-2.2.8.orig/src/dird/ua_output.c	2008-10-28 18:07:19.000000000 +0000
+++ bacula-2.2.8.new/src/dird/ua_output.c	2008-11-21 12:00:05.000000000 +0000
@@ -533,6 +533,7 @@
          bstrncpy(pr.Name, "*UnknownPool*", sizeof(pr.Name));
       }
       mr.PoolId = jcr->jr.PoolId;
+      mr.ScratchPoolId = pr.ScratchPoolId;
       get_job_storage(&store, job, run);
       mr.StorageId = store.store->StorageId;
       if (!find_next_volume_for_append(jcr, &mr, 1, fnv_no_create_vol, fnv_prune)) {
diff --exclude CVS --exclude '\.*' -ru bacula-2.2.8.orig/src/dird/ua_update.c bacula-2.2.8.new/src/dird/ua_update.c
--- bacula-2.2.8.orig/src/dird/ua_update.c	2008-02-27 17:13:25.000000000 +0000
+++ bacula-2.2.8.new/src/dird/ua_update.c	2008-11-20 17:17:50.000000000 +0000
@@ -328,6 +328,32 @@
    db_unlock(ua->db);
 }
 
+/* Modify the ScratchPool of a Volume */
+void update_vol_scratchpool(UAContext *ua, char *val, MEDIA_DBR *mr)
+{
+   POOL_DBR pr;
+   POOL_MEM query(PM_MESSAGE);
+   char ed1[50], ed2[50];
+
+   memset(&pr, 0, sizeof(pr));
+   bstrncpy(pr.Name, val, sizeof(pr.Name));
+   if (!get_pool_dbr(ua, &pr, NT_("recyclepool"))) {
+      return;
+   }
+   /* pool = select_pool_resource(ua);  */
+   mr->ScratchPoolId = pr.PoolId;            /* get the PoolId */
+
+   db_lock(ua->db);
+   Mmsg(query, "UPDATE Media SET ScratchPoolId=%s WHERE MediaId=%s",
+      edit_int64(mr->ScratchPoolId, ed1), edit_int64(mr->MediaId, ed2));
+   if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) {
+      ua->error_msg("%s", db_strerror(ua->db));
+   } else {
+      ua->info_msg(_("New ScratchPool is: %s\n"), pr.Name);
+   }
+   db_unlock(ua->db);
+}
+
 /* Modify the RecyclePool of a Volume */
 void update_vol_recyclepool(UAContext *ua, char *val, MEDIA_DBR *mr)
 {
@@ -448,6 +474,7 @@
       NT_("AllFromPool"),              /* 11 !!! see below !!! */
       NT_("Enabled"),                  /* 12 */
       NT_("RecyclePool"),              /* 13 */
+      NT_("ScratchPool"),              /* 14 */
       NULL };
 
 #define AllFromPool 11               /* keep this updated with above */
@@ -509,6 +536,9 @@
          case 13:
             update_vol_recyclepool(ua, ua->argv[j], &mr);
             break;
+         case 14:
+            update_vol_scratchpool(ua, ua->argv[j], &mr);
+            break;
          }
          done = true;
       }
@@ -531,11 +561,12 @@
       add_prompt(ua, _("All Volumes from Pool"));      /* 12 */
       add_prompt(ua, _("Enabled")),                    /* 13 */
       add_prompt(ua, _("RecyclePool")),                /* 14 */
-      add_prompt(ua, _("Done"));                       /* 15 */
+      add_prompt(ua, _("ScratchPool")),                /* 15 */
+      add_prompt(ua, _("Done"));                       /* 16 */
       i = do_prompt(ua, "", _("Select parameter to modify"), NULL, 0);  
 
       /* For All Volumes from Pool and Done, we don't need a Volume record */
-      if (i != 12 && i != 15) {
+      if (i != 12 && i != 16) {
          if (!select_media_dbr(ua, &mr)) {  /* Get Volume record */
             return 0;
          }
@@ -722,6 +753,20 @@
          update_vol_recyclepool(ua, ua->cmd, &mr);
          return 1;
 
+      case 15:
+         memset(&pr, 0, sizeof(POOL_DBR));
+         pr.PoolId = mr.ScratchPoolId;
+         if (db_get_pool_record(ua->jcr, ua->db, &pr)) {
+            ua->info_msg(_("Current ScratchPool is: %s\n"), pr.Name);
+         } else {
+            ua->warning_msg(_("No current ScratchPool\n"));
+         }
+         if (!get_cmd(ua, _("Enter new ScratchPool name: "))) {
+            return 0;
+         }
+         update_vol_scratchpool(ua, ua->cmd, &mr);
+         return 1;
+
       default:                        /* Done or error */
          ua->info_msg(_("Selection terminated.\n"));
          return 1;
@@ -753,6 +798,7 @@
    }
 
    set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE); /* update */
+   set_pooldbr_scratchpoolid(ua->jcr, ua->db, &pr, pool);
    set_pooldbr_recyclepoolid(ua->jcr, ua->db, &pr, pool);
 
    id = db_update_pool_record(ua->jcr, ua->db, &pr);
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Bacula-devel mailing list
Bacula-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/bacula-devel


This mailing list archive is a service of Copilotco.