]> 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 aa5d80b598fb9acb786b04921bd691ee53008914..1b6c87b846ff1e9d992a78ccfa24766181d0e56d 100644 (file)
@@ -1,3 +1,30 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   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.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 /*
  *
  *   Bacula Director -- Update command processing
  *
  *   Version $Id$
  */
-/*
-   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
-   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,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-   the file LICENSE for additional details.
-
- */
 
 #include "bacula.h"
 #include "dird.h"
 
-/* Imported functions */
-void update_slots(UAContext *ua);
-
-
-
 /* Forward referenced functions */
 static int update_volume(UAContext *ua);
 static bool update_pool(UAContext *ua);
@@ -54,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;
    }
 
@@ -105,6 +113,7 @@ static void update_volstatus(UAContext *ua, const char *val, MEDIA_DBR *mr)
       NT_("Cleaning"),
       NT_("Recycle"),
       NT_("Read-Only"),
+      NT_("Error"),
       NULL};
    bool found = false;
    int i;
@@ -281,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;
@@ -317,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
  */
@@ -364,17 +402,8 @@ static void update_all_vols_from_pool(UAContext *ua)
 
 static void update_volenabled(UAContext *ua, char *val, MEDIA_DBR *mr)
 {
-   if (strcasecmp(val, "yes") == 0 || strcasecmp(val, "true") == 0) {
-      mr->Enabled = 1;
-   } else if (strcasecmp(val, "no") == 0 || strcasecmp(val, "false") == 0) {
-      mr->Enabled = 0;
-   } else if (strcasecmp(val, "archived") == 0) { 
-      mr->Enabled = 2;
-   } else {
-      mr->Enabled = atoi(val);
-   }
-   if (mr->Enabled < 0 || mr->Enabled > 2) {
-      bsendmsg(ua, _("Invalid Enabled, it must be 0, 1, or 2\n"));
+   mr->Enabled = get_enabled(ua, val);
+   if (mr->Enabled < 0) {
       return;
    }
    if (!db_update_media_record(ua->jcr, ua->db, mr)) {
@@ -414,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 */
@@ -472,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;
       }
@@ -493,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;
          }
@@ -665,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;
@@ -696,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) {