]> git.sur5r.net Git - bacula/bacula/commitdiff
ebl add RecyclePool to Pool. Media will take Pool.RecyclePool
authorEric Bollengier <eric@eb.homelinux.org>
Mon, 19 Feb 2007 11:51:46 +0000 (11:51 +0000)
committerEric Bollengier <eric@eb.homelinux.org>
Mon, 19 Feb 2007 11:51:46 +0000 (11:51 +0000)
     when moving from Scratch to a Pool or when user will do
     update volume=xxx frompool
     To use it, add RecyclePool = aPool to your Pool resource
Pool {
Name = Default
RecyclePool = Scratch
...
}

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4205 91ce42f0-d328-0410-95d8-f526ca767f89

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/dird_conf.c
bacula/src/dird/dird_conf.h
bacula/src/dird/protos.h
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_update.c

index 6b77929e8cae0e4a5d4fd551c89d269657d4d362..139607ffc0e7c8a9acff4171766a8286baf98dd7 100644 (file)
@@ -734,6 +734,7 @@ struct POOL_DBR {
    uint32_t MaxVolJobs;               /* Max Jobs on Volume */
    uint32_t MaxVolFiles;              /* Max files on Volume */
    uint64_t MaxVolBytes;              /* Max bytes on Volume */
+   DBId_t RecyclePoolId;              /* RecyclePool destination when media is purged */
    char PoolType[MAX_NAME_LENGTH];
    char LabelFormat[MAX_NAME_LENGTH];
    /* Extra stuff not in DB */
index e938c8988ec8e3ffb96545389fe653fdb2c69aa4..36ac5c56fbd760d157c54dcdad565cefab4ba098 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];
+   char ed1[30], ed2[30], ed3[50], ed4[50];
 
    Dmsg0(200, "In create pool\n");
    db_lock(mdb);
@@ -192,8 +192,8 @@ 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) "
-"VALUES ('%s',%u,%u,%d,%d,%d,%d,%d,%s,%s,%u,%u,%s,'%s',%d,'%s')",
+"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)",
                   pr->Name,
                   pr->NumVols, pr->MaxVols,
                   pr->UseOnce, pr->UseCatalog,
@@ -203,7 +203,8 @@ db_create_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
                   edit_uint64(pr->VolUseDuration, ed2),
                   pr->MaxVolJobs, pr->MaxVolFiles,
                   edit_uint64(pr->MaxVolBytes, ed3),
-                  pr->PoolType, pr->LabelType, pr->LabelFormat);
+                  pr->PoolType, pr->LabelType, pr->LabelFormat,
+                  edit_int64(pr->RecyclePoolId,ed4));
    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 9174a14d1a39068e03830f04733c663a7c3cd4c5..00565450e899bd5343091e90ac7f4cab29769f23 100644 (file)
@@ -574,13 +574,13 @@ 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 FROM Pool WHERE Pool.PoolId=%s", 
+"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId 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 FROM Pool WHERE Pool.Name='%s'", 
+"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId FROM Pool WHERE Pool.Name='%s'", 
          pdbr->Name);
    }
 
@@ -613,6 +613,7 @@ bool db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr)
             bstrncpy(pdbr->PoolType, row[14]!=NULL?row[14]:"", sizeof(pdbr->PoolType));
             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]);
             ok = true;
          }
       }
index c4174369eb08296b5586975e95fe01079917be4a..09ff60c4d4558d3ab7fd5e6564448117f86bc6d7 100644 (file)
@@ -255,7 +255,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];
+   char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50];
 
    db_lock(mdb);
    Mmsg(mdb->cmd, "SELECT count(*) from Media WHERE PoolId=%s",
@@ -267,14 +267,14 @@ 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' WHERE PoolId=%s",
+"AutoPrune=%d,LabelType=%d,LabelFormat='%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, 
+      pr->LabelFormat, edit_int64(pr->RecyclePoolId,ed5),
       ed4);
 
    stat = UPDATE_DB(jcr, mdb, mdb->cmd);
index a7c306ba34b3d27f66b62f72f72cce8caa27386c..c38ed5cab8bb503766c399860897856ec0c19250 100644 (file)
@@ -361,7 +361,7 @@ static RES_ITEM pool_items[] = {
    {"storage",       store_alist_res, ITEM(res_pool.storage),  R_STORAGE, 0, 0},
    {"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},
+   {"recyclepool",     store_res,     ITEM(res_pool.RecyclePool), R_POOL, 0, 0},
    {NULL, NULL, {0}, 0, 0, 0}
 };
 
@@ -854,7 +854,10 @@ next_run:
               edit_uint64(res->res_pool.MigrationHighBytes, ed2),
               edit_uint64(res->res_pool.MigrationLowBytes, ed3));
       if (res->res_pool.NextPool) {
-         sendit(sock, _("      NextPool=%s\n"), res->res_pool.NextPool->hdr.name);
+         sendit(sock, _("      NextPool=%s\n"), res->res_pool.NextPool->name());
+      }
+      if (res->res_pool.RecyclePool) {
+         sendit(sock, _("      RecyclePool=%s\n"), res->res_pool.RecyclePool->name());
       }
       if (res->res_pool.storage) {
          STORE *store;
@@ -1245,6 +1248,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.storage    = res_all.res_pool.storage;
          break;
       case R_CONSOLE:
index 6cecf73937a0a3fcf2bf827b9cadfdf7b30ecd8e..b8f270f5ccc1daeebbe04e7118f8e04b1d5056b4 100644 (file)
@@ -523,7 +523,7 @@ public:
    bool  recycle_current_volume;      /* attempt recycle of current volume */
    bool  AutoPrune;                   /* default for pool auto prune */
    bool  Recycle;                     /* default for media recycle yes/no */
-
+   POOL  *RecyclePool;                /* RecyclePool destination when media is purged */
    /* Methods */
    char *name() const;
 };
index 44f4aba962597bf9412cfc0587695aab73af9536..a7ce19d8842eafabe0f50de2f66cebe80ffca135 100644 (file)
@@ -180,6 +180,7 @@ 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);
 void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op);
 
 /* ua_input.c */
index 93b3357d33b8bcd40f304e7587cb539769205e9c..8b3c18fdafa86e0769b7b708b9404f63d7bed070 100644 (file)
@@ -194,6 +194,7 @@ void set_pool_dbr_defaults_in_media_dbr(MEDIA_DBR *mr, POOL_DBR *pr)
    mr->Recycle = pr->Recycle;
    mr->VolRetention = pr->VolRetention;
    mr->VolUseDuration = pr->VolUseDuration;
+   mr->RecyclePoolId = pr->RecyclePoolId;
    mr->MaxVolJobs = pr->MaxVolJobs;
    mr->MaxVolFiles = pr->MaxVolFiles;
    mr->MaxVolBytes = pr->MaxVolBytes;
@@ -493,7 +494,11 @@ static int cancel_cmd(UAContext *ua, const char *cmd)
  *   Pool DB base record from a Pool Resource. We handle
  *   the setting of MaxVols and NumVols slightly differently
  *   depending on if we are creating the Pool or we are
- *   simply bringing it into agreement with the resource (updage).
+ *   simply bringing it into agreement with the resource (update).
+ *
+ * Caution : RecyclePoolId isn't setup in this function.
+ *           You can use set_pooldbr_recyclepoolid();
+ * 
  */
 void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op)
 {
@@ -527,6 +532,28 @@ void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op)
    }
 }
 
+bool set_pooldbr_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool)
+{
+   POOL_DBR rpool;
+   bool ret = true;
+
+   if (pool->RecyclePool) {
+      memset(&rpool, 0, sizeof(POOL_DBR));
+
+      bstrncpy(rpool.Name, pool->RecyclePool->name(), sizeof(rpool.Name));
+      if (db_get_pool_record(jcr, db, &rpool)) {
+        pr->RecyclePoolId = rpool.PoolId;
+      } else {
+        Jmsg(jcr, M_WARNING, 0, 
+             _("Can't set %s RecyclePool to %s, %s is not in database, try to update it with 'update pool=%s'\n"),pool->name(),rpool.Name, rpool.Name,pool->name());
+        
+        ret = false;
+      }
+   } else {                    /* no RecyclePool used, set it to 0 */
+      pr->RecyclePoolId = 0;
+   }
+   return ret;
+}
 
 /*
  * Create a pool record from a given Pool resource
@@ -554,6 +581,7 @@ int create_pool(JCR *jcr, B_DB *db, POOL *pool, e_pool_op op)
    }
 
    set_pooldbr_from_poolres(&pr, pool, op);
+   set_pooldbr_recyclepoolid(jcr, db, &pr, pool);
 
    if (!db_create_pool_record(jcr, db, &pr)) {
       return -1;                      /* error */
index 95157f8f7222ee33e6f5c85d24816f8e717ccbb1..f31c814939cd9b3ddaf54f391bced0e88b9fa313 100644 (file)
@@ -744,6 +744,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);
 
    id = db_update_pool_record(ua->jcr, ua->db, &pr);
    if (id <= 0) {