]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #3593 VirtualFull will select jobs to consolidate using Job name in addition...
authorEric Bollengier <eric@baculasystems.com>
Thu, 15 Mar 2018 09:06:10 +0000 (10:06 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 14 Jul 2018 14:02:24 +0000 (16:02 +0200)
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.

bacula/src/cats/sql_cmds.c
bacula/src/cats/sql_get.c
bacula/src/dird/vbackup.c

index 2a85a8747667b8c4490bf9bc4ed6bbdf1e7ca2f3..06b23b25301e47c912599cfc55eb454781b1089f 100644 (file)
@@ -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[] = {
index da6938f406af1baab22ff23b84fdb4113413f590..201017bcd0d3984648b5473f13ac342fe77f2399 100644 (file)
@@ -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;
       }
index ab7c2d4fcb10267d8f815a3e2c55bdf104e44d63..93c2ff5988453f6b586e2a0e3e8a6f2ceef78a44 100644 (file)
@@ -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);
    }