]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_prune.c
Fix conio.h problem on Solaris
[bacula/bacula] / bacula / src / dird / ua_prune.c
index cccd7c86205654c9befa7bf32eef32f5d08d694b..d72fe1d370854552dd1eed55afe3880e703be570 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 /*
-   Copyright (C) 2002-2003 Kern Sibbald and John Walker
+   Copyright (C) 2002-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -47,6 +47,7 @@ extern char *insert_delcand;
 extern char *select_backup_del;
 extern char *select_verify_del;
 extern char *select_restore_del;
+extern char *select_admin_del;
 extern char *cnt_File;
 extern char *del_File;
 extern char *upd_Purged;
@@ -155,14 +156,14 @@ static int file_delete_handler(void *ctx, int num_fields, char **row)
  *    prune jobs (from) client=xxx
  *    prune volume=xxx 
  */
-int prunecmd(UAContext *ua, char *cmd)
+int prunecmd(UAContext *ua, const char *cmd)
 {
    CLIENT *client;
    POOL_DBR pr;
    MEDIA_DBR mr;
    int kw;
 
-   static char *keywords[] = {
+   static const char *keywords[] = {
       N_("Files"),
       N_("Jobs"),
       N_("Volume"),
@@ -244,7 +245,7 @@ int prune_files(UAContext *ua, CLIENT *client)
    now = (utime_t)time(NULL);
        
    /* Select Jobs -- for counting */
-   Mmsg(&query, select_job, edit_uint64(now - period, ed1), cr.ClientId);
+   Mmsg(query, select_job, edit_uint64(now - period, ed1), cr.ClientId);
    Dmsg1(050, "select sql=%s\n", query);
    if (!db_sql_query(ua->db, query, file_count_handler, (void *)&del)) {
       if (ua->verbose) {
@@ -276,11 +277,11 @@ int prune_files(UAContext *ua, CLIENT *client)
    for (i=0; i < del.num_ids; i++) {
       struct s_count_ctx cnt;
       Dmsg1(050, "Delete JobId=%d\n", del.JobId[i]);
-      Mmsg(&query, cnt_File, del.JobId[i]);
+      Mmsg(query, cnt_File, del.JobId[i]);
       cnt.count = 0;
       db_sql_query(ua->db, query, count_handler, (void *)&cnt);
       del.tot_ids += cnt.count;
-      Mmsg(&query, del_File, del.JobId[i]);
+      Mmsg(query, del_File, del.JobId[i]);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
       /* 
        * Now mark Job as having files purged. This is necessary to
@@ -288,7 +289,7 @@ int prune_files(UAContext *ua, CLIENT *client)
        * we don't do this, the number of JobId's in our in memory list
        * could grow very large.
        */
-      Mmsg(&query, upd_Purged, del.JobId[i]);
+      Mmsg(query, upd_Purged, del.JobId[i]);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
       Dmsg1(050, "Del sql=%s\n", query);
    }
@@ -347,7 +348,7 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType)
 {
    struct s_job_del_ctx del;
    struct s_count_ctx cnt;
-   char *query = (char *)get_pool_memory(PM_MESSAGE);
+   POOLMEM *query = (char *)get_pool_memory(PM_MESSAGE);
    int i;
    utime_t now, period;
    CLIENT_DBR cr;
@@ -378,7 +379,7 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType)
     *  and stuff them into the "DeletionCandidates" table.
     */
    edit_uint64(now - period, ed1);
-   Mmsg(&query, insert_delcand, (char)JobType, ed1, cr.ClientId);
+   Mmsg(query, insert_delcand, (char)JobType, ed1, cr.ClientId);
    if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
       if (ua->verbose) {
          bsendmsg(ua, "%s", db_strerror(ua->db));
@@ -388,7 +389,7 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType)
    }
 
    /* Count Files to be deleted */
-   pm_strcpy(&query, cnt_DelCand);
+   pm_strcpy(query, cnt_DelCand);
    Dmsg1(100, "select sql=%s\n", query);
    cnt.count = 0;
    if (!db_sql_query(ua->db, query, count_handler, (void *)&cnt)) {
@@ -413,15 +414,17 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType)
    del.PurgedFiles = (char *)malloc(del.max_ids);
 
    switch (JobType) {
-   case JT_ADMIN:
    case JT_BACKUP:
-      Mmsg(&query, select_backup_del, ed1, ed1, cr.ClientId);
+      Mmsg(query, select_backup_del, ed1, ed1, cr.ClientId);
       break;
    case JT_RESTORE:
-      Mmsg(&query, select_restore_del, ed1, cr.ClientId);
+      Mmsg(query, select_restore_del, ed1, ed1, cr.ClientId);
       break;
    case JT_VERIFY:
-      Mmsg(&query, select_verify_del, ed1, cr.ClientId);
+      Mmsg(query, select_verify_del, ed1, ed1, cr.ClientId);
+      break;
+   case JT_ADMIN:
+      Mmsg(query, select_admin_del, ed1, ed1, cr.ClientId);
       break;
    }
    if (!db_sql_query(ua->db, query, job_delete_handler, (void *)&del)) {
@@ -436,20 +439,20 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType)
    for (i=0; i < del.num_ids; i++) {
       Dmsg1(050, "Delete JobId=%d\n", del.JobId[i]);
       if (!del.PurgedFiles[i]) {
-        Mmsg(&query, del_File, del.JobId[i]);
+        Mmsg(query, del_File, del.JobId[i]);
         if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
             bsendmsg(ua, "%s", db_strerror(ua->db));
         }
          Dmsg1(050, "Del sql=%s\n", query);
       }
 
-      Mmsg(&query, del_Job, del.JobId[i]);
+      Mmsg(query, del_Job, del.JobId[i]);
       if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
          bsendmsg(ua, "%s", db_strerror(ua->db));
       }
       Dmsg1(050, "Del sql=%s\n", query);
 
-      Mmsg(&query, del_JobMedia, del.JobId[i]);
+      Mmsg(query, del_JobMedia, del.JobId[i]);
       if (!db_sql_query(ua->db, query, NULL, (void *)NULL)) {
          bsendmsg(ua, "%s", db_strerror(ua->db));
       }
@@ -476,7 +479,7 @@ bail_out:
  */
 int prune_volume(UAContext *ua, MEDIA_DBR *mr)
 {
-   char *query = (char *)get_pool_memory(PM_MESSAGE);
+   POOLMEM *query = (char *)get_pool_memory(PM_MESSAGE);
    struct s_count_ctx cnt;
    struct s_file_del_ctx del;
    int i, stat = 0;
@@ -492,7 +495,7 @@ int prune_volume(UAContext *ua, MEDIA_DBR *mr)
     *  counting the JobMedia records.
     */
    cnt.count = 0;
-   Mmsg(&query, cnt_JobMedia, mr->MediaId);
+   Mmsg(query, cnt_JobMedia, mr->MediaId);
    if (!db_sql_query(ua->db, query, count_handler, (void *)&cnt)) {
       bsendmsg(ua, "%s", db_strerror(ua->db));
       Dmsg0(050, "Count failed\n");
@@ -500,7 +503,7 @@ int prune_volume(UAContext *ua, MEDIA_DBR *mr)
    }
       
    if (cnt.count == 0) {
-      if (ua->verbose) {
+      if (strcmp(mr->VolStatus, "Purged") != 0 && verbose) {
          bsendmsg(ua, "There are no Jobs associated with Volume \"%s\". Marking it purged.\n",
            mr->VolumeName);
       }
@@ -519,7 +522,7 @@ int prune_volume(UAContext *ua, MEDIA_DBR *mr)
     *  Could optimize here by adding JobTDate > (now - period).
     */
    del.JobId = (JobId_t *)malloc(sizeof(JobId_t) * del.max_ids);
-   Mmsg(&query, sel_JobMedia, mr->MediaId);
+   Mmsg(query, sel_JobMedia, mr->MediaId);
    if (!db_sql_query(ua->db, query, file_delete_handler, (void *)&del)) {
       if (ua->verbose) {
          bsendmsg(ua, "%s", db_strerror(ua->db));
@@ -545,11 +548,11 @@ int prune_volume(UAContext *ua, MEDIA_DBR *mr)
         continue;
       }
       Dmsg2(200, "Delete JobId=%d Job=%s\n", del.JobId[i], jr.Job);
-      Mmsg(&query, del_File, del.JobId[i]);
+      Mmsg(query, del_File, del.JobId[i]);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Mmsg(&query, del_Job, del.JobId[i]);
+      Mmsg(query, del_Job, del.JobId[i]);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Mmsg(&query, del_JobMedia, del.JobId[i]);
+      Mmsg(query, del_JobMedia, del.JobId[i]);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
       Dmsg1(050, "Del sql=%s\n", query);
       del.num_del++;