]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #3225 about Migration issue when the Job resource is no longer defined
authorEric Bollengier <eric@baculasystems.com>
Tue, 15 Jan 2019 08:49:51 +0000 (09:49 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 19 Jan 2019 14:17:03 +0000 (15:17 +0100)
The Migration job status was "no files to migrate" and the original job
type was marked as M.

Now, the Migration job status is "Migration Error" and the original job
type is not modified.

bacula/src/dird/mac.c
bacula/src/dird/msgchan.c

index c052640db861360d5c7ba9237071d3c1a84fff7c..b54dcab65eb11fed10418f951e5c39ba08721455 100644 (file)
@@ -673,7 +673,8 @@ void mac_cleanup(JCR *jcr, int TermCode, int writeTermCode)
       goterrors = jcr->SDErrors > 0 || jcr->JobErrors > 0 ||
          jcr->SDJobStatus == JS_Canceled ||
          jcr->SDJobStatus == JS_ErrorTerminated ||
-         jcr->SDJobStatus == JS_FatalError;
+         jcr->SDJobStatus == JS_FatalError ||
+         jcr->JobStatus == JS_FatalError;
 
       if (goterrors && jcr->getJobType() == JT_MIGRATE && jcr->JobStatus == JS_Terminated) {
          Jmsg(jcr, M_WARNING, 0, _("Found errors during the migration process. "
@@ -786,39 +787,44 @@ void mac_cleanup(JCR *jcr, int TermCode, int writeTermCode)
               JS_ErrorTerminated, new_jobid);
          db_sql_query(wjcr->db, query.c_str(), NULL, NULL);
       }
+   }
 
-      switch (jcr->JobStatus) {
-      case JS_Terminated:
-         if (jcr->JobErrors || jcr->SDErrors) {
-            Mmsg(term_msg, _("%%s OK -- %s"), jcr->StatusErrMsg[0] ? jcr->StatusErrMsg : _("with warnings"));
-         } else {
-            Mmsg(term_msg, _("%%s OK"));
-         }
-         break;
-      case JS_FatalError:
-      case JS_ErrorTerminated:
-         Mmsg(term_msg, _("*** %%s Error ***"));
-         msg_type = M_ERROR;          /* Generate error message */
-         terminate_sd_msg_chan_thread(jcr);
-         terminate_sd_msg_chan_thread(wjcr);
-         break;
-      case JS_Canceled:
-         Mmsg(term_msg, _("%%s Canceled"));
-         terminate_sd_msg_chan_thread(jcr);
-         terminate_sd_msg_chan_thread(wjcr);
-         break;
-      default:
-         Mmsg(term_msg, _("Inappropriate %s term code"));
-         break;
+   switch (jcr->JobStatus) {
+   case JS_Terminated:
+      if (jcr->JobErrors || jcr->SDErrors) {
+         Mmsg(term_msg, _("%%s OK -- %s"), jcr->StatusErrMsg[0] ? jcr->StatusErrMsg : _("with warnings"));
+      } else {
+         Mmsg(term_msg, _("%%s OK"));
       }
-   } else {
-      if (!goterrors && jcr->getJobType() == JT_MIGRATE && jcr->previous_jr.JobId != 0) {
-         /* Mark previous job as migrated */
-         Mmsg(query, "UPDATE Job SET Type='%c' WHERE JobId=%s",
-              (char)JT_MIGRATED_JOB, edit_uint64(jcr->previous_jr.JobId, ec1));
-         db_sql_query(jcr->db, query.c_str(), NULL, NULL);
+      break;
+   case JS_FatalError:
+   case JS_ErrorTerminated:
+      Mmsg(term_msg, _("*** %%s Error ***"));
+      msg_type = M_ERROR;          /* Generate error message */
+      terminate_sd_msg_chan_thread(jcr);
+      terminate_sd_msg_chan_thread(wjcr);
+      break;
+   case JS_Canceled:
+      Mmsg(term_msg, _("%%s Canceled"));
+      terminate_sd_msg_chan_thread(jcr);
+      terminate_sd_msg_chan_thread(wjcr);
+      break;
+   default:
+      Mmsg(term_msg, _("Inappropriate %s term code"));
+      break;
+   }
+
+   if (!wjcr) {                 /* We did nothing */
+      goterrors = jcr->JobErrors > 0 || jcr->JobStatus == JS_FatalError;
+      if (!goterrors) {
+         if (jcr->getJobType() == JT_MIGRATE && jcr->previous_jr.JobId != 0) {
+            /* Mark previous job as migrated */
+            Mmsg(query, "UPDATE Job SET Type='%c' WHERE JobId=%s",
+                 (char)JT_MIGRATED_JOB, edit_uint64(jcr->previous_jr.JobId, ec1));
+            db_sql_query(jcr->db, query.c_str(), NULL, NULL);
+         }
+         Mmsg(term_msg, _("%%s -- no files to %%s"));
       }
-      Mmsg(term_msg, _("%%s -- no files to %%s"));
    }
 
    Mmsg(term_code, term_msg.c_str(), jcr->get_OperationName(), jcr->get_ActionName(0));
index 247b09d17c8c2bc74a714b0e39f7628039806d12..d091fcf87f69c8b28d0ad03ff89e32083c05fd6f 100644 (file)
@@ -503,7 +503,7 @@ void wait_for_storage_daemon_termination(JCR *jcr)
 
 void terminate_sd_msg_chan_thread(JCR *jcr)
 {
-   if (jcr->store_bsock) {
+   if (jcr && jcr->store_bsock) {
       jcr->store_bsock->signal(BNET_TERMINATE);
       jcr->lock();
       if (  !jcr->sd_msg_thread_done