]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/migrate.c
26May06
[bacula/bacula] / bacula / src / dird / migrate.c
index 9e79a51c6e53416f4135e7e430309a35c6f66068..5e5f52bf9fe5654e82b37aa6a28a6164d641c687 100644 (file)
@@ -43,6 +43,7 @@ static bool get_job_to_migrate(JCR *jcr);
 struct idpkt;
 static bool regex_find_jobids(JCR *jcr, idpkt *ids, const char *query1,
                  const char *query2, const char *type);
+static void start_migration_job(JCR *jcr);
 
 /* 
  * Called here before the job is run to do the job
@@ -272,6 +273,10 @@ bool do_migration(JCR *jcr)
       return false;
    }
 
+   if (!bnet_fsend(sd, "run")) {
+      return false;
+   }
+
    /*
     * Now start a Storage daemon message thread
     */
@@ -279,9 +284,6 @@ bool do_migration(JCR *jcr)
       return false;
    }
 
-   if (!bnet_fsend(sd, "run")) {
-      return false;
-   }
 
    set_jcr_job_status(jcr, JS_Running);
    set_jcr_job_status(prev_jcr, JS_Running);
@@ -449,8 +451,9 @@ static bool get_job_to_migrate(JCR *jcr)
    ids.count = 0;
 
    if (jcr->MigrateJobId != 0) {
-      jcr->previous_jr.JobId = jcr->MigrateJobId;
       Dmsg1(000, "previous jobid=%u\n", jcr->MigrateJobId);
+      edit_uint64(jcr->MigrateJobId, ids.list);
+      ids.count = 1;
    } else {
       switch (jcr->job->selection_type) {
       case MT_JOB:
@@ -513,6 +516,8 @@ static bool get_job_to_migrate(JCR *jcr)
    JobId = 0;
    stat = get_next_jobid_from_list(&p, &JobId);
    Dmsg2(000, "get_next_jobid stat=%d JobId=%u\n", stat, JobId);
+   jcr->MigrateJobId = JobId;
+   start_migration_job(jcr);
    if (stat < 0) {
       Jmsg(jcr, M_FATAL, 0, _("Invalid JobId found.\n"));
       goto bail_out;
@@ -522,7 +527,7 @@ static bool get_job_to_migrate(JCR *jcr)
    }
    
    jcr->previous_jr.JobId = JobId;
-   Dmsg1(000, "Last jobid=%d\n", jcr->previous_jr.JobId);
+   Dmsg1(000, "Previous jobid=%d\n", jcr->previous_jr.JobId);
 
    if (!db_get_job_record(jcr, jcr->db, &jcr->previous_jr)) {
       Jmsg(jcr, M_FATAL, 0, _("Could not get job record for JobId %s to migrate. ERR=%s"),
@@ -542,6 +547,25 @@ bail_out:
    return false;
 }
 
+static void start_migration_job(JCR *jcr)
+{
+   UAContext *ua = new_ua_context(jcr);
+   char ed1[50];
+   ua->batch = true;
+   Mmsg(ua->cmd, "run %s jobid=%s", jcr->job->hdr.name, 
+        edit_uint64(jcr->MigrateJobId, ed1));
+   Dmsg1(000, "=============== Migration cmd=%s\n", ua->cmd);
+   parse_ua_args(ua);                 /* parse command */
+// int stat = run_cmd(ua, ua->cmd);
+   int stat = (int)jcr->MigrateJobId;
+   if (stat == 0) {
+      Jmsg(jcr, M_ERROR, 0, _("Could not start migration job.\n"));
+   } else {
+      Jmsg(jcr, M_INFO, 0, _("Migration JobId %d started.\n"), stat);
+   }
+   free_ua_context(ua);
+}
+
 
 static bool regex_find_jobids(JCR *jcr, idpkt *ids, const char *query1,
                  const char *query2, const char *type) {