From: Eric Bollengier Date: Thu, 15 Mar 2018 09:06:10 +0000 (+0100) Subject: Fix #3593 VirtualFull will select jobs to consolidate using Job name in addition... X-Git-Tag: Release-9.2.0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d436d321482ce6676b4bf650d8545e33c619bd3;p=thirdparty%2Fbacula.git Fix #3593 VirtualFull will select jobs to consolidate using Job name in addition to Client/FileSet If multiple jobs on a client are sharing the same fileset, the virtual full was selecting all the jobs matching the Client/FileSet names. Leading to a VirtualFull with the correct files, but an incorrect parent hierarchy. The new code will select the JobIds to consolidate with the job Name, the Client and the FileSet. --- diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index 2a85a8747..06b23b253 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -420,6 +420,7 @@ static const char *create_temp_accurate_jobids_default = "AND Level='F' AND JobStatus IN ('T','W') AND Type='B' " "AND StartTime<'%s' " "AND FileSet.FileSet=(SELECT FileSet FROM FileSet WHERE FileSetId = %s) " + " %s " /* Any filter */ "ORDER BY Job.JobTDate DESC LIMIT 1"; const char *create_temp_accurate_jobids[] = { diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index da6938f40..201017bcd 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1327,7 +1327,8 @@ bool BDB::bdb_get_accurate_jobids(JCR *jcr, bool ret=false; char clientid[50], jobid[50], filesetid[50]; char date[MAX_TIME_LENGTH]; - POOL_MEM query(PM_FNAME); + char esc[MAX_ESCAPE_NAME_LENGTH]; + POOL_MEM query(PM_MESSAGE), name(PM_FNAME); /* Take the current time as upper limit if nothing else specified */ utime_t StartTime = (jr->StartTime)?jr->StartTime:time(NULL); @@ -1346,12 +1347,19 @@ bool BDB::bdb_get_accurate_jobids(JCR *jcr, edit_uint64(jcr->JobId, jobid); } + if (jr->Name[0] != 0) { + bdb_escape_string(jcr, esc, jr->Name, strlen(jr->Name)); + Mmsg(name, " AND Name = '%s' ", esc); + } + /* First, find the last good Full backup for this job/client/fileset */ Mmsg(query, create_temp_accurate_jobids[bdb_get_type_index()], jobid, edit_uint64(jr->ClientId, clientid), date, - edit_uint64(jr->FileSetId, filesetid)); + edit_uint64(jr->FileSetId, filesetid), + name.c_str() + ); if (!bdb_sql_query(query.c_str(), NULL, NULL)) { goto bail_out; @@ -1368,12 +1376,15 @@ bool BDB::bdb_get_accurate_jobids(JCR *jcr, "AND StartTime > (SELECT EndTime FROM btemp3%s ORDER BY EndTime DESC LIMIT 1) " "AND StartTime < '%s' " "AND FileSet.FileSet= (SELECT FileSet FROM FileSet WHERE FileSetId = %s) " + " %s " /* Optional name */ "ORDER BY Job.JobTDate DESC LIMIT 1 ", jobid, clientid, jobid, date, - filesetid); + filesetid, + name.c_str() + ); if (!bdb_sql_query(query.c_str(), NULL, NULL)) { goto bail_out; @@ -1389,12 +1400,15 @@ bool BDB::bdb_get_accurate_jobids(JCR *jcr, "AND StartTime > (SELECT EndTime FROM btemp3%s ORDER BY EndTime DESC LIMIT 1) " "AND StartTime < '%s' " "AND FileSet.FileSet= (SELECT FileSet FROM FileSet WHERE FileSetId = %s) " + " %s " "ORDER BY Job.JobTDate DESC ", jobid, clientid, jobid, date, - filesetid); + filesetid, + name.c_str() + ); if (!bdb_sql_query(query.c_str(), NULL, NULL)) { goto bail_out; } diff --git a/bacula/src/dird/vbackup.c b/bacula/src/dird/vbackup.c index ab7c2d4fc..93c2ff598 100644 --- a/bacula/src/dird/vbackup.c +++ b/bacula/src/dird/vbackup.c @@ -211,6 +211,8 @@ _("This Job is not an Accurate backup so is not equivalent to a Full backup.\n") } else { /* No argument provided */ jcr->jr.JobLevel = L_VIRTUAL_FULL; + /* We restrict the search of the JobIds to the current job */ + bstrncpy(jcr->jr.Name, jcr->job->name(), sizeof(jcr->jr.Name)); db_get_accurate_jobids(jcr, jcr->db, &jcr->jr, &jobids); Dmsg1(10, "Accurate jobids=%s\n", jobids.list); }