From: Eric Bollengier Date: Mon, 19 Feb 2007 11:51:46 +0000 (+0000) Subject: ebl add RecyclePool to Pool. Media will take Pool.RecyclePool X-Git-Tag: Release-7.0.0~6872 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f6d5bc0d2ba1dfbd5d8a782e3f7d0d1f4e2a0ef2;p=bacula%2Fbacula ebl add RecyclePool to Pool. Media will take Pool.RecyclePool 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 --- diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 6b77929e8c..139607ffc0 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -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 */ diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index e938c8988e..36ac5c56fb 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -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"), diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 9174a14d1a..00565450e8 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -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; } } diff --git a/bacula/src/cats/sql_update.c b/bacula/src/cats/sql_update.c index c4174369eb..09ff60c4d4 100644 --- a/bacula/src/cats/sql_update.c +++ b/bacula/src/cats/sql_update.c @@ -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); diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index a7c306ba34..c38ed5cab8 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -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: diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index 6cecf73937..b8f270f5cc 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -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; }; diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 44f4aba962..a7ce19d884 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -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 */ diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 93b3357d33..8b3c18fdaf 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -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 */ diff --git a/bacula/src/dird/ua_update.c b/bacula/src/dird/ua_update.c index 95157f8f72..f31c814939 100644 --- a/bacula/src/dird/ua_update.c +++ b/bacula/src/dird/ua_update.c @@ -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) {