From: Eric Bollengier Date: Wed, 1 Jun 2022 14:54:57 +0000 (+0200) Subject: Add support for PriorJob with VirtualFull to support specific plugins X-Git-Tag: Beta-15.0.0~562 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0bbd817ece828d8a95fe730649f3656d0b05ac14;p=thirdparty%2Fbacula.git Add support for PriorJob with VirtualFull to support specific plugins --- diff --git a/bacula/src/cats/bdb.h b/bacula/src/cats/bdb.h index b1b8bf1d7..27589685f 100644 --- a/bacula/src/cats/bdb.h +++ b/bacula/src/cats/bdb.h @@ -219,6 +219,7 @@ public: /* sql_get.c */ char *bdb_get_jobids(const char *jobids, POOLMEM **ret, bool append); + bool bdb_get_prior_job(JCR *jcr, const char *jobids, JOB_DBR *jr); bool bdb_get_file_record(JCR *jcr, JOB_DBR *jr, FILE_DBR *fdbr); bool bdb_get_snapshot_record(JCR *jcr, SNAPSHOT_DBR *snap); bool bdb_get_volume_jobids(JCR *jcr, diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 08e69b9fe..f57c18bd5 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -240,7 +240,9 @@ void bdb_free_restoreobject_record(JCR *jcr, ROBJECT_DBR *rr); mdb->bdb_get_counter_record(jcr, cr) #define db_get_query_dbids(jcr, mdb, query, ids) \ mdb->bdb_get_query_dbids(jcr, query, ids) -#define db_get_file_list(jcr, mdb, jobids, opts, result_handler, ctx) \ +#define db_get_prior_job(jcr, mdb, jobids, jr) \ + mdb->bdb_get_prior_job(jcr, jobids, jr) +#define db_get_file_list(jcr, mdb, jobids, opts, result_handler, ctx) \ mdb->bdb_get_file_list(jcr, jobids, opts, result_handler, ctx) #define db_get_base_jobid(jcr, mdb, jr, jobid) \ mdb->bdb_get_base_jobid(jcr, jr, jobid) diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index c796c5941..fe4109c49 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1696,6 +1696,41 @@ bail_out: return ret; } +static int db_prior_job_handler(void *ctx, int num_fields, char **row) +{ + JOB_DBR *jr = (JOB_DBR*) ctx; + jr->PriorJobId = 0; + *jr->PriorJob = 0; + + if (num_fields == 2) { + jr->PriorJobId = str_to_uint64(row[0]); + bstrncpy(jr->PriorJob, row[1], sizeof(jr->PriorJob)); + } + return 0; +} + +/* Function to assign the PriorJob, PriorJobid to the current job after a VirtualFull */ +bool BDB::bdb_get_prior_job(JCR *jcr, const char *jobids, JOB_DBR *jr) +{ + bool ret=false; + bdb_lock(); + Mmsg(cmd, "SELECT PriorJobId, PriorJob FROM Job WHERE JobId IN (%s) ORDER By JobTDate DESC LIMIT 1", jobids); + if(!bdb_sql_query(cmd, db_prior_job_handler, jr)) { + goto bail_out; + } + if (jr->PriorJobId == 0) { // If we just copied a Full, we can use it directly + Mmsg(cmd, "SELECT JobId, Job FROM Job WHERE JobId IN (%s) ORDER BY JobTDate DESC LIMIT 1", jobids); + if(!bdb_sql_query(cmd, db_prior_job_handler, jr)) { + goto bail_out; + } + } + Dmsg2(0, "PriorJobId=%lu PriorJob=%s\n", jr->PriorJobId, jr->PriorJob); + ret = true; +bail_out: + bdb_unlock(); + return ret; +} + bool BDB::bdb_get_base_file_list(JCR *jcr, bool use_md5, DB_RESULT_HANDLER *result_handler, void *ctx) { diff --git a/bacula/src/dird/vbackup.c b/bacula/src/dird/vbackup.c index 6a206706e..8ed0a29ae 100644 --- a/bacula/src/dird/vbackup.c +++ b/bacula/src/dird/vbackup.c @@ -383,9 +383,16 @@ _("This Job is not an Accurate backup so is not equivalent to a Full backup.\n") return false; } + /* Waiting to copy objects with the BSR like RestoreObjects, we use SQL */ if (!copy_object_list(jcr, jobids.list, jcr->JobId)) { - Jmsg(jcr, M_ERROR, 0, "Unable to copy objects ERR=%s\n", jcr->db_batch->errmsg); + Jmsg(jcr, M_ERROR, 0, _("Unable to copy objects ERR=%s\n"), jcr->db_batch->errmsg); + } + + /* For some plugins, we need to maintain the PriorJob and PriorJobId for the new job */ + if (!db_get_prior_job(jcr, jcr->db_batch, jobids.list, &jcr->jr)) { + Jmsg(jcr, M_ERROR, 0, _("Unable to find or set the PriorJob information to the new Job record ERR=%s\n"), + jcr->db_batch->errmsg); } if (jcr->JobStatus != JS_Terminated) {