]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_update.c
ebl Commit file relocation
[bacula/bacula] / bacula / src / dird / ua_update.c
index 4fdfd09b4475a2b74051c7c39408ecabf1cb272a..1b6c87b846ff1e9d992a78ccfa24766181d0e56d 100644 (file)
@@ -1,16 +1,7 @@
-/*
- *
- *   Bacula Director -- Update command processing
- *     Split from ua_cmds.c March 2005
- *
- *     Kern Sibbald, September MM
- *
- *   Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *
+ *   Bacula Director -- Update command processing
+ *     Split from ua_cmds.c March 2005
+ *
+ *     Kern Sibbald, September MM
+ *
+ *   Version $Id$
+ */
 
 #include "bacula.h"
 #include "dird.h"
@@ -62,7 +62,7 @@ int update_cmd(UAContext *ua, const char *cmd)
       NT_("slots"),  /* 3 */
       NULL};
 
-   if (!open_db(ua)) {
+   if (!open_client_db(ua)) {
       return 1;
    }
 
@@ -114,7 +114,6 @@ static void update_volstatus(UAContext *ua, const char *val, MEDIA_DBR *mr)
       NT_("Recycle"),
       NT_("Read-Only"),
       NT_("Error"),
-      NT_("Purged"),
       NULL};
    bool found = false;
    int i;
@@ -291,7 +290,7 @@ static void update_volslot(UAContext *ua, char *val, MEDIA_DBR *mr)
 }
 
 /* Modify the Pool in which this Volume is located */
-static void update_vol_pool(UAContext *ua, char *val, MEDIA_DBR *mr, POOL_DBR *opr)
+void update_vol_pool(UAContext *ua, char *val, MEDIA_DBR *mr, POOL_DBR *opr)
 {
    POOL_DBR pr;
    POOLMEM *query;
@@ -327,6 +326,35 @@ static void update_vol_pool(UAContext *ua, char *val, MEDIA_DBR *mr, POOL_DBR *o
    free_pool_memory(query);
 }
 
+/* Modify the RecyclePool of a Volume */
+void update_vol_recyclepool(UAContext *ua, char *val, MEDIA_DBR *mr)
+{
+   POOL_DBR pr;
+   POOLMEM *query;
+   char ed1[50], ed2[50];
+
+   memset(&pr, 0, sizeof(pr));
+   bstrncpy(pr.Name, val, sizeof(pr.Name));
+   if (!get_pool_dbr(ua, &pr, NT_("recyclepool"))) {
+      return;
+   }
+   /* pool = select_pool_resource(ua);  */
+   mr->RecyclePoolId = pr.PoolId;            /* get the PoolId */
+
+   query = get_pool_memory(PM_MESSAGE);
+   db_lock(ua->db);
+   Mmsg(query, "UPDATE Media SET RecyclePoolId=%s WHERE MediaId=%s",
+      edit_int64(mr->RecyclePoolId, ed1),
+      edit_int64(mr->MediaId, ed2));
+   if (!db_sql_query(ua->db, query, NULL, NULL)) {
+      bsendmsg(ua, "%s", db_strerror(ua->db));
+   } else {
+      bsendmsg(ua, _("New RecyclePool is: %s\n"), pr.Name);
+   }
+   db_unlock(ua->db);
+   free_pool_memory(query);
+}
+
 /*
  * Refresh the Volume information from the Pool record
  */
@@ -415,6 +443,7 @@ static int update_volume(UAContext *ua)
       _("FromPool"),                 /* 10 */
       _("AllFromPool"),              /* 11 !!! see below !!! */
       _("Enabled"),                  /* 12 */
+      _("RecyclePool"),              /* 13 */
       NULL };
 
 #define AllFromPool 11               /* keep this updated with above */
@@ -473,6 +502,9 @@ static int update_volume(UAContext *ua)
          case 12:
             update_volenabled(ua, ua->argv[j], &mr);
             break;
+         case 13:
+            update_vol_recyclepool(ua, ua->argv[j], &mr);
+            break;
          }
          done = true;
       }
@@ -494,11 +526,12 @@ static int update_volume(UAContext *ua)
       add_prompt(ua, _("Volume from Pool"));           /* 11 */
       add_prompt(ua, _("All Volumes from Pool"));      /* 12 */
       add_prompt(ua, _("Enabled")),                    /* 13 */
-      add_prompt(ua, _("Done"));                       /* 14 */
+      add_prompt(ua, _("RecyclePool")),                /* 14 */
+      add_prompt(ua, _("Done"));                       /* 15 */
       i = do_prompt(ua, "", _("Select parameter to modify"), NULL, 0);  
 
       /* For All Volumes from Pool and Done, we don't need a Volume record */
-      if (i != 12 && i != 14) {
+      if (i != 12 && i != 15) {
          if (!select_media_dbr(ua, &mr)) {  /* Get Volume record */
             return 0;
          }
@@ -666,6 +699,20 @@ static int update_volume(UAContext *ua)
          update_volenabled(ua, ua->cmd, &mr);
          break;
 
+      case 14:
+         memset(&pr, 0, sizeof(POOL_DBR));
+         pr.PoolId = mr.RecyclePoolId;
+         if (db_get_pool_record(ua->jcr, ua->db, &pr)) {
+            bsendmsg(ua, _("Current RecyclePool is: %s\n"), pr.Name);
+         } else {
+            bsendmsg(ua, _("No current RecyclePool\n"));
+         }
+         if (!get_cmd(ua, _("Enter new RecyclePool name: "))) {
+            return 0;
+         }
+         update_vol_recyclepool(ua, ua->cmd, &mr);
+         return 1;
+
       default:                        /* Done or error */
          bsendmsg(ua, _("Selection terminated.\n"));
          return 1;
@@ -697,6 +744,7 @@ static bool update_pool(UAContext *ua)
    }
 
    set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE); /* update */
+   set_pooldbr_recyclepoolid(ua->jcr, ua->db, &pr, pool);
 
    id = db_update_pool_record(ua->jcr, ua->db, &pr);
    if (id <= 0) {