]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_purge.c
Correct pool source setting
[bacula/bacula] / bacula / src / dird / ua_purge.c
index 55cbc074760ba407a00655d41f2d1304b264c2ae..41a5c5634918c02ca65d7bc5408bbcb6100e7bd2 100644 (file)
  *   Version $Id$
  */
 /*
-   Copyright (C) 2002-2005 Kern Sibbald
+   Copyright (C) 2002-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 ammended with additional clauses defined in the
+   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,
 static int purge_files_from_client(UAContext *ua, CLIENT *client);
 static int purge_jobs_from_client(UAContext *ua, CLIENT *client);
 
-void purge_files_from_volume(UAContext *ua, MEDIA_DBR *mr );
-int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr);
-void purge_files_from_job(UAContext *ua, JOB_DBR *jr);
-int mark_media_purged(UAContext *ua, MEDIA_DBR *mr);
-
 #define MAX_DEL_LIST_LEN 1000000
 
-
 static const char *select_jobsfiles_from_client =
    "SELECT JobId FROM Job "
    "WHERE ClientId=%s "
@@ -127,7 +121,7 @@ static int job_delete_handler(void *ctx, int num_fields, char **row)
       del->PurgedFiles = (char *)brealloc(del->PurgedFiles, del->max_ids);
    }
    del->JobId[del->num_ids] = (JobId_t)str_to_int64(row[0]);
-   del->PurgedFiles[del->num_ids++] = (char)str_to_int64(row[0]);
+   del->PurgedFiles[del->num_ids++] = (char)str_to_int64(row[1]);
    return 0;
 }
 
@@ -162,21 +156,21 @@ int purgecmd(UAContext *ua, const char *cmd)
    MEDIA_DBR mr;
    JOB_DBR  jr;
    static const char *keywords[] = {
-      N_("files"),
-      N_("jobs"),
-      N_("volume"),
+      NT_("files"),
+      NT_("jobs"),
+      NT_("volume"),
       NULL};
 
    static const char *files_keywords[] = {
-      N_("Job"),
-      N_("JobId"),
-      N_("Client"),
-      N_("Volume"),
+      NT_("Job"),
+      NT_("JobId"),
+      NT_("Client"),
+      NT_("Volume"),
       NULL};
 
    static const char *jobs_keywords[] = {
-      N_("Client"),
-      N_("Volume"),
+      NT_("Client"),
+      NT_("Volume"),
       NULL};
 
    bsendmsg(ua, _(
@@ -229,7 +223,7 @@ int purgecmd(UAContext *ua, const char *cmd)
       }
    /* Volume */
    case 2:
-      while ((i=find_arg(ua, _("volume"))) >= 0) {
+      while ((i=find_arg(ua, NT_("volume"))) >= 0) {
          if (select_media_dbr(ua, &mr)) {
             purge_jobs_from_volume(ua, &mr);
          }
@@ -273,7 +267,7 @@ int purgecmd(UAContext *ua, const char *cmd)
 static int purge_files_from_client(UAContext *ua, CLIENT *client)
 {
    struct s_file_del_ctx del;
-   char *query = (char *)get_pool_memory(PM_MESSAGE);
+   POOLMEM *query = get_pool_memory(PM_MESSAGE);
    int i;
    CLIENT_DBR cr;
    char ed1[50];
@@ -315,7 +309,7 @@ static int purge_files_from_client(UAContext *ua, CLIENT *client)
 
    for (i=0; i < del.num_ids; i++) {
       edit_int64(del.JobId[i], ed1);
-      Dmsg1(050, "Delete JobId=%s\n", ed1);
+      Dmsg1(050, "Delete Files JobId=%s\n", ed1);
       Mmsg(query, "DELETE FROM File WHERE JobId=%s", ed1);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
       /*
@@ -326,7 +320,7 @@ static int purge_files_from_client(UAContext *ua, CLIENT *client)
        */
       Mmsg(query, "UPDATE Job Set PurgedFiles=1 WHERE JobId=%s", ed1);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Dmsg1(050, "Del sql=%s\n", query);
+      Dmsg1(050, "Update Purged sql=%s\n", query);
    }
    bsendmsg(ua, _("%d Files for client \"%s\" purged from %s catalog.\n"), del.num_ids,
       client->hdr.name, client->catalog->hdr.name);
@@ -346,13 +340,12 @@ bail_out:
  * is older than the retention period, we unconditionally delete
  * it and all File records for that Job.  This is simple enough that no
  * temporary tables are needed. We simply make an in memory list of
- * the JobIds meeting the prune conditions, then delete the Job,
- * Files, and JobMedia records in that list.
+ * the JobIds then delete the Job, Files, and JobMedia records in that list.
  */
 static int purge_jobs_from_client(UAContext *ua, CLIENT *client)
 {
    struct s_job_del_ctx del;
-   char *query = (char *)get_pool_memory(PM_MESSAGE);
+   POOLMEM *query = get_pool_memory(PM_MESSAGE);
    int i;
    CLIENT_DBR cr;
    char ed1[50];
@@ -401,7 +394,7 @@ static int purge_jobs_from_client(UAContext *ua, CLIENT *client)
     */
    for (i=0; i < del.num_ids; i++) {
       edit_int64(del.JobId[i], ed1);
-      Dmsg1(050, "Delete JobId=%s\n", ed1); 
+      Dmsg1(050, "Delete Files JobId=%s\n", ed1); 
       if (!del.PurgedFiles[i]) {
          Mmsg(query, "DELETE FROM File WHERE JobId=%s", ed1);
          db_sql_query(ua->db, query, NULL, (void *)NULL);
@@ -410,11 +403,15 @@ static int purge_jobs_from_client(UAContext *ua, CLIENT *client)
 
       Mmsg(query, "DELETE FROM Job WHERE JobId=%s", ed1);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Dmsg1(050, "Del sql=%s\n", query);
+      Dmsg1(050, "Delete Job sql=%s\n", query);
+
+      Mmsg(query, "DELETE FROM MAC WHERE JobId=%s", ed1);
+      db_sql_query(ua->db, query, NULL, (void *)NULL);
+      Dmsg1(050, "Delete MAC sql=%s\n", query);
 
       Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", ed1);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
-      Dmsg1(050, "Del sql=%s\n", query);
+      Dmsg1(050, "Delete JobMedia sql=%s\n", query);
    }
    bsendmsg(ua, _("%d Jobs for client %s purged from %s catalog.\n"), del.num_ids,
       client->hdr.name, client->catalog->hdr.name);
@@ -432,10 +429,10 @@ bail_out:
 
 void purge_files_from_job(UAContext *ua, JOB_DBR *jr)
 {
-   char *query = (char *)get_pool_memory(PM_MESSAGE);
+   POOLMEM *query = get_pool_memory(PM_MESSAGE);
    char ed1[50];
 
-   edit_int64(jr->JobId,ed1);
+   edit_int64(jr->JobId, ed1);
    Mmsg(query, "DELETE FROM File WHERE JobId=%s", ed1);
    db_sql_query(ua->db, query, NULL, (void *)NULL);
 
@@ -454,7 +451,7 @@ void purge_files_from_volume(UAContext *ua, MEDIA_DBR *mr )
  */
 int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr)
 {
-   char *query = (char *)get_pool_memory(PM_MESSAGE);
+   POOLMEM *query = get_pool_memory(PM_MESSAGE);
    struct s_count_ctx cnt;
    struct s_file_del_ctx del;
    int i, stat = 0;
@@ -485,7 +482,7 @@ int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr)
    }
 
    if (cnt.count == 0) {
-      bsendmsg(ua, "There are no Jobs associated with Volume \"%s\". Marking it purged.\n",
+      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));
@@ -530,6 +527,8 @@ int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr)
       db_sql_query(ua->db, query, NULL, (void *)NULL);
       Mmsg(query, "DELETE FROM Job WHERE JobId=%s", ed1);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
+      Mmsg(query, "DELETE FROM MAC WHERE JobId=%s", ed1);
+      db_sql_query(ua->db, query, NULL, (void *)NULL);
       Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", ed1);
       db_sql_query(ua->db, query, NULL, (void *)NULL);
       Dmsg1(050, "Del sql=%s\n", query);
@@ -552,7 +551,7 @@ int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr)
    }
 
    if (cnt.count == 0) {
-      bsendmsg(ua, "There are no more Jobs associated with Volume \"%s\". Marking it purged.\n",
+      bsendmsg(ua, _("There are no more Jobs associated with Volume \"%s\". Marking it purged.\n"),
          mr->VolumeName);
       if (!(stat = mark_media_purged(ua, mr))) {
          bsendmsg(ua, "%s", db_strerror(ua->db));
@@ -569,19 +568,22 @@ bail_out:
  * 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)
+bool mark_media_purged(UAContext *ua, MEDIA_DBR *mr)
 {
+   JCR *jcr = ua->jcr;
    if (strcmp(mr->VolStatus, "Append") == 0 ||
        strcmp(mr->VolStatus, "Full")   == 0 ||
        strcmp(mr->VolStatus, "Used")   == 0 ||
        strcmp(mr->VolStatus, "Error")  == 0) {
       bstrncpy(mr->VolStatus, "Purged", sizeof(mr->VolStatus));
-      if (!db_update_media_record(ua->jcr, ua->db, mr)) {
-         return 0;
+      if (!db_update_media_record(jcr, ua->db, mr)) {
+         return false;
       }
-      return 1;
+      pm_strcpy(jcr->VolumeName, mr->VolumeName);
+      generate_job_event(jcr, "VolumePurged");
+      return true;
    } else {
       bsendmsg(ua, _("Cannot purge Volume with VolStatus=%s\n"), mr->VolStatus);
    }
-   return strcpy(mr->VolStatus, "Purged") == 0;
+   return strcmp(mr->VolStatus, "Purged") == 0;
 }