]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_run.c
======================= Warning ==========================
[bacula/bacula] / bacula / src / dird / ua_run.c
index 8187c5c11cf852dd2606302fc8d92b66c556a7ae..334fe079c1e733a85c27d9b174e4a201267e9e16 100644 (file)
@@ -7,11 +7,11 @@
  *   Version $Id$
  */
 /*
  *   Version $Id$
  */
 /*
-   Copyright (C) 2001-2005 Kern Sibbald
+   Copyright (C) 2001-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
-   version 2 as ammended with additional clauses defined in the
+   version 2 as amended with additional clauses defined in the
    file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
    file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
@@ -34,7 +34,7 @@ extern struct s_kw ReplaceOptions[];
  *     run [job=]<job-name> level=<level-name>
  *
  * For Restore Jobs
  *     run [job=]<job-name> level=<level-name>
  *
  * For Restore Jobs
- *     run <job-name> jobid=nn
+ *     run <job-name> 
  *
  *  Returns: 0 on error
  *           JobId if OK
  *
  *  Returns: 0 on error
  *           JobId if OK
@@ -47,13 +47,16 @@ int run_cmd(UAContext *ua, const char *cmd)
    char *where, *fileset_name, *client_name, *bootstrap;
    const char *replace;
    char *when, *verify_job_name, *catalog_name;
    char *where, *fileset_name, *client_name, *bootstrap;
    const char *replace;
    char *when, *verify_job_name, *catalog_name;
+   char *previous_job_name;
    char *since = NULL;
    char *since = NULL;
+   char *verify_list;
    bool cloned = false;
    int Priority = 0;
    int i, j, opt, files = 0;
    bool kw_ok;
    JOB *job = NULL;
    JOB *verify_job = NULL;
    bool cloned = false;
    int Priority = 0;
    int i, j, opt, files = 0;
    bool kw_ok;
    JOB *job = NULL;
    JOB *verify_job = NULL;
+   JOB *previous_job = NULL;
    STORE *store = NULL;
    CLIENT *client = NULL;
    FILESET *fileset = NULL;
    STORE *store = NULL;
    CLIENT *client = NULL;
    FILESET *fileset = NULL;
@@ -79,6 +82,8 @@ int run_cmd(UAContext *ua, const char *cmd)
       "catalog",                      /* 17 override catalog */
       "since",                        /* 18 since */
       "cloned",                       /* 19 cloned */
       "catalog",                      /* 17 override catalog */
       "since",                        /* 18 since */
       "cloned",                       /* 19 cloned */
+      "verifylist",                   /* 20 verify output list */
+      "migrationjob",                 /* 21 migration job name */
       NULL};
 
 #define YES_POS 14
       NULL};
 
 #define YES_POS 14
@@ -99,15 +104,17 @@ int run_cmd(UAContext *ua, const char *cmd)
    bootstrap = NULL;
    replace = NULL;
    verify_job_name = NULL;
    bootstrap = NULL;
    replace = NULL;
    verify_job_name = NULL;
+   previous_job_name = NULL;
    catalog_name = NULL;
    catalog_name = NULL;
+   verify_list = NULL;
 
    for (i=1; i<ua->argc; i++) {
       Dmsg2(800, "Doing arg %d = %s\n", i, ua->argk[i]);
       kw_ok = false;
       /* Keep looking until we find a good keyword */
       for (j=0; !kw_ok && kw[j]; j++) {
 
    for (i=1; i<ua->argc; i++) {
       Dmsg2(800, "Doing arg %d = %s\n", i, ua->argk[i]);
       kw_ok = false;
       /* Keep looking until we find a good keyword */
       for (j=0; !kw_ok && kw[j]; j++) {
-         if (strcasecmp(ua->argk[i], _(kw[j])) == 0) {
-            /* Note, yes and run have no value, so do not err */
+         if (strcasecmp(ua->argk[i], kw[j]) == 0) {
+            /* Note, yes and run have no value, so do not fail */
             if (!ua->argv[i] && j != YES_POS /*yes*/) {
                bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
                return 1;
             if (!ua->argv[i] && j != YES_POS /*yes*/) {
                bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
                return 1;
@@ -247,6 +254,20 @@ int run_cmd(UAContext *ua, const char *cmd)
                kw_ok = true;
                break;
 
                kw_ok = true;
                break;
 
+            case 20: /* write verify list output */
+               verify_list = ua->argv[i];
+               kw_ok = true;
+               break;
+            case 21: /* Migration Job */
+               if (previous_job_name) {
+                  bsendmsg(ua, _("Migration Job specified twice.\n"));
+                  return 0;
+               }
+               previous_job_name = ua->argv[i];
+               kw_ok = true;
+               break;
+
+
             default:
                break;
             }
             default:
                break;
             }
@@ -393,6 +414,17 @@ int run_cmd(UAContext *ua, const char *cmd)
       verify_job = job->verify_job;
    }
 
       verify_job = job->verify_job;
    }
 
+   if (previous_job_name) {
+      previous_job = (JOB *)GetResWithName(R_JOB, previous_job_name);
+      if (!previous_job) {
+         bsendmsg(ua, _("Migration Job \"%s\" not found.\n"), previous_job_name);
+         previous_job = select_job_resource(ua);
+      }
+   } else {
+      previous_job = job->verify_job;
+   }
+
+
    /*
     * Create JCR to run job.  NOTE!!! after this point, free_jcr()
     *  before returning.
    /*
     * Create JCR to run job.  NOTE!!! after this point, free_jcr()
     *  before returning.
@@ -401,6 +433,7 @@ int run_cmd(UAContext *ua, const char *cmd)
    set_jcr_defaults(jcr, job);
 
    jcr->verify_job = verify_job;
    set_jcr_defaults(jcr, job);
 
    jcr->verify_job = verify_job;
+   jcr->previous_job = previous_job;
    set_storage(jcr, store);
    jcr->client = client;
    jcr->fileset = fileset;
    set_storage(jcr, store);
    jcr->client = client;
    jcr->fileset = fileset;
@@ -461,7 +494,7 @@ int run_cmd(UAContext *ua, const char *cmd)
 
    jcr->cloned = cloned;
 
 
    jcr->cloned = cloned;
 
-   if (find_arg(ua, _("fdcalled")) > 0) {
+   if (find_arg(ua, NT_("fdcalled")) > 0) {
       jcr->file_bsock = dup_bsock(ua->UA_sock);
       ua->quit = true;
    }
       jcr->file_bsock = dup_bsock(ua->UA_sock);
       ua->quit = true;
    }
@@ -480,11 +513,12 @@ try_again:
       }
    }
    if (jid) {
       }
    }
    if (jid) {
+      /* Note, this is also MigrateJobId */
       jcr->RestoreJobId = str_to_int64(jid);
    }
 
    /* Run without prompting? */
       jcr->RestoreJobId = str_to_int64(jid);
    }
 
    /* Run without prompting? */
-   if (ua->batch || find_arg(ua, _("yes")) > 0) {
+   if (ua->batch || find_arg(ua, NT_("yes")) > 0) {
       goto start_job;
    }
 
       goto start_job;
    }
 
@@ -541,6 +575,12 @@ try_again:
          } else {
             Name = "";
          }
          } else {
             Name = "";
          }
+         if (!verify_list) {
+            verify_list = job->WriteVerifyList;
+         }
+         if (!verify_list) {
+            verify_list = "";
+         }
          bsendmsg(ua, _("Run %s job\n"
 "JobName:     %s\n"
 "FileSet:     %s\n"
          bsendmsg(ua, _("Run %s job\n"
 "JobName:     %s\n"
 "FileSet:     %s\n"
@@ -549,6 +589,7 @@ try_again:
 "Storage:     %s\n"
 "Pool:        %s\n"
 "Verify Job:  %s\n"
 "Storage:     %s\n"
 "Pool:        %s\n"
 "Verify Job:  %s\n"
+"Verify List: %s\n"
 "When:        %s\n"
 "Priority:    %d\n"),
               _("Verify"),
 "When:        %s\n"
 "Priority:    %d\n"),
               _("Verify"),
@@ -559,6 +600,7 @@ try_again:
               jcr->store->hdr.name,
               NPRT(jcr->pool->hdr.name),
               Name,
               jcr->store->hdr.name,
               NPRT(jcr->pool->hdr.name),
               Name,
+              verify_list,
               bstrutime(dt, sizeof(dt), jcr->sched_time),
               jcr->JobPriority);
       }
               bstrutime(dt, sizeof(dt), jcr->sched_time),
               jcr->JobPriority);
       }
@@ -622,12 +664,33 @@ try_again:
               jcr->JobPriority);
       }
       break;
               jcr->JobPriority);
       }
       break;
+   case JT_MIGRATE:
+      jcr->JobLevel = L_FULL;      /* default level */
+      bsendmsg(ua, _("Run Migration job\n"
+                     "JobName:       %s\n"
+                     "Bootstrap:     %s\n"
+                     "FileSet:       %s\n"
+                     "Client:        %s\n"
+                     "Storage:       %s\n"
+                     "JobId:         %s\n"
+                     "When:          %s\n"
+                     "Catalog:       %s\n"
+                     "Priority:      %d\n"),
+           job->hdr.name,
+           NPRT(jcr->RestoreBootstrap),
+           jcr->fileset->hdr.name,
+           jcr->client->hdr.name,
+           jcr->store->hdr.name,
+           jcr->MigrateJobId==0?"*None*":edit_uint64(jcr->MigrateJobId, ec1),
+           bstrutime(dt, sizeof(dt), jcr->sched_time),
+           jcr->catalog->hdr.name,
+           jcr->JobPriority);
+      break;
    default:
       bsendmsg(ua, _("Unknown Job Type=%d\n"), jcr->JobType);
       goto bail_out;
    }
 
    default:
       bsendmsg(ua, _("Unknown Job Type=%d\n"), jcr->JobType);
       goto bail_out;
    }
 
-
    if (!get_cmd(ua, _("OK to run? (yes/mod/no): "))) {
       goto bail_out;
    }
    if (!get_cmd(ua, _("OK to run? (yes/mod/no): "))) {
       goto bail_out;
    }
@@ -799,7 +862,7 @@ try_again:
          }
          if (ua->cmd[0] != 0) {
             jcr->RestoreBootstrap = bstrdup(ua->cmd);
          }
          if (ua->cmd[0] != 0) {
             jcr->RestoreBootstrap = bstrdup(ua->cmd);
-            fd = fopen(jcr->RestoreBootstrap, "r");
+            fd = fopen(jcr->RestoreBootstrap, "rb");
             if (!fd) {
                bsendmsg(ua, _("Warning cannot open %s: ERR=%s\n"),
                   jcr->RestoreBootstrap, strerror(errno));
             if (!fd) {
                bsendmsg(ua, _("Warning cannot open %s: ERR=%s\n"),
                   jcr->RestoreBootstrap, strerror(errno));
@@ -851,6 +914,8 @@ try_again:
             bsendmsg(ua, _("You must set the bootstrap file to NULL to be able to specify a JobId.\n"));
          }
          goto try_again;
             bsendmsg(ua, _("You must set the bootstrap file to NULL to be able to specify a JobId.\n"));
          }
          goto try_again;
+      case -1:                        /* error or cancel */
+         goto bail_out;
       default:
          goto try_again;
       }
       default:
          goto try_again;
       }
@@ -862,6 +927,12 @@ try_again:
       Dmsg1(800, "Calling run_job job=%x\n", jcr->job);
 start_job:
       JobId = run_job(jcr);
       Dmsg1(800, "Calling run_job job=%x\n", jcr->job);
 start_job:
       JobId = run_job(jcr);
+#if 0  
+      bsendmsg(ua, "<job director=\"console\" time=\"%u\" status=\"%c\" type=\"%c\" "
+              "jobid=\"%u\" job=\"%s\" level=\"%c\" finished=\"false\" priority=\"%u\"/>\n",
+               time(NULL), jcr->JobStatus, jcr->JobType, jcr->JobId,
+              jcr->Job, jcr->JobLevel, jcr->JobPriority);
+#endif
       free_jcr(jcr);                  /* release jcr */
       if (JobId == 0) {
          bsendmsg(ua, _("Job failed.\n"));
       free_jcr(jcr);                  /* release jcr */
       if (JobId == 0) {
          bsendmsg(ua, _("Job failed.\n"));