]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Update PriorJob and PriorJobId in db_update_job_start_record()
authorEric Bollengier <eric@baculasystems.com>
Wed, 30 Aug 2023 07:42:18 +0000 (09:42 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:02 +0000 (13:57 +0200)
bacula/src/cats/sql_update.c
bacula/src/dird/mac.c

index 2b7f1d5ac3d28bb492a83895761cc661e4743d79..602912703b7d3e9ac4416b7665d9f4b7a7f8fa8a 100644 (file)
@@ -93,6 +93,7 @@ bool BDB::bdb_update_job_start_record(JCR *jcr, JOB_DBR *jr)
    btime_t JobTDate;
    int stat;
    char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50];
+   char PriorJobId[50];
 
    stime = jr->StartTime;
    (void)localtime_r(&stime, &tm);
@@ -105,12 +106,19 @@ bool BDB::bdb_update_job_start_record(JCR *jcr, JOB_DBR *jr)
    if (!is_name_valid(jr->LastReadDevice, NULL)) {
       *jr->LastReadDevice = 0;     // Not valid, not used
    }
-   
+
+   if (jr->PriorJobId) {
+      bstrncpy(PriorJobId, edit_int64(jr->PriorJobId, ed1), sizeof(PriorJobId));
+   } else {
+      bstrncpy(PriorJobId, "0", sizeof(PriorJobId));
+   }
+
    bdb_lock();
    Mmsg(cmd, "UPDATE Job SET JobStatus='%c',Level='%c',StartTime='%s',"
         "ClientId=%s,JobTDate=%s,PoolId=%s,FileSetId=%s,RealStartTime='%s',"
         "isVirtualFull=%d,LastReadStorageId=%d,LastReadDevice='%s',"
-        "WriteStorageId=%d,WriteDevice='%s',StatusInfo='%s',Encrypted=%d WHERE JobId=%s",
+        "WriteStorageId=%d,WriteDevice='%s',StatusInfo='%s',Encrypted=%d,PriorJobId=%s,PriorJob='%s' "
+        "WHERE JobId=%s",
       (char)(jcr->JobStatus),
       (char)(jr->JobLevel), dt,
       edit_int64(jr->ClientId, ed1),
@@ -125,6 +133,8 @@ bool BDB::bdb_update_job_start_record(JCR *jcr, JOB_DBR *jr)
       jr->WriteDevice,
       jr->StatusInfo,
       jr->Encrypted,
+      PriorJobId,
+      jr->PriorJob,
       edit_int64(jr->JobId, ed5));
 
    stat = UpdateDB(jcr, cmd, false);
@@ -174,13 +184,6 @@ int BDB::bdb_update_job_end_record(JCR *jcr, JOB_DBR *jr)
    int stat;
    char ed1[30], ed2[30], ed3[50], ed4[50], ed5[50], ed6[50];
    btime_t JobTDate;
-   char PriorJobId[50];
-
-   if (jr->PriorJobId) {
-      bstrncpy(PriorJobId, edit_int64(jr->PriorJobId, ed1), sizeof(PriorJobId));
-   } else {
-      bstrncpy(PriorJobId, "0", sizeof(PriorJobId));
-   }
 
    ttime = jr->EndTime;
    (void)localtime_r(&ttime, &tm);
@@ -203,14 +206,14 @@ int BDB::bdb_update_job_end_record(JCR *jcr, JOB_DBR *jr)
       "UPDATE Job SET JobStatus='%c',EndTime='%s',"
 "ClientId=%u,JobBytes=%s,ReadBytes=%s,JobFiles=%u,JobErrors=%u,VolSessionId=%u,"
 "VolSessionTime=%u,PoolId=%u,FileSetId=%u,JobTDate=%s,"
-"RealEndTime='%s',PriorJobId=%s,HasBase=%u,PurgedFiles=%u,PriorJob='%s',"
+"RealEndTime='%s',HasBase=%u,PurgedFiles=%u,"
 "Rate=%.1f,CompressRatio=%.1f,WriteStorageId=%s,LastReadStorageId=%s,StatusInfo='%s',"
 "LastReadDevice='%s',WriteDevice='%s',Encrypted=%d WHERE JobId=%s",
       (char)(jr->JobStatus), dt, jr->ClientId, edit_uint64(jr->JobBytes, ed1),
       edit_uint64(jr->ReadBytes, ed4),
       jr->JobFiles, jr->JobErrors, jr->VolSessionId, jr->VolSessionTime,
       jr->PoolId, jr->FileSetId, edit_uint64(JobTDate, ed2),
-      rdt, PriorJobId, jr->HasBase, jr->PurgedFiles, jr->PriorJob,
+      rdt, jr->HasBase, jr->PurgedFiles,
       jr->Rate, jr->CompressRatio, edit_uint64(jr->WriteStorageId, ed5),
       edit_uint64(jr->LastReadStorageId, ed6), esc1, esc2, esc3,
       jr->Encrypted,
index c47c65dd6989828149bc77310f0ebedda4cec534..a4a317b9946edf4cc9bdd845f60a4589c70b3328 100644 (file)
@@ -638,6 +638,12 @@ bool do_mac(JCR *jcr)
    wjcr->jr.JobTDate = wjcr->start_time;
    wjcr->setJobStatus(JS_Running);
 
+   wjcr->jr.PriorJobId = jcr->previous_jr.JobId;
+   if (jcr->previous_jr.PriorJob[0]) {
+      bstrncpy(wjcr->jr.PriorJob, jcr->previous_jr.PriorJob, sizeof(wjcr->jr.PriorJob));
+   } else {
+      bstrncpy(wjcr->jr.PriorJob, jcr->previous_jr.Job, sizeof(wjcr->jr.PriorJob));
+   }
 
    /* Update job start record for the real mac backup job */
    if (!db_update_job_start_record(wjcr, wjcr->db, &wjcr->jr)) {
@@ -812,12 +818,6 @@ void mac_cleanup(JCR *jcr, int TermCode, int writeTermCode)
       wjcr->JobFiles = jcr->JobFiles = wjcr->SDJobFiles;
       wjcr->JobBytes = jcr->JobBytes = wjcr->SDJobBytes;
       wjcr->jr.RealEndTime = 0;
-      wjcr->jr.PriorJobId = jcr->previous_jr.JobId;
-      if (jcr->previous_jr.PriorJob[0]) {
-         bstrncpy(wjcr->jr.PriorJob, jcr->previous_jr.PriorJob, sizeof(wjcr->jr.PriorJob));
-      } else {
-         bstrncpy(wjcr->jr.PriorJob, jcr->previous_jr.Job, sizeof(wjcr->jr.PriorJob));
-      }
       wjcr->JobErrors += wjcr->SDErrors;
       update_job_end(wjcr, TermCode);