]> git.sur5r.net Git - bacula/bacula/commitdiff
Rework purge, list volumes rework, remove Win32 pid file
authorKern Sibbald <kern@sibbald.com>
Thu, 13 Mar 2003 19:37:19 +0000 (19:37 +0000)
committerKern Sibbald <kern@sibbald.com>
Thu, 13 Mar 2003 19:37:19 +0000 (19:37 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@379 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/sql_cmds.c
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_output.c
bacula/src/dird/ua_purge.c
bacula/src/lib/bnet.c

index cc7b5b028c3d8c7dcc6c96d713b35a69ed95cf09..84a73ff53b74b67eb23fdfc00b3d98db60e0d7ea 100644 (file)
@@ -30,6 +30,9 @@
 #include "bacula.h"
 #include "dird.h"
 
+/* For ua_cmds.c */
+char *list_pool = "SELECT * FROM Pool WHERE PoolId=%u";
+
 /* ====== ua_prune.c */
 
 char *cnt_File     = "SELECT count(*) FROM File WHERE JobId=%u";
index 82072bee124b3fbe1828993ca027f579383af655..352051e4847779ad626a2e4416f6626a877c250a 100644 (file)
@@ -41,6 +41,8 @@ extern struct s_res resources[];
 extern char my_name[];
 extern workq_t job_wq;               /* work queue */
 
+extern char *list_pool;
+
 /* Imported functions */
 extern int statuscmd(UAContext *ua, char *cmd);
 extern int listcmd(UAContext *ua, char *cmd);
@@ -891,6 +893,7 @@ static int update_pool(UAContext *ua)
    POOL_DBR  pr;
    int id;
    POOL *pool;
+   POOLMEM *query;      
    
    
    pool = get_pool_resource(ua);
@@ -911,6 +914,10 @@ static int update_pool(UAContext *ua)
       bsendmsg(ua, _("db_update_pool_record returned %d. ERR=%s\n"),
         id, db_strerror(ua->db));
    }
+   query = get_pool_memory(PM_MESSAGE);
+   Mmsg(&query, list_pool, pr.PoolId);
+   db_list_sql_query(ua->jcr, ua->db, query, prtit, ua, 1);
+   free_pool_memory(query);
    bsendmsg(ua, _("Pool DB record updated from resource.\n"));
    return 1;
 }
index f862dad02407e069347f3a2692be18dbcca1440f..7fec913b334db9d8c2be75634c7d2661dbd6bba8 100644 (file)
@@ -185,7 +185,8 @@ int showcmd(UAContext *ua, char *cmd)
  *  list files job=name
  *  list pools         - list pool records
  *  list jobtotals     - list totals for all jobs
- *  list media         - list media for given pool
+ *  list media         - list media for given pool (deprecated)
+ *  list volumes       - list Volumes
  *  list clients       - list clients
  *
  */
@@ -309,11 +310,34 @@ int listcmd(UAContext *ua, char *cmd)
         }
         /* if no job or jobid keyword found, then we list all media */
         if (!done) {
-           if (!get_pool_dbr(ua, &pr)) {
+           int num_pools;
+           uint32_t *ids;
+           /* Is a specific pool wanted? */
+           for (i=1; i<ua->argc; i++) {
+               if (strcasecmp(ua->argk[i], _("pool")) == 0) {
+                 if (!get_pool_dbr(ua, &pr)) {
+                    return 1;
+                 }
+                 mr.PoolId = pr.PoolId;
+                 db_list_media_records(ua->jcr, ua->db, &mr, prtit, ua);
+                 return 1;
+              }
+           }
+           /* List Volumes in all pools */
+           if (!db_get_pool_ids(ua->jcr, ua->db, &num_pools, &ids)) {
+               bsendmsg(ua, _("Error obtaining pool ids. ERR=%s\n"), 
+                       db_strerror(ua->db));
               return 1;
            }
-           mr.PoolId = pr.PoolId;
-           db_list_media_records(ua->jcr, ua->db, &mr, prtit, ua);
+           if (num_pools <= 0) {
+              return 1;
+           }
+           for (i=0; i < num_pools; i++) {
+              mr.PoolId = ids[i];
+              db_list_media_records(ua->jcr, ua->db, &mr, prtit, ua);
+           }
+           free(ids);
+           return 1;
         }
       } else {
          bsendmsg(ua, _("Unknown list keyword: %s\n"), NPRT(ua->argk[i]));
index 3c06c0fc188b457c9091099b6a831f53bd9c4f88..82a273006aaffad936f6b664eb86b06b8e3887b0 100644 (file)
@@ -170,6 +170,7 @@ int purgecmd(UAContext *ua, char *cmd)
    static char *keywords[] = {
       N_("files"),
       N_("jobs"),
+      N_("volume"),
       NULL};
 
    static char *files_keywords[] = {
@@ -199,7 +200,7 @@ int purgecmd(UAContext *ua, char *cmd)
    case 0:
       switch(find_arg_keyword(ua, files_keywords)) {
       case 0:                        /* Job */
-      case 1:
+      case 1:                        /* JobId */
         if (get_job_dbr(ua, &jr)) {
            purge_files_from_job(ua, &jr);
         }
@@ -208,7 +209,7 @@ int purgecmd(UAContext *ua, char *cmd)
         client = select_client_resource(ua);
         purge_files_from_client(ua, client);
         return 1;
-      case 3:
+      case 3:                        /* Volume */
         if (select_pool_and_media_dbr(ua, &pr, &mr)) {
            purge_files_from_volume(ua, &pr, &mr);
         }
@@ -221,30 +222,41 @@ int purgecmd(UAContext *ua, char *cmd)
         client = select_client_resource(ua);
         purge_jobs_from_client(ua, client);
         return 1;
-      case 1:
+      case 1:                        /* Volume */
         if (select_pool_and_media_dbr(ua, &pr, &mr)) {
            purge_jobs_from_volume(ua, &pr, &mr);
         }
         return 1;
       }
+   /* Volume */
+   case 2:
+      if (select_pool_and_media_dbr(ua, &pr, &mr)) {
+        purge_jobs_from_volume(ua, &pr, &mr);
+      }
+      return 1;
    default:
       break;
    }
    switch (do_keyword_prompt(ua, _("Choose item to purge"), keywords)) {
-   case 0:
+   case 0:                           /* files */
       client = select_client_resource(ua);
       if (!client) {
         return 1;
       }
       purge_files_from_client(ua, client);
       break;
-   case 1:
+   case 1:                           /* jobs */
       client = select_client_resource(ua);
       if (!client) {
         return 1;
       }
       purge_jobs_from_client(ua, client);
       break;
+   case 2:                           /* Volume */
+      if (select_pool_and_media_dbr(ua, &pr, &mr)) {
+        purge_jobs_from_volume(ua, &pr, &mr);
+      }
+      break;
    }
    return 1;
 }
@@ -450,6 +462,7 @@ void purge_jobs_from_volume(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr)
       bsendmsg(ua, "There are no Jobs associated with Volume %s. Marking it purged.\n",
         mr->VolumeName);
       if (!mark_media_purged(ua, mr)) {
+         bsendmsg(ua, "%s", db_strerror(ua->db));
         goto bail_out;
       }
       goto bail_out;
@@ -489,7 +502,9 @@ void purge_jobs_from_volume(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr)
 
    /* If purged, mark it so */
    if (del.num_ids == del.num_del) {
-      mark_media_purged(ua, mr);
+      if (!mark_media_purged(ua, mr)) {
+         bsendmsg(ua, "%s", db_strerror(ua->db));
+      }
    }
 
 bail_out:   
@@ -497,22 +512,22 @@ bail_out:
 }
 
 /*
- * IF volume status is Append, Full, or Used, mark it Purged
+ * IF volume status is Append, Full, Used, or Error, mark it Purged
  *   Purged volumes can then be recycled (if enabled).
  */
 int mark_media_purged(UAContext *ua, MEDIA_DBR *mr)
 {
    if (strcmp(mr->VolStatus, "Append") == 0 || 
        strcmp(mr->VolStatus, "Full")   == 0 ||
-       strcmp(mr->VolStatus, "Used") == 0) {
+       strcmp(mr->VolStatus, "Used")   == 0 || 
+       strcmp(mr->VolStatus, "Error")  == 0) {
       strcpy(mr->VolStatus, "Purged");
       if (!db_update_media_record(ua->jcr, ua->db, mr)) {
-        if (ua->verbose) {
-            bsendmsg(ua, "%s", db_strerror(ua->db));
-        }
         return 0;
       }
       return 1;
+   } else {
+      bsendmsg(ua, _("Cannot purge Volume with VolStatus=%s\n"), mr->VolStatus);
    }
    return strcpy(mr->VolStatus, "Purged") == 0;
 }
index 9035e5cf70ffedefdef968d3b90c4ccd87a20689..2599d717bdcbb1214583d5488a17662293eb2ce4 100644 (file)
@@ -503,7 +503,7 @@ bnet_connect(void *vjcr, int retry_interval, int max_retry_time, char *name,
    JCR *jcr = (JCR *)vjcr;
 
    for (i=0; (bsock = bnet_open(jcr, name, host, service, port)) == NULL; i -= retry_interval) {
-     if (job_cancelled(jcr)) {
+     if (jcr && job_cancelled(jcr)) {
        break;
      }
      Dmsg4(100, "Unable to connect to %s on %s:%d. ERR=%s\n",