]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_cmds.c
07Jan06
[bacula/bacula] / bacula / src / dird / ua_cmds.c
index ba2208487c3eafdf4273571518c893555767e359..8a224741f7d8d185d7edfc9aa42d4855466db635 100644 (file)
@@ -7,7 +7,7 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   Copyright (C) 2000-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
@@ -143,10 +143,16 @@ int do_a_command(UAContext *ua, const char *cmd)
       return 1;
    }
 
+   while (ua->jcr->storage->size()) {
+      ua->jcr->storage->remove(0);
+   }
+
    len = strlen(ua->argk[0]);
    for (i=0; i<comsize; i++) {     /* search for command */
       if (strncasecmp(ua->argk[0],  _(commands[i].key), len) == 0) {
-         if (!acl_access_ok(ua, Command_ACL, ua->argk[0], len)) {
+         /* Check if command permitted, but "quit" is always OK */
+         if (strcmp(ua->argk[0], "quit") != 0 &&
+             !acl_access_ok(ua, Command_ACL, ua->argk[0], len)) {
             break;
          }
          stat = (*commands[i].func)(ua, cmd);   /* go execute command */
@@ -222,7 +228,7 @@ static int add_cmd(UAContext *ua, const char *cmd)
    }
 
    /* Get media type */
-   if ((store = get_storage_resource(ua, 0)) != NULL) {
+   if ((store = get_storage_resource(ua, false/*no default*/)) != NULL) {
       bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
    } else if (!get_media_type(ua, mr.MediaType, sizeof(mr.MediaType))) {
       return 1;
@@ -396,12 +402,11 @@ static int cancel_cmd(UAContext *ua, const char *cmd)
       /* Count Jobs running */
       foreach_jcr(jcr) {
          if (jcr->JobId == 0) {      /* this is us */
-            free_jcr(jcr);
             continue;
          }
-         free_jcr(jcr);
          njobs++;
       }
+      endeach_jcr(jcr);
 
       if (njobs == 0) {
          bsendmsg(ua, _("No Jobs running.\n"));
@@ -411,13 +416,12 @@ static int cancel_cmd(UAContext *ua, const char *cmd)
       foreach_jcr(jcr) {
          char ed1[50];
          if (jcr->JobId == 0) {      /* this is us */
-            free_jcr(jcr);
             continue;
          }
-         bsnprintf(buf, sizeof(buf), "JobId=%s Job=%s", edit_int64(jcr->JobId, ed1), jcr->Job);
+         bsnprintf(buf, sizeof(buf), _("JobId=%s Job=%s"), edit_int64(jcr->JobId, ed1), jcr->Job);
          add_prompt(ua, buf);
-         free_jcr(jcr);
       }
+      endeach_jcr(jcr);
 
       if (do_prompt(ua, _("Job"),  _("Choose Job to cancel"), buf, sizeof(buf)) < 0) {
          return 1;
@@ -753,7 +757,7 @@ static int setdebug_cmd(UAContext *ua, const char *cmd)
    Dmsg1(120, "setdebug:%s:\n", cmd);
 
    level = -1;
-   i = find_arg_with_value(ua, _("level"));
+   i = find_arg_with_value(ua, "level");
    if (i >= 0) {
       level = atoi(ua->argv[i]);
    }
@@ -765,7 +769,7 @@ static int setdebug_cmd(UAContext *ua, const char *cmd)
    }
 
    /* Look for trace flag. -1 => not change */
-   i = find_arg_with_value(ua, _("trace"));
+   i = find_arg_with_value(ua, "trace");
    if (i >= 0) {
       trace_flag = atoi(ua->argv[i]);
       if (trace_flag > 0) {
@@ -775,18 +779,18 @@ static int setdebug_cmd(UAContext *ua, const char *cmd)
 
    /* General debug? */
    for (i=1; i<ua->argc; i++) {
-      if (strcasecmp(ua->argk[i], _("all")) == 0) {
+      if (strcasecmp(ua->argk[i], "all") == 0) {
          do_all_setdebug(ua, level, trace_flag);
          return 1;
       }
-      if (strcasecmp(ua->argk[i], _("dir")) == 0 ||
-          strcasecmp(ua->argk[i], _("director")) == 0) {
+      if (strcasecmp(ua->argk[i], "dir") == 0 ||
+          strcasecmp(ua->argk[i], "director") == 0) {
          debug_level = level;
          set_trace(trace_flag);
          return 1;
       }
-      if (strcasecmp(ua->argk[i], _("client")) == 0 ||
-          strcasecmp(ua->argk[i], _("fd")) == 0) {
+      if (strcasecmp(ua->argk[i], "client") == 0 ||
+          strcasecmp(ua->argk[i], "fd") == 0) {
          client = NULL;
          if (ua->argv[i]) {
             client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]);
@@ -802,9 +806,9 @@ static int setdebug_cmd(UAContext *ua, const char *cmd)
          }
       }
 
-      if (strcasecmp(ua->argk[i], _("store")) == 0 ||
-          strcasecmp(ua->argk[i], _("storage")) == 0 ||
-          strcasecmp(ua->argk[i], _("sd")) == 0) {
+      if (strcasecmp(ua->argk[i], "store") == 0 ||
+          strcasecmp(ua->argk[i], "storage") == 0 ||
+          strcasecmp(ua->argk[i], "sd") == 0) {
          store = NULL;
          if (ua->argv[i]) {
             store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]);
@@ -813,7 +817,7 @@ static int setdebug_cmd(UAContext *ua, const char *cmd)
                return 1;
             }
          }
-         store = get_storage_resource(ua, 0);
+         store = get_storage_resource(ua, false/*no default*/);
          if (store) {
             do_storage_setdebug(ua, store, level, trace_flag);
             return 1;
@@ -825,17 +829,17 @@ static int setdebug_cmd(UAContext *ua, const char *cmd)
     * prompt the user.
     */
    start_prompt(ua, _("Available daemons are: \n"));
-   add_prompt(ua, _("Director"));
-   add_prompt(ua, _("Storage"));
-   add_prompt(ua, _("Client"));
-   add_prompt(ua, _("All"));
+   add_prompt(ua, "Director");
+   add_prompt(ua, "Storage");
+   add_prompt(ua, "Client");
+   add_prompt(ua, "All");
    switch(do_prompt(ua, "", _("Select daemon type to set debug level"), NULL, 0)) {
    case 0:                         /* Director */
       debug_level = level;
       set_trace(trace_flag);
       break;
    case 1:
-      store = get_storage_resource(ua, 0);
+      store = get_storage_resource(ua, false/*no default*/);
       if (store) {
          do_storage_setdebug(ua, store, level, trace_flag);
       }
@@ -902,37 +906,36 @@ static int estimate_cmd(UAContext *ua, const char *cmd)
    JOB *job = NULL;
    CLIENT *client = NULL;
    FILESET *fileset = NULL;
-   FILESET_DBR fsr;
    int listing = 0;
    char since[MAXSTRING];
    JCR *jcr = ua->jcr;
 
    jcr->JobLevel = L_FULL;
    for (int i=1; i<ua->argc; i++) {
-      if (strcasecmp(ua->argk[i], _("client")) == 0 ||
-          strcasecmp(ua->argk[i], _("fd")) == 0) {
+      if (strcasecmp(ua->argk[i], "client") == 0 ||
+          strcasecmp(ua->argk[i], "fd") == 0) {
          if (ua->argv[i]) {
             client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]);
             continue;
          }
       }
-      if (strcasecmp(ua->argk[i], _("job")) == 0) {
+      if (strcasecmp(ua->argk[i], "job") == 0) {
          if (ua->argv[i]) {
             job = (JOB *)GetResWithName(R_JOB, ua->argv[i]);
             continue;
          }
       }
-      if (strcasecmp(ua->argk[i], _("fileset")) == 0) {
+      if (strcasecmp(ua->argk[i], "fileset") == 0) {
          if (ua->argv[i]) {
             fileset = (FILESET *)GetResWithName(R_FILESET, ua->argv[i]);
             continue;
          }
       }
-      if (strcasecmp(ua->argk[i], _("listing")) == 0) {
+      if (strcasecmp(ua->argk[i], "listing") == 0) {
          listing = 1;
          continue;
       }
-      if (strcasecmp(ua->argk[i], _("level")) == 0) {
+      if (strcasecmp(ua->argk[i], "level") == 0) {
          if (!get_level_from_name(ua->jcr, ua->argv[i])) {
             bsendmsg(ua, _("Level %s not valid.\n"), ua->argv[i]);
          }
@@ -973,7 +976,7 @@ static int estimate_cmd(UAContext *ua, const char *cmd)
    if (!get_or_create_client_record(jcr)) {
       return 1;
    }
-   if (!get_or_create_fileset_record(jcr, &fsr)) {
+   if (!get_or_create_fileset_record(jcr)) {
       return 1;
    }
 
@@ -1068,7 +1071,7 @@ static int delete_cmd(UAContext *ua, const char *cmd)
       return 1;
    case 2:
       int i;
-      while ((i=find_arg(ua, _("jobid"))) > 0) {
+      while ((i=find_arg(ua, "jobid")) > 0) {
          delete_job(ua);
          *ua->argk[i] = 0;         /* zap keyword already visited */
       }
@@ -1112,7 +1115,7 @@ static void delete_job(UAContext *ua)
    JobId_t JobId;
    char *s,*sep,*tok;
 
-   int i = find_arg_with_value(ua, _("jobid"));
+   int i = find_arg_with_value(ua, N_("jobid"));
    if (i >= 0) {
       if (strchr(ua->argv[i], ',') != NULL || strchr(ua->argv[i], '-') != NULL) {
         s = bstrdup(ua->argv[i]);
@@ -1246,21 +1249,23 @@ static void do_mount_cmd(UAContext *ua, const char *command)
    BSOCK *sd;
    JCR *jcr = ua->jcr;
    char dev_name[MAX_NAME_LENGTH];
+   int drive;
 
    if (!open_db(ua)) {
       return;
    }
    Dmsg2(120, "%s: %s\n", command, ua->UA_sock->msg);
 
-   store = get_storage_resource(ua, 1);
+   store = get_storage_resource(ua, true/*arg is storage*/);
    if (!store) {
       return;
    }
+   set_storage(jcr, store);
+   drive = get_storage_drive(ua, store);
 
-   Dmsg2(120, "Found storage, MediaType=%s DevName=%s\n",
-      store->media_type, store->dev_name());
+   Dmsg3(120, "Found storage, MediaType=%s DevName=%s drive=%d\n",
+      store->media_type, store->dev_name(), drive);
 
-   set_storage(jcr, store);
    if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
       bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
       return;
@@ -1268,7 +1273,7 @@ static void do_mount_cmd(UAContext *ua, const char *command)
    sd = jcr->store_bsock;
    bstrncpy(dev_name, store->dev_name(), sizeof(dev_name));
    bash_spaces(dev_name);
-   bnet_fsend(sd, "%s %s", command, dev_name);
+   bnet_fsend(sd, "%s %s drive=%d", command, dev_name, drive);
    while (bnet_recv(sd) >= 0) {
       bsendmsg(ua, "%s", sd->msg);
    }
@@ -1278,7 +1283,7 @@ static void do_mount_cmd(UAContext *ua, const char *command)
 }
 
 /*
- * mount [storage | device] <name>
+ * mount [storage=<name>] [drive=nn]
  */
 static int mount_cmd(UAContext *ua, const char *cmd)
 {
@@ -1288,7 +1293,7 @@ static int mount_cmd(UAContext *ua, const char *cmd)
 
 
 /*
- * unmount [storage | device] <name>
+ * unmount [storage=<name>] [drive=nn]
  */
 static int unmount_cmd(UAContext *ua, const char *cmd)
 {
@@ -1298,7 +1303,7 @@ static int unmount_cmd(UAContext *ua, const char *cmd)
 
 
 /*
- * release [storage | device] <name>
+ * release [storage=<name>] [drive=nn]
  */
 static int release_cmd(UAContext *ua, const char *cmd)
 {
@@ -1349,11 +1354,11 @@ int wait_cmd(UAContext *ua, const char *cmd)
       foreach_jcr(jcr) {
          if (jcr->JobId != 0) {
             running = true;
-            free_jcr(jcr);
             break;
          }
-         free_jcr(jcr);
       }
+      endeach_jcr(jcr);
+
       if (running) {
          bmicrosleep(1, 0);
       }
@@ -1379,14 +1384,14 @@ int qhelp_cmd(UAContext *ua, const char *cmd)
    unsigned int i;
 
    for (i=0; i<comsize; i++) {
-      bsendmsg(ua, _("%s %s\n"), _(commands[i].key), _(commands[i].help));
+      bsendmsg(ua, "%s %s\n", _(commands[i].key), _(commands[i].help));
    }
    return 1;
 }
 
 static int version_cmd(UAContext *ua, const char *cmd)
 {
-   bsendmsg(ua, "%s Version: " VERSION " (" BDATE ")\n", my_name);
+   bsendmsg(ua, _("%s Version: %s (%s)\n"), my_name, VERSION, BDATE);
    return 1;
 }