]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_run.c
Add heap stats to Dir and SD -- eliminate #ifdefs
[bacula/bacula] / bacula / src / dird / ua_run.c
index d8c96b821ec97d1968d16b63720d71490305ac23..6fdd3478474202b50e6bc3c868f1e028481f0f85 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 /*
-   Copyright (C) 2001-2003 Kern Sibbald and John Walker
+   Copyright (C) 2001-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -33,7 +33,6 @@
 /* Imported subroutines */
 
 /* Imported variables */
-extern struct s_jl joblevels[];
 extern struct s_kw ReplaceOptions[];
 
 /*
@@ -44,22 +43,23 @@ extern struct s_kw ReplaceOptions[];
  *     run <job-name> jobid=nn
  *
  */
-int run_cmd(UAContext *ua, char *cmd)
+int run_cmd(UAContext *ua, const char *cmd)
 {
    JCR *jcr;
    char *job_name, *level_name, *jid, *store_name, *pool_name;
-   char *where, *fileset_name, *client_name, *bootstrap, *replace;
+   char *where, *fileset_name, *client_name, *bootstrap;
+   const char *replace;
    char *when, *verify_job_name;
    int Priority = 0;
-   int i, j, opt;
-   bool found;
+   int i, j, opt, files = 0;
+   bool kw_ok;
    JOB *job = NULL;
    JOB *verify_job = NULL;
    STORE *store = NULL;
    CLIENT *client = NULL;
    FILESET *fileset = NULL;
    POOL *pool = NULL;
-   static char *kw[] = {             /* command line arguments */
+   static const char *kw[] = {       /* command line arguments */
       N_("job"),                      /*  Used in a switch() */
       N_("jobid"),                    /* 1 */
       N_("client"),                   /* 2 */
@@ -75,12 +75,11 @@ int run_cmd(UAContext *ua, char *cmd)
       N_("when"),                     /* 12 */
       N_("priority"),                 /* 13 */
       N_("yes"),          /* 14 -- if you change this change YES_POS too */
-      N_("run"),          /* 15 -- if you change this change RUN_POS too */
-      N_("verifyjob"),                /* 16 */
+      N_("verifyjob"),                /* 15 */
+      N_("files"),                    /* 16 number of files to restore */
       NULL};
 
 #define YES_POS 14
-#define RUN_POS 15
 
    if (!open_db(ua)) {
       return 1;
@@ -100,12 +99,13 @@ int run_cmd(UAContext *ua, char *cmd)
    verify_job_name = NULL;
 
    for (i=1; i<ua->argc; i++) {
-      found = false;
       Dmsg2(200, "Doing arg %d = %s\n", i, ua->argk[i]);
-      for (j=0; !found && kw[j]; j++) {
+      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 (!ua->argv[i] && (j != YES_POS /*yes*/ && j != RUN_POS)) {  
+           if (!ua->argv[i] && j != YES_POS /*yes*/) {  
                bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
               return 1;
            }
@@ -117,7 +117,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               job_name = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 1: /* JobId */
               if (jid) {
@@ -125,7 +125,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               jid = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 2: /* client */
            case 3: /* fd */
@@ -134,7 +134,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               client_name = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 4: /* fileset */
               if (fileset_name) {
@@ -142,7 +142,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               fileset_name = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 5: /* level */
               if (level_name) {
@@ -150,7 +150,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               level_name = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 6: /* storage */
            case 7: /* sd */
@@ -159,7 +159,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               store_name = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 8: /* pool */
               if (pool_name) {
@@ -167,7 +167,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               pool_name = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 9: /* where */
               if (where) {
@@ -175,7 +175,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               where = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 10: /* bootstrap */
               if (bootstrap) {
@@ -183,7 +183,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               bootstrap = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 11: /* replace */
               if (replace) {
@@ -191,7 +191,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               replace = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 12: /* When */
               if (when) {
@@ -199,7 +199,7 @@ int run_cmd(UAContext *ua, char *cmd)
                  return 1;
               }
               when = ua->argv[i];
-              found = true;
+              kw_ok = true;
               break;
            case 13:  /* Priority */
               if (Priority) {
@@ -211,18 +211,22 @@ int run_cmd(UAContext *ua, char *cmd)
                   bsendmsg(ua, _("Priority must be positive nonzero setting it to 10.\n"));
                  Priority = 10;
               }
+              kw_ok = true;
               break;
            case 14: /* yes */
-           case 15: /* run */
-              found = true;
+              kw_ok = true;
               break;
-           case 16: /* Verify Job */
+           case 15: /* Verify Job */
               if (verify_job_name) {
                   bsendmsg(ua, _("Verify Job specified twice.\n"));
                  return 1;
               }
               verify_job_name = ua->argv[i];
-              found = true;
+              kw_ok = true;
+              break;
+           case 16: /* files */
+              files = atoi(ua->argv[i]);
+              kw_ok = true;
               break;
 
            default:
@@ -230,7 +234,10 @@ int run_cmd(UAContext *ua, char *cmd)
            }
         } /* end strcase compare */
       } /* end keyword loop */
-      if (!found) {
+      /*
+       * End of keyword for loop -- if not found, we got a bogus keyword
+       */
+      if (!kw_ok) {
          Dmsg1(200, "%s not found\n", ua->argk[i]);
         /*
          * Special case for Job Name, it can be the first
@@ -252,7 +259,9 @@ int run_cmd(UAContext *ua, char *cmd)
       /* Find Job */
       job = (JOB *)GetResWithName(R_JOB, job_name);
       if (!job) {
-         bsendmsg(ua, _("Job \"%s\" not found\n"), job_name);
+        if (*job_name != 0) {
+            bsendmsg(ua, _("Job \"%s\" not found\n"), job_name);
+        }
         job = select_job_resource(ua);
       } else {
          Dmsg1(200, "Found job=%s\n", job_name);
@@ -268,7 +277,9 @@ int run_cmd(UAContext *ua, char *cmd)
    if (store_name) {
       store = (STORE *)GetResWithName(R_STORAGE, store_name);
       if (!store) {
-         bsendmsg(ua, _("Storage \"%s\" not found.\n"), store_name);
+        if (*store_name != 0) {
+            bsendmsg(ua, _("Storage \"%s\" not found.\n"), store_name);
+        }
         store = select_storage_resource(ua);
       }
    } else {
@@ -282,17 +293,24 @@ int run_cmd(UAContext *ua, char *cmd)
    if (pool_name) {
       pool = (POOL *)GetResWithName(R_POOL, pool_name);
       if (!pool) {
-         bsendmsg(ua, _("Pool \"%s\" not found.\n"), pool_name);
-        pool = get_pool_resource(ua);
+        if (*pool_name != 0) {
+            bsendmsg(ua, _("Pool \"%s\" not found.\n"), pool_name);
+        }
+        pool = select_pool_resource(ua);
       }
    } else {
       pool = job->pool;            /* use default */
    }
+   if (!pool) {
+      return 1;
+   }
 
    if (client_name) {
       client = (CLIENT *)GetResWithName(R_CLIENT, client_name);
       if (!client) {
-         bsendmsg(ua, _("Client \"%s\" not found.\n"), client_name);
+        if (*client_name != 0) {
+            bsendmsg(ua, _("Client \"%s\" not found.\n"), client_name);
+        }
         client = select_client_resource(ua);
       }
    } else {
@@ -336,6 +354,7 @@ int run_cmd(UAContext *ua, char *cmd)
    jcr->client = client;
    jcr->fileset = fileset;
    jcr->pool = pool;
+   jcr->ExpectedFiles = files;
    if (where) {
       if (jcr->where) {
         free(jcr->where);
@@ -386,6 +405,29 @@ try_again:
         replace = ReplaceOptions[i].name;
       }
    }
+   if (level_name) {
+      if (!get_level_from_name(jcr, level_name)) {
+         bsendmsg(ua, _("Level %s not valid.\n"), level_name);
+        goto bail_out;
+      }
+   }
+   if (jid) {
+      jcr->RestoreJobId = atoi(jid);
+   }
+
+   /* Run without prompting? */
+   if (find_arg(ua, _("yes")) > 0) {
+      Dmsg1(200, "Calling run_job job=%x\n", jcr->job);
+      run_job(jcr);
+      free_jcr(jcr);                 /* release jcr */
+      bsendmsg(ua, _("Run command submitted.\n"));
+      return 1;
+   }
+
+   /*  
+    * Prompt User to see if all run job parameters are correct, and
+    *  allow him to modify them.
+    */
    Dmsg1(20, "JobType=%c\n", jcr->JobType);
    switch (jcr->JobType) {
       char ec1[30];
@@ -409,22 +451,6 @@ Priority: %d\n"),
       break;
    case JT_BACKUP:
    case JT_VERIFY:
-      if (level_name) {
-        /* Look up level name and pull code */
-        found = 0;
-        for (i=0; joblevels[i].level_name; i++) {
-           if (strcasecmp(level_name, _(joblevels[i].level_name)) == 0) {
-              jcr->JobLevel = joblevels[i].level;
-              found = 1;
-              break;
-           }
-        }
-        if (!found) { 
-            bsendmsg(ua, _("Level %s not valid.\n"), level_name);
-           goto bail_out;
-        }
-      }
-      level_name = NULL;
       if (jcr->JobType == JT_BACKUP) {
          bsendmsg(ua, _("Run %s job\n\
 JobName:  %s\n\
@@ -445,7 +471,7 @@ Priority: %d\n"),
                 bstrutime(dt, sizeof(dt), jcr->sched_time),
                 jcr->JobPriority);
       } else { /* JT_VERIFY */
-        char *Name;
+        const char *Name;
         if (jcr->job->verify_job) {
            Name = jcr->job->verify_job->hdr.name;
         } else {
@@ -535,14 +561,6 @@ Priority:   %d\n"),
       goto bail_out;
    }
 
-   /* Run without prompting? */
-   if (find_arg(ua, _("yes")) > 0) {
-      Dmsg1(200, "Calling run_job job=%x\n", jcr->job);
-      run_job(jcr);
-      free_jcr(jcr);                 /* release jcr */
-      bsendmsg(ua, _("Run command submitted.\n"));
-      return 1;
-   }
 
    if (!get_cmd(ua, _("OK to run? (yes/mod/no): "))) {
       goto bail_out;