]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Allow to use PriorJob in db_get_job_record() if the Job is not found
authorEric Bollengier <eric@baculasystems.com>
Tue, 26 Oct 2021 09:19:02 +0000 (11:19 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:03 +0000 (09:03 +0100)
The .bvfs_get_jobids ujobid=xxxx function will set the Job and the PriorJob
fields to search for a JobId. It will allow to search on Copy Jobs.

bacula/src/cats/sql_get.c

index 1450a85b6f84c2403ef395a0f368e846e5ad91d9..1509c720b5826719751b6fde31222e1c4e5689e7 100644 (file)
@@ -251,30 +251,52 @@ bool BDB::bdb_get_job_record(JCR *jcr, JOB_DBR *jr)
 
    bdb_lock();
    if (jr->JobId == 0) {
-      bdb_escape_string(jcr, esc, jr->Job, strlen(jr->Job));
-      Mmsg(cmd, "SELECT VolSessionId,VolSessionTime,"
+      if (jr->Job[0]) {
+         bdb_escape_string(jcr, esc, jr->Job, strlen(jr->Job));
+         Mmsg(cmd, "SELECT VolSessionId,VolSessionTime,"
 "PoolId,StartTime,EndTime,JobFiles,JobBytes,JobTDate,Job,JobStatus,"
 "Type,Level,ClientId,Name,PriorJobId,RealEndTime,JobId,FileSetId,"
 "SchedTime,RealEndTime,ReadBytes,HasBase,PurgedFiles,PriorJob,Comment,Reviewed "
 "FROM Job WHERE Job='%s'", esc);
-    } else {
+
+      } else if (jr->PriorJob[0]) {
+         bdb_escape_string(jcr, esc, jr->PriorJob, strlen(jr->PriorJob));
+         Mmsg(cmd, "SELECT VolSessionId,VolSessionTime,"
+"PoolId,StartTime,EndTime,JobFiles,JobBytes,JobTDate,Job,JobStatus,"
+"Type,Level,ClientId,Name,PriorJobId,RealEndTime,JobId,FileSetId,"
+"SchedTime,RealEndTime,ReadBytes,HasBase,PurgedFiles,PriorJob,Comment,Reviewed "
+"FROM Job WHERE PriorJob='%s' ORDER BY Type ASC LIMIT 1", esc);
+      } else {
+         Mmsg0(errmsg, _("No Job found\n"));
+         bdb_unlock();
+         return false;                   /* failed */
+      }
+
+   } else {
       Mmsg(cmd, "SELECT VolSessionId,VolSessionTime,"
 "PoolId,StartTime,EndTime,JobFiles,JobBytes,JobTDate,Job,JobStatus,"
 "Type,Level,ClientId,Name,PriorJobId,RealEndTime,JobId,FileSetId,"
 "SchedTime,RealEndTime,ReadBytes,HasBase,PurgedFiles,PriorJob,Comment,Reviewed "
 "FROM Job WHERE JobId=%s",
           edit_int64(jr->JobId, ed1));
-    }
+   }
 
    if (!QueryDB(jcr, cmd)) {
       bdb_unlock();
       return false;                   /* failed */
    }
+
    if ((row = sql_fetch_row()) == NULL) {
       Mmsg1(errmsg, _("No Job found for JobId %s\n"), edit_int64(jr->JobId, ed1));
       sql_free_result();
       bdb_unlock();
-      return false;                   /* failed */
+
+      /* If a prior job is set, we can retry with it */
+      if (jr->Job[0] && jr->PriorJob[0]) {
+         jr->Job[0] = 0;
+         return bdb_get_job_record(jcr, jr);
+      }
+      return false;
    }
 
    jr->VolSessionId = str_to_uint64(row[0]);