From: Eric Bollengier Date: Mon, 8 Aug 2022 16:52:44 +0000 (+0200) Subject: Fix #9085 Very long jobid list are truncated in copy/migration/virtualfull X-Git-Tag: Beta-15.0.0~534 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a48f5c2395884b972e1a5def2b7c0f1b83c1c4de;p=thirdparty%2Fbacula.git Fix #9085 Very long jobid list are truncated in copy/migration/virtualfull --- diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 4e6539cd5..911701597 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -1966,3 +1966,23 @@ bool flush_file_records(JCR *jcr) return db_write_batch_file_records(jcr); /* used by bulk batch file insert */ } + +/* Small helper to display very long jobid list + * The msg format should have a single %s + */ +void jmsg_large_jobid_list(JCR *jcr, const char *msg, const char *jobids) +{ + sellist sel; + char *p; + + sel.set_expanded_limit(120); + sel.set_string(jobids, true); + p = sel.get_expanded_list(); + Jmsg(jcr, M_INFO, 0, msg, p); + + sel.free_expanded(); + while ((p = sel.get_expanded_list()) && p[0]) { + Jmsg(jcr, M_INFO, 0, _(" %s\n"), p); + sel.free_expanded(); + } +} diff --git a/bacula/src/dird/mac_sql.c b/bacula/src/dird/mac_sql.c index cfb95d256..032ae2870 100644 --- a/bacula/src/dird/mac_sql.c +++ b/bacula/src/dird/mac_sql.c @@ -376,9 +376,11 @@ int getJob_to_migrate(JCR *jcr) goto ok_out; } - Jmsg(jcr, M_INFO, 0, _("The following %u JobId%s chosen to be %s: %s\n"), - ids.count, (ids.count < 2) ? _(" was") : _("s were"), - jcr->get_ActionName(1), ids.list); + Mmsg(query, _("The following %u JobId%s chosen to be %s: %%s\n"), + ids.count, (ids.count < 2) ? _(" was") : _("s were"), + jcr->get_ActionName(1)); + /* Print the list, but make sure we don't have lines that are too long for Jmsg() */ + jmsg_large_jobid_list(jcr, query.c_str(), ids.list); Dmsg2(dbglevel, "Before loop count=%d ids=%s\n", ids.count, ids.list); /* diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index fec32974f..c19e05c5e 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -120,6 +120,7 @@ enum e_prtmsg { extern bool response(JCR *jcr, BSOCK *fd, BSOCK_CLIENT_TYPE role, const char *resp, const char *cmd, e_prtmsg prtmsg); /* job.c */ +extern void jmsg_large_jobid_list(JCR *jcr, const char *msg, const char *jobids); extern bool allow_duplicate_job(JCR *jcr); extern void set_jcr_defaults(JCR *jcr, JOB *job); extern void create_unique_job_name(JCR *jcr, const char *base_name); diff --git a/bacula/src/dird/vbackup.c b/bacula/src/dird/vbackup.c index 8ed0a29ae..5bea21de4 100644 --- a/bacula/src/dird/vbackup.c +++ b/bacula/src/dird/vbackup.c @@ -91,7 +91,9 @@ bool do_vbackup_init(JCR *jcr) */ static bool copy_object_list(JCR *jcr, const char *jobids, uint32_t JobId) { - /* The batch session is not used anymore at this point */ + if (jcr->is_canceled()) { + return false; + } db_lock(jcr->db_batch); Mmsg(jcr->db_batch->cmd, copy_object[db_get_type_index(jcr->db_batch)], JobId, jobids, jobids); if (!db_sql_query(jcr->db_batch, jcr->db_batch->cmd, NULL, NULL)) { @@ -196,8 +198,7 @@ _("This Job is not an Accurate backup so is not equivalent to a Full backup.\n") return false; } - Jmsg(jcr, M_INFO, 0, _("Using user supplied JobIds=%s\n"), - jobids.list); + jmsg_large_jobid_list(jcr, _("Using user supplied JobIds=%s\n"), jobids.list); /* Check status */ Mmsg(query, @@ -278,7 +279,8 @@ _("This Job is not an Accurate backup so is not equivalent to a Full backup.\n") /* Full by default, or might be Incr/Diff when jobid= is used */ jcr->jr.JobLevel = level_computed; - Jmsg(jcr, M_INFO, 0, "Consolidating JobIds=%s\n", jobids.list); + /* Display the JobId selection and adjust the output for Jmsg */ + jmsg_large_jobid_list(jcr, _("Consolidating JobIds=%s\n"), jobids.list); /* * Now we find the last job that ran and store it's info in @@ -377,6 +379,13 @@ _("This Job is not an Accurate backup so is not equivalent to a Full backup.\n") /* Note, the SD stores in jcr->JobFiles/ReadBytes/JobBytes/JobErrors */ wait_for_storage_daemon_termination(jcr); jcr->setJobStatus(jcr->SDJobStatus); + + /* At this point, the batch SQL link should be open */ + if (!db_open_batch_connection(jcr, jcr->db)) { + Jmsg0(jcr, M_FATAL, 0, "Can't get batch sql connection"); + return false; + } + if (!flush_file_records(jcr)) { /* cached attribute + batch insert */ Jmsg(jcr, M_ERROR, 0, _("Unable to flush file records!\n")); @@ -402,7 +411,8 @@ _("This Job is not an Accurate backup so is not equivalent to a Full backup.\n") ua = new_ua_context(jcr); purge_jobs_from_catalog(ua, jobids.list); free_ua_context(ua); - Jmsg(jcr, M_INFO, 0, _("Deleted consolidated JobIds=%s\n"), jobids.list); + + jmsg_large_jobid_list(jcr, _("Delete consolidated JobIds=%s\n"), jobids.list); } vbackup_cleanup(jcr, jcr->JobStatus);