From: Alain Spineux Date: Tue, 6 Dec 2022 10:35:08 +0000 (+0100) Subject: fix wrong "Last Volume Bytes" in VirtualFull X-Git-Tag: Beta-15.0.0~329 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c49edaca209fe9aebcba43f52f2bebad5787972;p=thirdparty%2Fbacula.git fix wrong "Last Volume Bytes" in VirtualFull - the data was coming from the last volume that was READ instead of the last WTRITTEN one - the problem don't show up in copy/migrate - unify the code to retrieve this information for VF & MAC - extent get_job_volume_names() to also return the last written volume --- diff --git a/bacula/src/cats/bdb.h b/bacula/src/cats/bdb.h index 4de12cdd0..3e572f72c 100644 --- a/bacula/src/cats/bdb.h +++ b/bacula/src/cats/bdb.h @@ -235,7 +235,8 @@ public: int bdb_get_client_record(JCR *jcr, CLIENT_DBR *cr); bool bdb_get_jobmedia_record(JCR *jcr, JOBMEDIA_DBR *jmr); bool bdb_get_job_record(JCR *jcr, JOB_DBR *jr); - int bdb_get_job_volume_names(JCR *jcr, JobId_t JobId, POOLMEM **VolumeNames); + int bdb_get_job_volume_names(JCR *jcr, JobId_t JobId, POOLMEM **VolumeNames, + char *LastVolumeName, int maxlen); bool bdb_get_file_attributes_record(JCR *jcr, char *fname, JOB_DBR *jr, FILE_DBR *fdbr); int bdb_get_fileset_record(JCR *jcr, FILESET_DBR *fsr); bool bdb_get_media_record(JCR *jcr, MEDIA_DBR *mr); diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 68675d7a7..b8b33ce73 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -217,8 +217,8 @@ void bdb_free_restoreobject_record(JCR *jcr, ROBJECT_DBR *rr); mdb->bdb_get_jobmedia_record(jcr, jmr) #define db_get_job_record(jcr, mdb, jr) \ mdb->bdb_get_job_record(jcr, jr) -#define db_get_job_volume_names(jcr, mdb, JobId, VolumeNames) \ - mdb->bdb_get_job_volume_names(jcr, JobId, VolumeNames) +#define db_get_job_volume_names(jcr, mdb, JobId, VolumeNames, LastVolumeName, maxlen) \ + mdb->bdb_get_job_volume_names(jcr, JobId, VolumeNames, LastVolumeName, maxlen) #define db_get_file_attributes_record(jcr, mdb, fname, jr, fdbr) \ mdb->bdb_get_file_attributes_record(jcr, fname, jr, fdbr) #define db_get_fileset_record(jcr, mdb, fsr) \ diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 95a99ecbc..c7632431f 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -363,7 +363,8 @@ bool BDB::bdb_get_job_record(JCR *jcr, JOB_DBR *jr) * * Returns: number of volumes on success */ -int BDB::bdb_get_job_volume_names(JCR *jcr, JobId_t JobId, POOLMEM **VolumeNames) +int BDB::bdb_get_job_volume_names(JCR *jcr, JobId_t JobId, POOLMEM **VolumeNames, + char *LastVolumeName, int maxlen) { SQL_ROW row; char ed1[50]; @@ -379,7 +380,10 @@ int BDB::bdb_get_job_volume_names(JCR *jcr, JobId_t JobId, POOLMEM **VolumeNames "ORDER BY 2 ASC", edit_int64(JobId,ed1)); Dmsg1(130, "VolNam=%s\n", cmd); - *VolumeNames[0] = 0; + *VolumeNames[0] = '\0'; + if (LastVolumeName != NULL && maxlen>0) { + LastVolumeName[0] = '\0'; + } if (QueryDB(jcr, cmd)) { Dmsg1(130, "Num rows=%d\n", sql_num_rows()); if (sql_num_rows() <= 0) { @@ -400,6 +404,9 @@ int BDB::bdb_get_job_volume_names(JCR *jcr, JobId_t JobId, POOLMEM **VolumeNames pm_strcat(VolumeNames, row[0]); } } + if (LastVolumeName != NULL && stat > 0) { + bstrncat(LastVolumeName, row[0], maxlen); /* remember the last written volume */ + } } sql_free_result(); } else { diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 33f5e66eb..2cc4c6a99 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -1117,7 +1117,7 @@ void backup_cleanup(JCR *jcr, int TermCode) bstrftimes_na(schedt, sizeof(schedt), jcr->jr.SchedTime); bstrftimes_na(sdt, sizeof(sdt), jcr->jr.StartTime); bstrftimes_na(edt, sizeof(edt), jcr->jr.EndTime); - if (!db_get_job_volume_names(jcr, jcr->db, jcr->jr.JobId, &jcr->VolumeName)) { + if (!db_get_job_volume_names(jcr, jcr->db, jcr->jr.JobId, &jcr->VolumeName, NULL, 0)) { /* * Note, if the job has erred, most likely it did not write any * tape, so suppress this "error" message since in that case diff --git a/bacula/src/dird/mac.c b/bacula/src/dird/mac.c index dcbaf7a47..66b387bde 100644 --- a/bacula/src/dird/mac.c +++ b/bacula/src/dird/mac.c @@ -887,7 +887,8 @@ void mac_cleanup(JCR *jcr, int TermCode, int writeTermCode) update_bootstrap_file(wjcr); - if (!db_get_job_volume_names(wjcr, wjcr->db, wjcr->jr.JobId, &wjcr->VolumeName)) { + if (!db_get_job_volume_names(wjcr, wjcr->db, wjcr->jr.JobId, &wjcr->VolumeName, + mr.VolumeName, sizeof(mr.VolumeName))) { /* * Note, if the job has failed, most likely it did not write any * tape, so suppress this "error" message since in that case @@ -898,17 +899,8 @@ void mac_cleanup(JCR *jcr, int TermCode, int writeTermCode) Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(wjcr->db)); } wjcr->VolumeName[0] = 0; /* none */ - } - - if (wjcr->VolumeName[0]) { - /* Find last volume name. Multiple vols are separated by | */ - char *p = strrchr(wjcr->VolumeName, '|'); - if (p) { - p++; /* skip | */ - } else { - p = wjcr->VolumeName; /* no |, take full name */ - } - bstrncpy(mr.VolumeName, p, sizeof(mr.VolumeName)); + } else { + /* retrieve the last volume record for the "Last Volume Bytes" */ if (!db_get_media_record(jcr, jcr->db, &mr)) { Jmsg(jcr, M_WARNING, 0, _("Error getting Media record for Volume \"%s\": ERR=%s"), mr.VolumeName, db_strerror(jcr->db)); diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index 9af03dfee..f925a950a 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -858,7 +858,7 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist) continue; } VolumeName = get_pool_memory(PM_FNAME); - n = db_get_job_volume_names(ua->jcr, ua->db, jobid, &VolumeName); + n = db_get_job_volume_names(ua->jcr, ua->db, jobid, &VolumeName, NULL, 0); ua->send_msg(_("Jobid %d used %d Volume(s): %s\n"), jobid, n, VolumeName); free_pool_memory(VolumeName); done = true; diff --git a/bacula/src/dird/vbackup.c b/bacula/src/dird/vbackup.c index cf2fb769c..c5efe17a7 100644 --- a/bacula/src/dird/vbackup.c +++ b/bacula/src/dird/vbackup.c @@ -497,13 +497,6 @@ void vbackup_cleanup(JCR *jcr, int TermCode) db_strerror(jcr->db)); } - bstrncpy(mr.VolumeName, jcr->VolumeName, sizeof(mr.VolumeName)); - if (!db_get_media_record(jcr, jcr->db, &mr)) { - Jmsg(jcr, M_WARNING, 0, _("Error getting Media record for Volume \"%s\": ERR=%s"), - mr.VolumeName, db_strerror(jcr->db)); - jcr->setJobStatus(JS_ErrorTerminated); - } - update_bootstrap_file(jcr); switch (jcr->JobStatus) { @@ -535,7 +528,8 @@ void vbackup_cleanup(JCR *jcr, int TermCode) bstrftimes(schedt, sizeof(schedt), jcr->jr.SchedTime); bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime); bstrftimes(edt, sizeof(edt), jcr->jr.EndTime); - if (!db_get_job_volume_names(jcr, jcr->db, jcr->jr.JobId, &jcr->VolumeName)) { + if (!db_get_job_volume_names(jcr, jcr->db, jcr->jr.JobId, &jcr->VolumeName, + mr.VolumeName, sizeof(mr.VolumeName))) { /* * Note, if the job has erred, most likely it did not write any * tape, so suppress this "error" message since in that case @@ -546,6 +540,12 @@ void vbackup_cleanup(JCR *jcr, int TermCode) Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db)); } jcr->VolumeName[0] = 0; /* none */ + } else { + if (!db_get_media_record(jcr, jcr->db, &mr)) { + Jmsg(jcr, M_WARNING, 0, _("Error getting Media record for Volume \"%s\": ERR=%s"), + mr.VolumeName, db_strerror(jcr->db)); + jcr->setJobStatus(JS_ErrorTerminated); + } } jobstatus_to_ascii(jcr->SDJobStatus, sd_term_msg, sizeof(sd_term_msg));