/* 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,
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)
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)
{
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) {