]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add support for PriorJob with VirtualFull to support specific plugins
authorEric Bollengier <eric@baculasystems.com>
Wed, 1 Jun 2022 14:54:57 +0000 (16:54 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:58 +0000 (13:56 +0200)
bacula/src/cats/bdb.h
bacula/src/cats/protos.h
bacula/src/cats/sql_get.c
bacula/src/dird/vbackup.c

index b1b8bf1d7d6131dbbbba6963de047c03d0968321..27589685ff6b02c3120486b30b95dfed684a631a 100644 (file)
@@ -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,
index 08e69b9fe7789732c08927c6a2f2ffa1ca2e038a..f57c18bd5a9c7832fd7ee10062e083ca911c0647 100644 (file)
@@ -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)
index c796c59416f7d013b085a457a6b09b9799d0b184..fe4109c490127f6cb87bca4f0a9cd8a51d0fd318 100644 (file)
@@ -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)
 {
index 6a206706e4a7f295a5c30642ff58fc1d2bc43058..8ed0a29ae3f8a3c831ba7bc31c1983c7a13b8ed5 100644 (file)
@@ -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) {