From: Michal Rakowski Date: Tue, 1 Dec 2020 12:13:54 +0000 (+0100) Subject: Fix #7098 About bscan duplicating restore objects X-Git-Tag: Release-11.3.2~820 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9587645527b92faae89db897bb5550eed9935431;p=thirdparty%2Fbacula.git Fix #7098 About bscan duplicating restore objects --- diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 768a49f2f..3734669cb 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -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 */ diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index 6f35eed13..48239bcb1 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -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; }