]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #9085 Very long jobid list are truncated in copy/migration/virtualfull
authorEric Bollengier <eric@baculasystems.com>
Mon, 8 Aug 2022 16:52:44 +0000 (18:52 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:58 +0000 (13:56 +0200)
bacula/src/dird/job.c
bacula/src/dird/mac_sql.c
bacula/src/dird/protos.h
bacula/src/dird/vbackup.c

index 4e6539cd53fcb4819268249ece68fca47782a565..9117015976815c990b505a1236849a6ce2172302 100644 (file)
@@ -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();
+   }
+}
index cfb95d2563f4fbd1cd9a46a7f50986dd3f552353..032ae28702df42ed1b3260b5245da305fc609c09 100644 (file)
@@ -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);
       /*
index fec32974fdd423faa2999fa3c15bb745a447eb43..c19e05c5e8dca0ef505d023cbfd7260dfdd619aa 100644 (file)
@@ -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);
index 8ed0a29ae3f8a3c831ba7bc31c1983c7a13b8ed5..5bea21de42644621be99217d3b86602cf00bf3fb 100644 (file)
@@ -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);