]> git.sur5r.net Git - bacula/bacula/commitdiff
ebl Add new ScratchPool directive to Pool. Thanks to Graham
authorEric Bollengier <eric@eb.homelinux.org>
Wed, 28 Jan 2009 10:47:21 +0000 (10:47 +0000)
committerEric Bollengier <eric@eb.homelinux.org>
Wed, 28 Jan 2009 10:47:21 +0000 (10:47 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8407 91ce42f0-d328-0410-95d8-f526ca767f89

16 files changed:
bacula/src/cats/cats.h
bacula/src/cats/sql_create.c
bacula/src/cats/sql_get.c
bacula/src/cats/sql_update.c
bacula/src/dird/autoprune.c
bacula/src/dird/catreq.c
bacula/src/dird/dird.c
bacula/src/dird/dird_conf.c
bacula/src/dird/dird_conf.h
bacula/src/dird/next_vol.c
bacula/src/dird/protos.h
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_output.c
bacula/src/dird/ua_status.c
bacula/src/dird/ua_update.c
bacula/technotes-2.5

index 60c470876fa3101cadbefdb7079d7dac1cf76b15..baf8517b58c5f43e9e8f73885792d1ed255a1cf1 100644 (file)
@@ -898,6 +898,7 @@ struct POOL_DBR {
    uint32_t MaxVolFiles;              /* Max files on Volume */
    uint64_t MaxVolBytes;              /* Max bytes on Volume */
    DBId_t RecyclePoolId;              /* RecyclePool destination when media is purged */
+   DBId_t ScratchPoolId;              /* ScratchPool source when media is needed */
    char PoolType[MAX_NAME_LENGTH];
    char LabelFormat[MAX_NAME_LENGTH];
    /* Extra stuff not in DB */
index 998ccc6bf2ff04315ce59f07e8dd8eace9d902f1..422a0a6b429f259859779371a9bb0a5d17e3c67e 100644 (file)
@@ -170,7 +170,7 @@ bool
 db_create_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 {
    bool stat;        
-   char ed1[30], ed2[30], ed3[50], ed4[50];
+   char ed1[30], ed2[30], ed3[50], ed4[50], ed5[50];
 
    Dmsg0(200, "In create pool\n");
    db_lock(mdb);
@@ -192,8 +192,9 @@ db_create_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
    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,"
+"RecyclePoolId,ScratchPoolId) "
+"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,
@@ -204,7 +205,8 @@ db_create_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
                   pr->MaxVolJobs, pr->MaxVolFiles,
                   edit_uint64(pr->MaxVolBytes, ed3),
                   pr->PoolType, pr->LabelType, pr->LabelFormat,
-                  edit_int64(pr->RecyclePoolId,ed4));
+                  edit_int64(pr->RecyclePoolId,ed4),
+                  edit_int64(pr->ScratchPoolId,ed5));
    Dmsg1(200, "Create Pool: %s\n", mdb->cmd);
    if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create db Pool record %s failed: ERR=%s\n"),
index 4983ddedf559aee0d2045ca53ac0da765d2a8b70..dd6a29acfc7d40c9a598908264c807dbe9c0d718 100644 (file)
@@ -607,16 +607,15 @@ bool db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr)
       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);
    }
-
    if (QUERY_DB(jcr, mdb, mdb->cmd)) {
       mdb->num_rows = sql_num_rows(mdb);
       if (mdb->num_rows > 1) {
@@ -647,6 +646,7 @@ bool db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr)
             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;
          }
       }
index 535dbd11734f5833dcee2e93ce5ae8b33a52abbb..8c713aa70fe789809322fcf1714ea0bc90ad13fb 100644 (file)
@@ -260,7 +260,7 @@ int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
 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",
@@ -272,7 +272,8 @@ int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 "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',RecyclePoolId=%s,"
+"ScratchPoolId=%s WHERE PoolId=%s",
       pr->NumVols, pr->MaxVols, pr->UseOnce, pr->UseCatalog,
       pr->AcceptAnyVolume, edit_uint64(pr->VolRetention, ed1),
       edit_uint64(pr->VolUseDuration, ed2),
@@ -280,8 +281,7 @@ int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
       edit_uint64(pr->MaxVolBytes, ed3),
       pr->Recycle, pr->AutoPrune, pr->LabelType,
       pr->LabelFormat, edit_int64(pr->RecyclePoolId,ed5),
-      ed4);
-
+      edit_int64(pr->ScratchPoolId,ed6),ed4);
    stat = UPDATE_DB(jcr, mdb, mdb->cmd);
    db_unlock(mdb);
    return stat;
index 9632aeb3a5bd7aaf4acafd9ab70a6d4563e2de59..31f09167acbfba70000e6cfd33d1ac6b4d90646d 100644 (file)
@@ -122,7 +122,14 @@ void prune_volumes(JCR *jcr, bool InChanger, MEDIA_DBR *mr)
    } else {
       ed2[0] = 0;
    }
-   Dmsg1(100, "Scratch pool=%s\n", ed2);
+
+   if(mr->ScratchPoolId) {
+      edit_int64(mr->ScratchPoolId, ed3);
+      bstrncat(ed2, ed3, sizeof(ed2));
+      bstrncat(ed2, ",", sizeof(ed2));
+   }
+
+   Dmsg1(100, "Scratch pool(s)=%s\n", ed2);
    /*
     * ed2 ends up with scratch poolid and current poolid or
     *   just current poolid if there is no scratch pool 
index 69f9488eec7eb144c5be08c60c0d6ba14d0dc13a..aac92cf8faa9ef95a41da7e5a5d96b743e2aac0d 100644 (file)
@@ -143,6 +143,7 @@ void catalog_request(JCR *jcr, BSOCK *bs)
       if (ok) {
          mr.PoolId = pr.PoolId;
          mr.StorageId = jcr->wstore->StorageId;
+         mr.ScratchPoolId = pr.ScratchPoolId;
          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);
       }
index da5361b75308c15911f1ee07b438394bdbf4cdc6..edf4a650be912507c93a99294722cfba2b63fa5b 100644 (file)
@@ -957,7 +957,7 @@ static bool check_catalog()
           *   in that catalog.
           */
          if (!pool->catalog || pool->catalog == catalog) {
-            update_pool_recyclepool(NULL, db, pool);
+            update_pool_references(NULL, db, pool);
          }
       }
 
index 077ff4c7072685bda29b024b29975c4afa08ce56..5afe768a6d2ca188867bf727ad1a3a8ccbd5dd75 100644 (file)
@@ -397,6 +397,7 @@ static RES_ITEM pool_items[] = {
    {"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}
@@ -951,6 +952,9 @@ next_run:
       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());
       }
@@ -1385,6 +1389,7 @@ void save_resource(int type, RES_ITEM *items, int pass)
          /* 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;
          res->res_pool.catalog    = res_all.res_pool.catalog;
          break;
index 222afb9b7e2447c5cc60cdfd5c50f6e362a8f151..fea4ee029e7010261e090ba242c3206b2a1764e1 100644 (file)
@@ -562,6 +562,7 @@ public:
    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 source when requesting media */
    alist *CopyPool;                   /* List of copy pools */
    CAT *catalog;                      /* Catalog to be used */
    /* Methods */
index 904f4cf0cab4e79eed6b0b1f1620d21f30789ccc..462d4550237e8e14cc04d0e105fd4197fe8c62a4 100644 (file)
@@ -43,6 +43,7 @@
  *  Items needed:
  *   mr.PoolId must be set
  *   mr.StorageId should also be set
+ *   mr.ScratchPoolId could be set (used if create==true)
  *   jcr->wstore
  *   jcr->db
  *   jcr->pool
@@ -347,9 +348,13 @@ bool get_scratch_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr)
    P(mutex);
    /* 
     * Get Pool record for Scratch Pool
+    * choose between ScratchPoolId and Scratch
+    * db_get_pool_record will first try ScratchPoolId, 
+    * and then try the pool named Scratch
     */
    memset(&spr, 0, sizeof(spr));
    bstrncpy(spr.Name, "Scratch", sizeof(spr.Name));
+   spr.PoolId = mr->ScratchPoolId;
    if (db_get_pool_record(jcr, jcr->db, &spr)) {
       memset(&smr, 0, sizeof(smr));
       smr.PoolId = spr.PoolId;
index 7fa5ebfe44045ec8235017f355e52a9f61ede0a2..26e5d7194443bd8967e168c14061be9fe623135f 100644 (file)
@@ -197,9 +197,9 @@ enum e_pool_op {
 };
 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_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool);
+bool set_pooldbr_references(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_recyclepool(JCR *jcr, B_DB *db, POOL *pool);
+int update_pool_references(JCR *jcr, B_DB *db, POOL *pool);
 
 /* ua_input.c */
 int get_cmd(UAContext *ua, const char *prompt);
index 818e3dac7f0fe0e3fe110be47abb6f4c9fb5ead0..4371fe05a242a89a53dee2ba10db4ee3a53820b4 100644 (file)
@@ -565,12 +565,12 @@ void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op)
    }
 }
 
-/* set/update Pool.RecyclePoolId in Catalog */
-int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool)
+/* set/update Pool.RecyclePoolId and Pool.ScratchPoolId in Catalog */
+int update_pool_references(JCR *jcr, B_DB *db, POOL *pool)
 {
    POOL_DBR  pr;
 
-   if (!pool->RecyclePool) {
+   if (!pool->RecyclePool && !pool->ScratchPool) {
       return 1;
    }
 
@@ -583,7 +583,7 @@ int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool)
 
    set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE);
 
-   if (!set_pooldbr_recyclepoolid(jcr, db, &pr, pool)) {
+   if (!set_pooldbr_references(jcr, db, &pr, pool)) {
       return -1;                      /* error */
    }
 
@@ -593,10 +593,10 @@ int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool)
    return 1;
 }
 
-/* set POOL_DBR.RecyclePoolId from Pool resource 
+/* set POOL_DBR.RecyclePoolId and POOL_DBR.ScratchPoolId from Pool resource 
  * works with set_pooldbr_from_poolres
  */
-bool set_pooldbr_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool)
+bool set_pooldbr_references(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool)
 {
    POOL_DBR rpool;
    bool ret = true;
@@ -618,6 +618,24 @@ bool set_pooldbr_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool)
    } else {                    /* no RecyclePool used, set it to 0 */
       pr->RecyclePoolId = 0;
    }
+
+   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;
 }
 
@@ -642,12 +660,14 @@ int create_pool(JCR *jcr, B_DB *db, POOL *pool, e_pool_op op)
       /* Pool Exists */
       if (op == POOL_OP_UPDATE) {  /* update request */
          set_pooldbr_from_poolres(&pr, pool, op);
+         set_pooldbr_references(jcr, db, &pr, pool);
          db_update_pool_record(jcr, db, &pr);
       }
       return 0;                       /* exists */
    }
 
    set_pooldbr_from_poolres(&pr, pool, op);
+   set_pooldbr_references(jcr, db, &pr, pool);
 
    if (!db_create_pool_record(jcr, db, &pr)) {
       return -1;                      /* error */
index 1efb461a8f95d5a7b3719bf1c717bc6937cac31a..5c48755ea3b1d088d86850fea805f3e4fa4679a2 100644 (file)
@@ -523,6 +523,7 @@ static bool list_nextvol(UAContext *ua, int ndays)
       mr.PoolId = jcr->jr.PoolId;
       get_job_storage(&store, job, run);
       mr.StorageId = store.store->StorageId;
+      /* no need to set ScratchPoolId, since we use fnv_no_create_vol */
       if (!find_next_volume_for_append(jcr, &mr, 1, fnv_no_create_vol, fnv_prune)) {
          ua->error_msg(_("Could not find next Volume for Job %s (Pool=%s, Level=%s).\n"),
             job->name(), pr.Name, level_to_str(run->level));
index b430007d2248e53bd8874214c31199ed1bf82ca4..87c70f30ca509c219792f8c72fd042860965c3ac 100644 (file)
@@ -470,6 +470,7 @@ static void prt_runtime(UAContext *ua, sched_pkt *sp)
          mr.StorageId = sp->store->StorageId;
          jcr->wstore = sp->store;
          Dmsg0(250, "call find_next_volume_for_append\n");
+         /* no need to set ScratchPoolId, since we use fnv_no_create_vol */
          ok = find_next_volume_for_append(jcr, &mr, 1, fnv_no_create_vol, fnv_no_prune);
       }
       if (!ok) {
index e49ef67dc65201c18254e1ae0aab046fb1010a5a..e61f813954edfd66a04c49fc74e18863c0800a04 100644 (file)
@@ -840,7 +840,7 @@ static bool update_pool(UAContext *ua)
    }
 
    set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE); /* update */
-   set_pooldbr_recyclepoolid(ua->jcr, ua->db, &pr, pool);
+   set_pooldbr_references(ua->jcr, ua->db, &pr, pool);
 
    id = db_update_pool_record(ua->jcr, ua->db, &pr);
    if (id <= 0) {
index e8e6b75a8d28ffc34c140e690d82fb28fd883b8f..0b7ab88dfa0c13216d4bbc61aaf3e9a16840b4b5 100644 (file)
@@ -11,6 +11,7 @@ mixed priorities
 
 General:
 28Jan09
+ebl  Add new ScratchPool directive to Pool. Thanks to Graham
 ebl  Turn on db_get_file_list() single SQL because the failure
      was due to a full FS. And the accurate test fails with the
      other code.