From: Eric Bollengier Date: Tue, 26 Oct 2021 09:19:02 +0000 (+0200) Subject: Allow to use PriorJob in db_get_job_record() if the Job is not found X-Git-Tag: Release-11.3.2~342 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0040e98dc61a82c64a2aa48569b565e19e1b829e;p=thirdparty%2Fbacula.git Allow to use PriorJob in db_get_job_record() if the Job is not found 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. --- diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 1450a85b6..1509c720b 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -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]);