From: Michal Rakowski Date: Thu, 3 Dec 2020 05:58:29 +0000 (+0100) Subject: Improve bscan so that it reinserts file records after prunning X-Git-Tag: Release-11.3.2~812 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=049c213b84e3c7bea3fcce8b024a9ba0d0a0fbb0;p=thirdparty%2Fbacula.git Improve bscan so that it reinserts file records after prunning --- diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 3734669cb..f419d7c3b 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -524,6 +524,7 @@ public: 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 bscan_files_purged; /* Flag for bscan to know if this jcr has purged files */ 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 615cbf552..7c5cf05ba 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -736,7 +736,6 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) switch (rec->maskedStream) { case STREAM_UNIX_ATTRIBUTES: case STREAM_UNIX_ATTRIBUTES_EX: - if (!unpack_attributes_record(bjcr, rec->Stream, rec->data, rec->data_len, attr)) { Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n")); } @@ -756,11 +755,23 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) edit_uint64_with_commas(rec->Addr, ed2), edit_uint64_with_commas(mr.VolBytes, ed3)); } - if (!create_file_attributes_record(mjcr, attr, rec)) { + + mjcr = get_jcr_by_session(rec->VolSessionId, rec->VolSessionTime); + if (!mjcr) { + Pmsg2(000, _("Could not find SessId=%d SessTime=%d for File record.\n"), + rec->VolSessionId, rec->VolSessionTime); + break; + } + + if (mjcr->bscan_files_purged || mjcr->bscan_created) { + // We need to insert file records etiher because job that has files purged or bscan created it + if (!create_file_attributes_record(mjcr, attr, rec)) { Jmsg2(mjcr, M_ERROR, 0, _("Failed to insert record for file: %s. err: %s\n"), attr->fname, db_strerror(db)); - break; + } } + + mjcr->dec_use_count(); /* Decrease reference counter increased by get_jcr_by_session call */ break; case STREAM_RESTORE_OBJECT: @@ -1274,6 +1285,11 @@ static JCR *create_job_record(BDB *db, JOB_DBR *jr, SESSION_LABEL *label, db_driver, db_name); } + // Bscan needs to be aware if files were previously purged + if (jr->PurgedFiles) { + mjcr->bscan_files_purged = true; + } + if (!update_db) { return mjcr; }