]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_cmds.c
Add auto-changer support -- kes17Jul02
[bacula/bacula] / bacula / src / dird / ua_cmds.c
index 3f1ee1c59f0d9236e26131ba634fdb0485aa2c55..83228fff2b6e72a99370f858eac660730a83ff2f 100644 (file)
@@ -39,7 +39,6 @@ extern int r_first;
 extern int r_last;
 extern struct s_res resources[];
 extern int console_msg_pending;
-extern FILE *con_fd;
 extern char my_name[];
 
 /* Imported functions */
@@ -92,7 +91,7 @@ static struct cmdstruct commands[] = {
  { N_("sqlquery"),   sqlquerycmd,  _("use SQL to query catalog")}, 
  { N_("status"),     statuscmd,    _("status [storage | client]=<name>")},
  { N_("unmount"),    unmountcmd,   _("unmount <storage-name>")},
- { N_("update"),     updatecmd,    _("update DB Pool from resource")},
+ { N_("update"),     updatecmd,    _("update Volume or Pool")},
  { N_("use"),        usecmd,       _("use catalog xxx")},
  { N_("version"),    versioncmd,   _("print Director version")},
  { N_("quit"),       quitcmd,      _("quit")},
@@ -342,6 +341,7 @@ static int cancelcmd(UAContext *ua, char *cmd)
         free_locked_jcr(jcr);
       }
       unlock_jcr_chain();
+
       if (njobs == 0) {
          bsendmsg(ua, _("No Jobs running.\n"));
         return 1;
@@ -357,6 +357,7 @@ static int cancelcmd(UAContext *ua, char *cmd)
         free_locked_jcr(jcr);
       }
       unlock_jcr_chain();
+
       if (do_prompt(ua, _("Choose Job to cancel"), JobName) < 0) {
         return 1;
       }
@@ -499,6 +500,7 @@ Use update to change it.\n"), pool->hdr.name);
    default:
      break;
    }
+   bsendmsg(ua, _("Pool %s created.\n"), pool->hdr.name);
    return 1;
 }
 
@@ -539,8 +541,8 @@ static int updatecmd(UAContext *ua, char *cmd)
    }
     
    start_prompt(ua, _("Update choice:\n"));
-   add_prompt(ua, _("pool"));
-   add_prompt(ua, _("volume"));
+   add_prompt(ua, _("Pool from resource"));
+   add_prompt(ua, _("Volume parameters"));
    switch (do_prompt(ua, _("Choose catalog item to update"), NULL)) {
       case 0:
         update_pool(ua);
@@ -568,7 +570,7 @@ static int update_volume(UAContext *ua)
    static char *kw[] = {
       "volume",
       NULL};
-   char *query;
+   POOLMEM *query;
    char ed1[30];
 
    memset(&pr, 0, sizeof(pr));
@@ -590,20 +592,22 @@ static int update_volume(UAContext *ua)
       }
       strcpy(mr.VolumeName, ua->cmd);
    }
-   mr.MediaId = 0;
-   if (!db_get_media_record(ua->db, &mr)) {
-      bsendmsg(ua, _("Volume record for %s not found.\n"), mr.VolumeName);
-      return 0;
-   }
 
    for (int done=0; !done; ) {
+      mr.MediaId = 0;
+      if (!db_get_media_record(ua->db, &mr)) {
+         bsendmsg(ua, _("Volume record for %s not found.\n"), mr.VolumeName);
+        return 0;
+      }
       start_prompt(ua, _("Parameters to modify:\n"));
       add_prompt(ua, _("Volume Status"));
-      add_prompt(ua, _("Volume Retention"));
+      add_prompt(ua, _("Volume Retention Period"));
+      add_prompt(ua, _("Recycle Flag"));
+      add_prompt(ua, _("Slot"));
       add_prompt(ua, _("Done"));
       switch (do_prompt(ua, _("Select paramter to modify"), NULL)) {
       case 0:                        /* Volume Status */
-        /* Modify Volume */
+        /* Modify Volume Status */
          bsendmsg(ua, _("Current value is: %s\n"), mr.VolStatus);
          start_prompt(ua, _("Possible Values are:\n"));
          add_prompt(ua, "Append");
@@ -618,7 +622,7 @@ static int update_volume(UAContext *ua)
            return 1;
         }
         strcpy(mr.VolStatus, ua->cmd);
-        query = (char *)get_pool_memory(PM_MESSAGE);
+        query = get_pool_memory(PM_MESSAGE);
          Mmsg(&query, "UPDATE Media SET VolStatus=\"%s\" WHERE MediaId=%d",
            mr.VolStatus, mr.MediaId);
         if (!db_sql_query(ua->db, query, NULL, NULL)) {  
@@ -636,7 +640,7 @@ static int update_volume(UAContext *ua)
             bsendmsg(ua, _("Invalid retention period specified.\n"));
            break;
         }
-        query = (char *)get_pool_memory(PM_MESSAGE);
+        query = get_pool_memory(PM_MESSAGE);
          Mmsg(&query, "UPDATE Media SET VolRetention=%s WHERE MediaId=%d",
            edit_uint64(mr.VolRetention, ed1), mr.MediaId);
         if (!db_sql_query(ua->db, query, NULL, NULL)) {  
@@ -644,8 +648,60 @@ static int update_volume(UAContext *ua)
         }       
         free_pool_memory(query);
         break;
+      case 2:                        /* Recycle */
+        int recycle;
+         bsendmsg(ua, _("Current value is: %s\n"),
+            mr.Recycle==1?_("yes"):_("no"));
+         if (!get_cmd(ua, _("Enter new Recycle status: "))) {
+           return 0;
+        }
+         if (strcasecmp(ua->cmd, _("yes")) == 0) {
+           recycle = 1;
+         } else if (strcasecmp(ua->cmd, _("no")) == 0) {
+           recycle = 0;
+        } else {
+            bsendmsg(ua, _("Invalid recycle status specified.\n"));
+           break;
+        }
+        query = get_pool_memory(PM_MESSAGE);
+         Mmsg(&query, "UPDATE Media SET Recycle=%d WHERE MediaId=%d",
+           recycle, mr.MediaId);
+        if (!db_sql_query(ua->db, query, NULL, NULL)) {  
+            bsendmsg(ua, "%s", db_strerror(ua->db));
+        }       
+        free_pool_memory(query);
+        break;
+
+      case 3:                        /* Slot */
+        int slot;
+         bsendmsg(ua, _("Current value is: %d\n"), mr.Slot);
+         if (!get_cmd(ua, _("Enter new Slot: "))) {
+           return 0;
+        }
+        slot = atoi(ua->cmd);
+        if (slot < 0) {
+            bsendmsg(ua, _("Invalid slot, it must be 0 or greater\n"));
+           break;
+        } else if (pr.MaxVols > 0 && slot >(int)pr.MaxVols) {
+            bsendmsg(ua, _("Invalid slot, it must be between 0 and %d\n"),
+              pr.MaxVols);
+           break;
+        }
+        query = get_pool_memory(PM_MESSAGE);
+         Mmsg(&query, "UPDATE Media SET Slot=%d WHERE MediaId=%d",
+           slot, mr.MediaId);
+        if (!db_sql_query(ua->db, query, NULL, NULL)) {  
+            bsendmsg(ua, "%s", db_strerror(ua->db));
+        } else {
+            bsendmsg(ua, "New value is: %d\n", slot);
+        }
+        free_pool_memory(query);
+        break;
+
+        
       default:                       /* Done or error */
-        return 0;
+         bsendmsg(ua, "Selection done.\n");
+        return 1;
       }
    }
    return 1;
@@ -660,11 +716,17 @@ static int update_pool(UAContext *ua)
    int id;
    POOL *pool;
    
+   
+   pool = get_pool_resource(ua);
+   if (!pool) {
+      return 0;
+   }
+
    memset(&pr, 0, sizeof(pr));
+   strcpy(pr.Name, pool->hdr.name);
    if (!get_pool_dbr(ua, &pr)) {
-      return 1;
+      return 0;
    }
-
    strcpy(pr.PoolType, pool->pool_type);
    if (pr.MaxVols != (uint32_t) (pool->max_volumes)) {
       pr.MaxVols = pool->max_volumes;
@@ -682,8 +744,10 @@ static int update_pool(UAContext *ua)
    }
    id = db_update_pool_record(ua->db, &pr);
    if (id <= 0) {
-      bsendmsg(ua, "Error: db_update_pool_record returned %d\n", id);
+      bsendmsg(ua, _("db_update_pool_record returned %d. ERR=%s\n"),
+        id, db_strerror(ua->db));
    }
+   bsendmsg(ua, _("Pool DB record updated from resource.\n"));
    return 1;
 }