]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #7098 About bscan duplicating restore objects
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Tue, 1 Dec 2020 12:13:54 +0000 (13:13 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:59 +0000 (09:02 +0100)
bacula/src/jcr.h
bacula/src/stored/bscan.c

index 768a49f2f31dc17c0731759b4dd1c8cc362a6738..3734669cb9d297e0a76ecbee9b296d5c2f110f78 100644 (file)
@@ -523,6 +523,7 @@ public:
    bool PreferMountedVols;            /* Prefer mounted vols rather than new */
    bool Resched;                      /* Job may be rescheduled */
    bool bscan_insert_jobmedia_records; /*Bscan: needs to insert job media records */
+   bool bscan_created;                /* Flag for bscan to know if this jcr was created by it or not */
    bool sd_client;                    /* Set if acting as client */
    bool use_new_match_all;            /* TODO: Remove when the match_bsr() will be well tested */
 
index 6f35eed1365636f692824e8eb2810b4dd2c11ebb..48239bcb14426e3bfbf950a0507073d467d2d6ef 100644 (file)
@@ -776,22 +776,22 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
             break;
          }
 
-         ro.JobId = mjcr->JobId;
-
-         if (db_get_restoreobject_record(mjcr, db, &ro)) {
-            if (verbose) {
-               Pmsg1(0, _("RESTORE_OBJECT: Found Restore Object \"%s\" in the catalog\n"), ro.object_name);
-            }
-         } else if (update_db) {
-            /* Send it */
-            Pmsg1(0, _("RESTORE_OBJECT: Inserting Restore Object \"%s\" into the catalog\n"), ro.object_name);
-            if (!db_create_restore_object_record(mjcr, db, &ro)) {
-               Jmsg1(mjcr, M_FATAL, 0, _("Restore object create error. %s"), db_strerror(db));
+         if (mjcr->bscan_created) {
+            // bscan created this job record so we need to recreate objects as well
+            if (update_db) {
+               /* Send it */
+               Pmsg1(0, _("RESTORE_OBJECT: Inserting Restore Object \"%s\" into the catalog\n"), ro.object_name);
+               // Create record with updated jobid
+               ro.JobId = mjcr->JobId;
+               if (!db_create_restore_object_record(mjcr, db, &ro)) {
+                  Jmsg1(mjcr, M_FATAL, 0, _("Restore object create error. %s"), db_strerror(db));
+               }
             }
          } else {
             Pmsg1(0, _("RESTORE_OBJECT: Found Restore Object \"%s\" on the volume\n"), ro.object_name);
          }
 
+         mjcr->dec_use_count(); /* Decrease reference counter increased by get_jcr_by_session call */
          break;
       }
 
@@ -1286,6 +1286,7 @@ static JCR *create_job_record(BDB *db, JOB_DBR *jr, SESSION_LABEL *label,
    Pmsg2(000, _("Created new JobId=%u record for original JobId=%u\n"), jr->JobId,
          label->JobId);
    mjcr->JobId = jr->JobId;           /* set new JobId */
+   mjcr->bscan_created = true;
    return mjcr;
 }