]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/migrate.c
kes Fix memory leak with storage ids in cats/sql_get.c
[bacula/bacula] / bacula / src / dird / migrate.c
index 88a5189d3a860be6ba8575da8c8e1e9b610f8a18..6d21bd8a4af09ee4ffb40366ca3f91ab4940cdb0 100644 (file)
@@ -277,25 +277,6 @@ bool do_migration(JCR *jcr)
    Jmsg(jcr, M_INFO, 0, _("Start Migration JobId %s, Job=%s\n"),
         edit_uint64(jcr->JobId, ed1), jcr->Job);
 
-   set_jcr_job_status(jcr, JS_Running);
-   set_jcr_job_status(mig_jcr, JS_Running);
-   Dmsg2(dbglevel, "JobId=%d JobLevel=%c\n", (int)jcr->jr.JobId, jcr->jr.JobLevel);
-
-   /* Update job start record for this migration control job */
-   if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
-      Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
-      return false;
-   }
-
-   Dmsg4(dbglevel, "mig_jcr: Name=%s JobId=%d Type=%c Level=%c\n",
-      mig_jcr->jr.Name, (int)mig_jcr->jr.JobId, 
-      mig_jcr->jr.JobType, mig_jcr->jr.JobLevel);
-
-   /* Update job start record for the real migration backup job */
-   if (!db_update_job_start_record(mig_jcr, mig_jcr->db, &mig_jcr->jr)) {
-      Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(mig_jcr->db));
-      return false;
-   }
 
 
    /*
@@ -335,6 +316,49 @@ bool do_migration(JCR *jcr)
       return false;
    }
 
+   /*    
+    * We re-update the job start record so that the start
+    *  time is set after the run before job.  This avoids 
+    *  that any files created by the run before job will
+    *  be saved twice.  They will be backed up in the current
+    *  job, but not in the next one unless they are changed.
+    *  Without this, they will be backed up in this job and
+    *  in the next job run because in that case, their date 
+    *   is after the start of this run.
+    */
+   jcr->start_time = time(NULL);
+   jcr->jr.StartTime = jcr->start_time;
+   jcr->jr.JobTDate = jcr->start_time;
+   set_jcr_job_status(jcr, JS_Running);
+
+   /* Update job start record for this migration control job */
+   if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
+      Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
+      return false;
+   }
+
+
+   mig_jcr->start_time = time(NULL);
+   mig_jcr->jr.StartTime = mig_jcr->start_time;
+   mig_jcr->jr.JobTDate = mig_jcr->start_time;
+   set_jcr_job_status(mig_jcr, JS_Running);
+
+   /* Update job start record for the real migration backup job */
+   if (!db_update_job_start_record(mig_jcr, mig_jcr->db, &mig_jcr->jr)) {
+      Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(mig_jcr->db));
+      return false;
+   }
+
+   Dmsg4(dbglevel, "mig_jcr: Name=%s JobId=%d Type=%c Level=%c\n",
+      mig_jcr->jr.Name, (int)mig_jcr->jr.JobId, 
+      mig_jcr->jr.JobType, mig_jcr->jr.JobLevel);
+
+
+   /*
+    * Start the job prior to starting the message thread below
+    * to avoid two threads from using the BSOCK structure at
+    * the same time.
+    */
    if (!bnet_fsend(sd, "run")) {
       return false;
    }
@@ -848,9 +872,10 @@ static bool find_mediaid_then_jobids(JCR *jcr, idpkt *ids, const char *query1,
    }
    if (ids->count == 0) {
       Jmsg(jcr, M_INFO, 0, _("No %ss found to migrate.\n"), type);
-   }
-   if (ids->count != 1) {
-      Jmsg(jcr, M_FATAL, 0, _("SQL logic error. Count should be 1 but is %d\n"), 
+      ok = true;         /* Not an error */
+      goto bail_out;
+   } else if (ids->count != 1) {
+      Jmsg(jcr, M_FATAL, 0, _("SQL error. Expected 1 MediaId got %d\n"), 
          ids->count);
       goto bail_out;
    }
@@ -977,6 +1002,9 @@ static bool regex_find_jobids(JCR *jcr, idpkt *ids, const char *query1,
 
 bail_out:
    Dmsg2(dbglevel, "Count=%d Jobids=%s\n", ids->count, ids->list);
+   foreach_dlist(item, item_chain) {
+      free(item->item);
+   }
    delete item_chain;
    return ok;
 }