]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/migrate.c
kes Fix Verify InitCatalog. The attributes were not pointing to the
[bacula/bacula] / bacula / src / dird / migrate.c
index abe785e4b4ddb3793454b0ff180bd05aff98e775..3484f1324898d3e1bf029e9c297c37b1612afcda 100644 (file)
@@ -182,6 +182,8 @@ bool do_migration_init(JCR *jcr)
       return false;
    }
 
+   jcr->spool_data = job->spool_data;     /* turn on spooling if requested in job */ 
+
    /* Create a migation jcr */
    mig_jcr = jcr->mig_jcr = new_jcr(sizeof(JCR), dird_free_jcr);
    memcpy(&mig_jcr->previous_jr, &jcr->previous_jr, sizeof(mig_jcr->previous_jr));
@@ -198,9 +200,8 @@ bool do_migration_init(JCR *jcr)
 
    /* Now reset the job record from the previous job */
    memcpy(&mig_jcr->jr, &jcr->previous_jr, sizeof(mig_jcr->jr));
-   /* Update the jr to reflect the new values of PoolId, FileSetId, and JobId. */
+   /* Update the jr to reflect the new values of PoolId and JobId. */
    mig_jcr->jr.PoolId = jcr->jr.PoolId;
-   mig_jcr->jr.FileSetId = jcr->jr.FileSetId;
    mig_jcr->jr.JobId = mig_jcr->JobId;
 
    Dmsg4(dbglevel, "mig_jcr: Name=%s JobId=%d Type=%c Level=%c\n",
@@ -518,14 +519,16 @@ const char *sql_jobids_from_vol =
 
 
 const char *sql_smallest_vol = 
-   "SELECT MediaId FROM Media,Pool WHERE"
-   " VolStatus in ('Full','Used','Error') AND Media.Enabled=1 AND"
+   "SELECT Media.MediaId FROM Media,Pool,JobMedia WHERE"
+   " Media.MediaId in (SELECT DISTINCT MediaId from JobMedia) AND"
+   " Media.VolStatus in ('Full','Used','Error') AND Media.Enabled=1 AND"
    " Media.PoolId=Pool.PoolId AND Pool.Name='%s'"
    " ORDER BY VolBytes ASC LIMIT 1";
 
 const char *sql_oldest_vol = 
-   "SELECT MediaId FROM Media,Pool WHERE"
-   " VolStatus in ('Full','Used','Error') AND Media.Enabled=1 AND"
+   "SELECT Media.MediaId FROM Media,Pool,JobMedia WHERE"
+   " Media.MediaId in (SELECT DISTINCT MediaId from JobMedia) AND"
+   " Media.VolStatus in ('Full','Used','Error') AND Media.Enabled=1 AND"
    " Media.PoolId=Pool.PoolId AND Pool.Name='%s'"
    " ORDER BY LastWritten ASC LIMIT 1";
 
@@ -678,8 +681,8 @@ static int get_job_to_migrate(JCR *jcr)
             goto ok_out;
          }
          pool_bytes = ctx.value;
-         Dmsg2(dbglevel, "highbytes=%d pool=%d\n", (int)jcr->rpool->MigrationHighBytes,
-               (int)pool_bytes);
+         Dmsg2(dbglevel, "highbytes=%lld pool=%lld\n", jcr->rpool->MigrationHighBytes,
+               pool_bytes);
          if (pool_bytes < (int64_t)jcr->rpool->MigrationHighBytes) {
             Jmsg(jcr, M_INFO, 0, _("No Volumes found to migrate.\n"));
             goto ok_out;
@@ -719,6 +722,9 @@ static int get_job_to_migrate(JCR *jcr)
             if (!find_jobids_from_mediaid_list(jcr, &mid, "Volumes")) {
                continue;
             }
+            if (mid.count == 0) {
+               continue;                  /* nothing returned */
+            }
             if (i != 0) {
                pm_strcat(jids.list, ",");
             }
@@ -857,11 +863,11 @@ static void start_migration_job(JCR *jcr)
         edit_uint64(jcr->MigrateJobId, ed1));
    Dmsg1(dbglevel, "=============== Migration cmd=%s\n", ua->cmd);
    parse_ua_args(ua);                 /* parse command */
-   int stat = run_cmd(ua, ua->cmd);
-   if (stat == 0) {
+   int jobid = run_cmd(ua, ua->cmd);
+   if (jobid == 0) {
       Jmsg(jcr, M_ERROR, 0, _("Could not start migration job.\n"));
    } else {
-      Jmsg(jcr, M_INFO, 0, _("Migration JobId %d started.\n"), stat);
+      Jmsg(jcr, M_INFO, 0, _("Migration JobId %d started.\n"), jobid);
    }
    free_ua_context(ua);
 }
@@ -880,15 +886,14 @@ static bool find_mediaid_then_jobids(JCR *jcr, idpkt *ids, const char *query1,
       goto bail_out;
    }
    if (ids->count == 0) {
-      Jmsg(jcr, M_INFO, 0, _("No %ss found to migrate.\n"), type);
+      Jmsg(jcr, M_INFO, 0, _("No %s found to migrate.\n"), type);
       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);
+      Jmsg(jcr, M_FATAL, 0, _("SQL error. Expected 1 MediaId got %d\n"), ids->count);
       goto bail_out;
    }
-   Dmsg1(dbglevel, "Smallest Vol Jobids=%s\n", ids->list);
+   Dmsg2(dbglevel, "%s MediaIds=%s\n", type, ids->list);
 
    ok = find_jobids_from_mediaid_list(jcr, ids, type);
 
@@ -896,6 +901,12 @@ bail_out:
    return ok;
 }
 
+/* 
+ * This routine returns:
+ *    false       if an error occurred
+ *    true        otherwise
+ *    ids.count   number of jobids found (may be zero)
+ */       
 static bool find_jobids_from_mediaid_list(JCR *jcr, idpkt *ids, const char *type) 
 {
    bool ok = false;
@@ -911,6 +922,7 @@ static bool find_jobids_from_mediaid_list(JCR *jcr, idpkt *ids, const char *type
       Jmsg(jcr, M_INFO, 0, _("No %ss found to migrate.\n"), type);
    }
    ok = true;
+
 bail_out:
    return ok;
 }
@@ -1070,7 +1082,7 @@ void migration_cleanup(JCR *jcr, int TermCode)
       } 
 
       if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
-         Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
+         Jmsg(jcr, M_WARNING, 0, _("Error getting Job record for Job report: ERR=%s"),
             db_strerror(jcr->db));
          set_jcr_job_status(jcr, JS_ErrorTerminated);
       }
@@ -1152,7 +1164,8 @@ void migration_cleanup(JCR *jcr, int TermCode)
 
    jobstatus_to_ascii(jcr->SDJobStatus, sd_term_msg, sizeof(sd_term_msg));
 
-   Jmsg(jcr, msg_type, 0, _("Bacula %s Version: %s (%s) %s %s %s at %s\n"
+   Jmsg(jcr, msg_type, 0, _("Bacula %s %s (%s): %s\n"
+"  Build OS:               %s %s %s\n"
 "  Prev Backup JobId:      %s\n"
 "  New Backup JobId:       %s\n"
 "  Migration JobId:        %s\n"
@@ -1178,8 +1191,8 @@ void migration_cleanup(JCR *jcr, int TermCode)
 "  SD Errors:              %d\n"
 "  SD termination status:  %s\n"
 "  Termination:            %s\n\n"),
-        my_name, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER,
-        edt, 
+        my_name, VERSION, LSMDATE, edt,
+        HOST_OS, DISTNAME, DISTVER,
         edit_uint64(jcr->previous_jr.JobId, ec6),
         mig_jcr ? edit_uint64(mig_jcr->jr.JobId, ec7) : "0",
         edit_uint64(jcr->jr.JobId, ec8),