]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Enhance the network error reporting with between the Director and the File/SD
authorEric Bollengier <eric@baculasystems.com>
Fri, 11 Nov 2022 09:46:00 +0000 (10:46 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:00 +0000 (13:57 +0200)
13 files changed:
bacula/src/dird/backup.c
bacula/src/dird/fd_cmds.c
bacula/src/dird/getmsg.c
bacula/src/dird/job.c
bacula/src/dird/mac.c
bacula/src/dird/msgchan.c
bacula/src/dird/restore.c
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_dotcmds.c
bacula/src/dird/ua_status.c
bacula/src/dird/ua_update.c
bacula/src/dird/vbackup.c
bacula/src/dird/verify.c

index 0590f2b5279f2b1e5e0e7ba93ab48c45e9b498ee..2c53973ca3024f6d6ec4837e2699515987c014b9 100644 (file)
@@ -466,7 +466,7 @@ bool do_backup(JCR *jcr)
    char ed1[100];
    db_int64_ctx job, first, last;
    int64_t val=0;
-   POOL_MEM buf, tmp;
+   POOL_MEM buf, tmp, lasterr;
 
    if (jcr->is_JobLevel(L_VIRTUAL_FULL)) {
       return do_vbackup(jcr);
@@ -564,6 +564,13 @@ bool do_backup(JCR *jcr)
       }
 
       foreach_alist(store, jcr->store_mngr->get_wstore_list()) {
+         /* The idea is to display the error at the start of the loop
+          * doing so, the last error will be displayed as fatal if needed
+          */
+         if (strcmp(lasterr.c_str(), "") != 0) {
+            Jmsg(jcr, M_WARNING, 0, "%s", lasterr.c_str());
+            pm_strcpy(lasterr, "");
+         }
          jcr->store_mngr->set_current_wstorage(store);
 
          if (jcr->store_bsock) {
@@ -575,8 +582,13 @@ bool do_backup(JCR *jcr)
           * Start conversation with Storage daemon
           */
          if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
-            Dmsg1(100, "Failed connect to the storage: %s\n", jcr->store_mngr->get_wstore()->name());
+            /* The message will be displayed as warning in the next
+             * iteration of the loop, or as fatal at the end of the
+             * foreach block
+             */
+            pm_strcpy(lasterr, jcr->errmsg);
             continue;
+
          } else {
             Dmsg1(100, "Connected to the storage: %s\n", jcr->store_mngr->get_wstore()->name());
          }
@@ -599,7 +611,8 @@ bool do_backup(JCR *jcr)
           * because we have only 2 iterations (so 'iter' variable is either 0 or 1)
           */
          if (!start_storage_daemon_job(jcr, NULL, &wlist, wstore_group ? (bool)iter : true)) {
-            Dmsg1(100, "Failed to start job on the storage: %s\n", jcr->store_mngr->get_wstore()->name());
+            Mmsg(lasterr, _("Failed to start job on the storage: %s\n"),
+                 jcr->store_mngr->get_wstore()->name());
             continue;
          } else {
             sd_job_started = true;
@@ -626,7 +639,7 @@ bool do_backup(JCR *jcr)
    }
 
    if(!sd_job_started) {
-      Jmsg(jcr, M_FATAL, 0, _("Failed to start job on any of the storages defined!\n"));
+      Jmsg(jcr, M_FATAL, 0, "%s", lasterr.c_str());
       goto bail_out;
    }
 
@@ -654,7 +667,8 @@ bool do_backup(JCR *jcr)
 
    /* Print connection info only for real jobs */
    build_connecting_info_log(_("Client"), jcr->client->name(),
-                             get_client_address(jcr, jcr->client, tmp.addr()), jcr->client->FDport,
+                             get_client_address(jcr, jcr->client, tmp.addr()),
+                             jcr->client->FDport,
                              fd->tls ? true : false, buf.addr());
    Jmsg(jcr, M_INFO, 0, "%s", buf.c_str());
 
@@ -687,7 +701,7 @@ bool do_backup(JCR *jcr)
 
    if (jcr->sd_calls_client) {
       if (jcr->FDVersion < 10) {
-         Jmsg(jcr, M_FATAL, 0, _("The File daemon does not support SDCallsClient.\n"));
+         Jmsg(jcr, M_FATAL, 0, _("[DE0011] The File daemon does not support SDCallsClient.\n"));
          goto bail_out;
       }
       if (!send_client_addr_to_sd(jcr)) {
@@ -882,8 +896,9 @@ int wait_for_job_termination(JCR *jcr, int timeout)
       jcr->CommCompressedBytes = CommCompressedBytes;
       jcr->Snapshot = VSS;
       jcr->Encrypt = Encrypt;
+
    } else if (!jcr->is_canceled()) {
-      Jmsg(jcr, M_FATAL, 0, _("No Job status returned from FD. %c\n"), jcr->getJobStatus());
+      Jmsg(jcr, M_FATAL, 0, _("[DE0011] No Job status returned from FD\n"));
    }
 
    /* Return the first error status we find Dir, FD, or SD */
index c2f150819c44306237dcf9f2d3de1c22c6e7fceb..4d4d3524c5419b60dd8957bbece7a0f38c547500 100644 (file)
@@ -151,7 +151,6 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
    jcr->setJobStatus(JS_Running);
 
    if (!authenticate_file_daemon(jcr, &status, &jcr->errmsg)) {
-      Dmsg1(10, "Authentication error with FD. %s\n", jcr->errmsg);
       return 0;
    }
 
index d46a11e967fb9ad5765a419bc422dc49d363b5e8..54d8a1e1be8742ee765d49574598d827afca3f14 100644 (file)
@@ -416,12 +416,12 @@ bool response(JCR *jcr, BSOCK *bs, BSOCK_CLIENT_TYPE role, const char *resp, con
          return true;
       }
       if (prtmsg == DISPLAY_ERROR) {
-         Jmsg(jcr, M_FATAL, 0, _("Bad response to %s command: wanted %s, got %s\n"),
+         Jmsg(jcr, M_FATAL, 0, _("[DE0011] Bad response to %s command: wanted %s, got %s\n"),
             cmd, resp, bs->msg);
       }
       return false;
    }
-   Jmsg(jcr, M_FATAL, 0, _("Socket error on %s command: ERR=%s\n"),
+   Jmsg(jcr, M_FATAL, 0, _("[DE0018] Socket error on %s command: ERR=%s\n"),
          cmd, bs->bstrerror());
    return false;
 }
index ff674386a1a0450fd5133d2b420bf88874f1b57e..b5b838b723705e36deb0c4d5a4a9e9b64ef2fb69 100644 (file)
@@ -601,7 +601,7 @@ static bool cancel_sd_job(UAContext *ua, const char *cmd, JCR *jcr)
    }
 
    if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
-      ua->error_msg(_("Failed to connect to Storage daemon.\n"));
+      ua->error_msg("%s", ua->jcr->errmsg);
       return false;
    }
 
@@ -891,6 +891,7 @@ void cancel_storage_daemon_job(JCR *jcr)
       }
 
       if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
+         Jmsg(ua->jcr, M_ERROR, 0, "%s", ua->jcr->errmsg); /* TODO: Enhance, it's not always a job */
          goto bail_out;
       }
       Dmsg0(200, "Connected to storage daemon\n");
index cd17fe764e4a37dacc44b53465a5341685e86068..dcbaf7a471adefbb585bba475ef4dd0efc15f5e7 100644 (file)
@@ -524,7 +524,8 @@ bool do_mac(JCR *jcr)
     */
    Dmsg0(200, "Connect to write (wjcr) storage daemon.\n");
    if (!connect_to_storage_daemon(wjcr, 10, SDConnectTimeout, 1)) {
-      Jmsg(jcr, M_FATAL, 0, _("Could not connect to write Storage Daemon \"%s\"\n"), wjcr->store_mngr->get_wstore()->name());
+      Jmsg(jcr, M_ERROR, 0, _("Could not connect to write Storage Daemon \"%s\"\n"), wjcr->store_mngr->get_wstore()->name());
+      Jmsg(jcr, M_FATAL, 0, "%s", wjcr->errmsg);
       goto bail_out;
    }
    wsd = wjcr->store_bsock;
@@ -539,7 +540,8 @@ bool do_mac(JCR *jcr)
     */
    Dmsg1(200, "Connect to read (jcr) storage daemon. Jid=%d\n", jcr->JobId);
    if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
-      Jmsg(jcr, M_FATAL, 0, _("Could not connect to read Storage Daemon \"%s\"\n"), jcr->store_mngr->get_rstore()->name());
+      Jmsg(jcr, M_ERROR, 0, _("Could not connect to read Storage Daemon \"%s\"\n"), jcr->store_mngr->get_rstore()->name());
+      Jmsg(jcr, M_FATAL, 0, "%s", wjcr->errmsg);
       goto bail_out;
    }
    sd = jcr->store_bsock;
index 60603f362db1f7ce68f362a1e79798784ea381d2..4da9fec13859d50d0b5ddef7ab852a97b1e87161 100644 (file)
@@ -69,8 +69,9 @@ BSOCK *open_sd_bsock(UAContext *ua)
    if (!is_bsock_open(ua->jcr->store_bsock)) {
       ua->send_msg(_("Connecting to Storage daemon %s at %s:%d ...\n"),
          store->name(), store->address, store->SDport);
-      if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
-         ua->error_msg(_("Failed to connect to Storage daemon.\n"));
+      if (!connect_to_storage_daemon(ua->jcr, 5, SDConnectTimeout, 0 /* No need to be verbose */)) {
+         ua->error_msg("%s", ua->jcr->errmsg);
+         free_bsock(ua->jcr->store_bsock);
          return NULL;
       }
    }
index f83f1dcca1aee96177b3640f4d9a5a4216382b20..396bd673c18b9230ff3a13a5e05165649e502dce 100644 (file)
@@ -336,6 +336,7 @@ bool restore_bootstrap(JCR *jcr)
        * Start conversation with Storage daemon
        */
       if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
+         Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg);
          goto bail_out;
       }
       sd = jcr->store_bsock;
index 9d2775a2683247478aae046e29a85453643791cf..74c27c7ec963d398ff64855c0d0e70f82d31cbd8 100644 (file)
@@ -1064,8 +1064,8 @@ static void do_storage_setdebug(UAContext *ua, STORE *store,
    ua->send_msg(_("Connecting to Storage daemon %s at %s:%d\n"),
       store->name(), store->address, store->SDport);
    if (!connect_to_storage_daemon(ua->jcr, 1, 15, 0)) {
-      ua->error_msg(_("Failed to connect to Storage daemon.\n"));
-      return;
+      ua->error_msg("%s", ua->jcr->errmsg);
+      goto bail_out;
    }
    Dmsg0(120, _("Connected to storage daemon\n"));
    sd = ua->jcr->store_bsock;
@@ -1075,6 +1075,7 @@ static void do_storage_setdebug(UAContext *ua, STORE *store,
       ua->send_msg("%s", sd->msg);
    }
    sd->signal(BNET_TERMINATE);
+bail_out:
    free_bsock(ua->jcr->store_bsock);
    return;
 }
@@ -2519,7 +2520,7 @@ static void do_storage_cmd(UAContext *ua, const char *command)
    Dmsg4(120, "Cmd: %s %s drive=%d slot=%d\n", command, dev_name, drive, slot);
 
    if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
-      ua->error_msg(_("Failed to connect to Storage daemon.\n"));
+      ua->error_msg("%s", jcr->errmsg);
       goto bail_out;
    }
 
index b21340f4dd29f650af7679315a82ff0d9c722ec8..5ee58e04c1e95dbed6e230bd7a504648ace87881 100644 (file)
@@ -1753,7 +1753,7 @@ static void do_storage_cmd(UAContext *ua, STORE *store, const char *cmd)
    ua->send_msg(_("Connecting to Storage daemon %s at %s:%d\n"),
       store->name(), store->address, store->SDport);
    if (!connect_to_storage_daemon(jcr, 1, 15, 0)) {
-      ua->error_msg(_("Failed to connect to Storage daemon.\n"));
+      ua->error_msg("%s", jcr->errmsg);
       goto bail_out;
    }
    Dmsg0(120, _("Connected to storage daemon\n"));
index 526d0f4257ff179ee0946a39c27e0709aa5b70f0..41cb4012b9502a71d2e8aeea2ddeafb69c050983 100644 (file)
@@ -161,8 +161,8 @@ static int do_network_status(UAContext *ua)
                    ustore.store->name(), ustore.store->address, ustore.store->SDport);
    }
 
-   if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
-      ua->error_msg(_("Failed to connect to Storage.\n"));
+   if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 0 /* not verbose */)) {
+      ua->error_msg("%s", jcr->errmsg);
       goto bail_out;
    }
 
@@ -573,8 +573,7 @@ static void do_storage_status(UAContext *ua, STORE *store, char *cmd)
    if (!ua->api) ua->send_msg(_("Connecting to Storage daemon %s at %s:%d\n"),
       store->name(), store->address, store->SDport);
    if (!connect_to_storage_daemon(ua->jcr, 1, 15, 0)) {
-      ua->send_msg(_("\nFailed to connect to Storage daemon %s.\n====\n"),
-         store->name());
+      ua->error_msg("%s", ua->jcr->errmsg);
       free_bsock(ua->jcr->store_bsock);
       return;
    }
index 52c05050771746829bbee600f211ca25ddf76d97..08bea43f2d32444651d5492d42c726fc891c5207 100644 (file)
@@ -1203,7 +1203,7 @@ static int update_volumeprotect_cmd(UAContext *ua)
                 media_protect_list_handler, &list);
 
    if (list.size() > 0) {
-      ua->send_msg(_("Found %d volumes with status Used/Full that must be protected\n"), list.size());
+      ua->send_msg(_("Found %d volume(s) with status Used/Full that must be protected\n"), list.size());
 
    } else {
       ua->send_msg(_("No volume found to protect\n"));
@@ -1234,9 +1234,10 @@ static int update_volumeprotect_cmd(UAContext *ua)
             free_bsock(ua->jcr->store_bsock);
             sd = NULL;
          }
-
-         if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
-            ua->error_msg(_("Failed to connect to Storage daemon.\n"));
+         ua->send_msg(_("Connecting to Storage %s at %s:%d\n"),
+                      ustore.store->name(), ustore.store->address, ustore.store->SDport);
+         if (!connect_to_storage_daemon(jcr, 5, SDConnectTimeout, 0 /* not verbose */)) {
+            ua->error_msg("%s", jcr->errmsg);
             ret = 0;
             continue;
          }
index d0bb49f5188b676a7f2a5db7132e21a857b7fb9b..cf2fb769c7f801520df1bf423f55d58ba41bc522 100644 (file)
@@ -342,6 +342,7 @@ _("This Job is not an Accurate backup so is not equivalent to a Full backup.\n")
     * Start conversation with Storage daemon
     */
    if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
+      Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg);
       return false;
    }
    sd = jcr->store_bsock;
index 10fe85cd949307958b26abe0f15cf3f7cf93e3f8..0800b3b92d64767a6efc161b1c051ad8f9b6cf86 100644 (file)
@@ -274,6 +274,7 @@ bool do_verify(JCR *jcr)
        */
       jcr->setJobStatus(JS_Blocked);
       if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
+         Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg);
          return false;
       }
       /*