]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_purge.c
tidy up make clean and ensure we have all the create/drop etc files
[bacula/bacula] / bacula / src / dird / ua_purge.c
index e5eb298c87521594304ced93c8c37f3feff361ca..c0ce011d358696664e4921c53d014941302f00df 100644 (file)
@@ -205,8 +205,10 @@ int purgecmd(UAContext *ua, char *cmd)
         }
         return 1;
       case 2:                        /* client */
-        client = select_client_resource(ua);
-        purge_files_from_client(ua, client);
+        client = get_client_resource(ua);
+        if (client) {
+           purge_files_from_client(ua, client);
+        }
         return 1;
       case 3:                        /* Volume */
         if (select_media_dbr(ua, &mr)) {
@@ -218,8 +220,10 @@ int purgecmd(UAContext *ua, char *cmd)
    case 1:
       switch(find_arg_keyword(ua, jobs_keywords)) {
       case 0:                        /* client */
-        client = select_client_resource(ua);
-        purge_jobs_from_client(ua, client);
+        client = get_client_resource(ua);
+        if (client) {
+           purge_jobs_from_client(ua, client);
+        }
         return 1;
       case 1:                        /* Volume */
         if (select_media_dbr(ua, &mr)) {
@@ -238,18 +242,16 @@ int purgecmd(UAContext *ua, char *cmd)
    }
    switch (do_keyword_prompt(ua, _("Choose item to purge"), keywords)) {
    case 0:                           /* files */
-      client = select_client_resource(ua);
-      if (!client) {
-        return 1;
+      client = get_client_resource(ua);
+      if (client) {
+        purge_files_from_client(ua, client);
       }
-      purge_files_from_client(ua, client);
       break;
    case 1:                           /* jobs */
-      client = select_client_resource(ua);
-      if (!client) {
-        return 1;
+      client = get_client_resource(ua);
+      if (client) {
+        purge_jobs_from_client(ua, client);
       }
-      purge_jobs_from_client(ua, client);
       break;
    case 2:                           /* Volume */
       if (select_media_dbr(ua, &mr)) {
@@ -261,7 +263,7 @@ int purgecmd(UAContext *ua, char *cmd)
 }
 
 /*
- * Prune File records from the database. For any Job which
+ * Purge File records from the database. For any Job which
  * is older than the retention period, we unconditionally delete
  * all File records for that Job.  This is simple enough that no
  * temporary tables are needed. We simply make an in memory list of
@@ -338,12 +340,12 @@ bail_out:
 
 
 /*
- * Purging Jobs is a bit more complicated than purging Files
- * because we delete Job records only if there is a more current
- * backup of the FileSet. Otherwise, we keep the Job record.
- * In other words, we never delete the only Job record that
- * contains a current backup of a FileSet. This prevents the
- * Volume from being recycled and destroying a current backup.
+ * Purge Job records from the database. For any Job which
+ * 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.
  */
 int purge_jobs_from_client(UAContext *ua, CLIENT *client)
 {
@@ -355,7 +357,7 @@ int purge_jobs_from_client(UAContext *ua, CLIENT *client)
    memset(&cr, 0, sizeof(cr));
    memset(&del, 0, sizeof(del));
 
-   strcpy(cr.Name, client->hdr.name);
+   bstrncpy(cr.Name, client->hdr.name, sizeof(cr.Name));
    if (!db_create_client_record(ua->jcr, ua->db, &cr)) {
       return 0;
    }
@@ -427,10 +429,10 @@ void purge_files_from_job(UAContext *ua, JOB_DBR *jr)
 {
    char *query = (char *)get_pool_memory(PM_MESSAGE);
    
-   Mmsg(&query, "DELETE FROM File WHERE JobId=%d", jr->JobId);
+   Mmsg(&query, "DELETE FROM File WHERE JobId=%u", jr->JobId);
    db_sql_query(ua->db, query, NULL, (void *)NULL);
 
-   Mmsg(&query, "UPDATE Job Set PurgedFiles=1 WHERE JobId=%d", jr->JobId);
+   Mmsg(&query, "UPDATE Job Set PurgedFiles=1 WHERE JobId=%u", jr->JobId);
    db_sql_query(ua->db, query, NULL, (void *)NULL);
 
    free_pool_memory(query);
@@ -451,6 +453,18 @@ int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr)
    int i, stat = 0;
    JOB_DBR jr;
 
+   stat = strcmp(mr->VolStatus, "Append") == 0 || 
+          strcmp(mr->VolStatus, "Full")   == 0 ||
+          strcmp(mr->VolStatus, "Used")   == 0 || 
+          strcmp(mr->VolStatus, "Error")  == 0; 
+   if (!stat) {
+      bsendmsg(ua, "\n");
+      bsendmsg(ua, _("Volume \"%s\" has VolStatus \"%s\" and cannot be purged.\n"
+                     "The VolStatus must be: Append, Full, Used, or Error to be purged.\n"),
+                    mr->VolumeName, mr->VolStatus);
+      goto bail_out;
+   }
+   
    memset(&jr, 0, sizeof(jr));
    memset(&del, 0, sizeof(del));
    cnt.count = 0;