]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_purge.c
kes Move the checking of the database in initializion of the Director
[bacula/bacula] / bacula / src / dird / ua_purge.c
index 261485d66545498650731497c814c476180f3776..f41156558d9c5eb7918adf7128ef422a91450bd4 100644 (file)
@@ -13,7 +13,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2002-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2002-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.
@@ -288,7 +288,7 @@ static int purge_files_from_client(UAContext *ua, CLIENT *client)
    memset(&cr, 0, sizeof(cr));
    memset(&del, 0, sizeof(del));
 
-   bstrncpy(cr.Name, client->hdr.name, sizeof(cr.Name));
+   bstrncpy(cr.Name, client->name(), sizeof(cr.Name));
    if (!db_create_client_record(ua->jcr, ua->db, &cr)) {
       return 0;
    }
@@ -305,7 +305,7 @@ static int purge_files_from_client(UAContext *ua, CLIENT *client)
 
    if (del.tot_ids == 0) {
       bsendmsg(ua, _("No Files found for client %s to purge from %s catalog.\n"),
-         client->hdr.name, client->catalog->hdr.name);
+         client->name(), client->catalog->name());
       goto bail_out;
    }
 
@@ -324,7 +324,7 @@ static int purge_files_from_client(UAContext *ua, CLIENT *client)
       purge_files_from_job(ua, del.JobId[i]);
    }
    bsendmsg(ua, _("%d Files for client \"%s\" purged from %s catalog.\n"), del.num_ids,
-      client->hdr.name, client->catalog->hdr.name);
+      client->name(), client->catalog->name());
 
 bail_out:
    if (del.JobId) {
@@ -354,7 +354,7 @@ static int purge_jobs_from_client(UAContext *ua, CLIENT *client)
    memset(&cr, 0, sizeof(cr));
    memset(&del, 0, sizeof(del));
 
-   bstrncpy(cr.Name, client->hdr.name, sizeof(cr.Name));
+   bstrncpy(cr.Name, client->name(), sizeof(cr.Name));
    if (!db_create_client_record(ua->jcr, ua->db, &cr)) {
       return 0;
    }
@@ -371,7 +371,7 @@ static int purge_jobs_from_client(UAContext *ua, CLIENT *client)
    }
    if (del.tot_ids == 0) {
       bsendmsg(ua, _("No Jobs found for client %s to purge from %s catalog.\n"),
-         client->hdr.name, client->catalog->hdr.name);
+         client->name(), client->catalog->name());
       goto bail_out;
    }
 
@@ -401,7 +401,7 @@ static int purge_jobs_from_client(UAContext *ua, CLIENT *client)
       purge_job_from_catalog(ua, del.JobId[i]);
    }
    bsendmsg(ua, _("%d Jobs for client %s purged from %s catalog.\n"), del.num_ids,
-      client->hdr.name, client->catalog->hdr.name);
+      client->name(), client->catalog->name());
 
 bail_out:
    if (del.JobId) {
@@ -419,7 +419,7 @@ void purge_job_from_catalog(UAContext *ua, JobId_t JobId)
    POOL_MEM query(PM_MESSAGE);
    char ed1[50];
 
-   /* Records associated with the job */
+   /* Delete (or purge) records associated with the job */
    purge_job_records_from_catalog(ua, JobId);
 
    /* Now remove the Job record itself */
@@ -605,6 +605,31 @@ bool mark_media_purged(UAContext *ua, MEDIA_DBR *mr)
       }
       pm_strcpy(jcr->VolumeName, mr->VolumeName);
       generate_job_event(jcr, "VolumePurged");
+      /*
+       * If the RecyclePool is defined, move the volume there
+       */
+      if (mr->RecyclePoolId && mr->RecyclePoolId != mr->PoolId) {
+         POOL_DBR oldpr, newpr;
+         memset(&oldpr, 0, sizeof(POOL_DBR));
+         memset(&newpr, 0, sizeof(POOL_DBR));
+         newpr.PoolId = mr->RecyclePoolId;
+         oldpr.PoolId = mr->PoolId;
+         if (   db_get_pool_record(jcr, ua->db, &oldpr) 
+             && db_get_pool_record(jcr, ua->db, &newpr)) 
+         {
+            /* check if destination pool size is ok */
+            if (newpr.MaxVols > 0 && newpr.NumVols >= newpr.MaxVols) {
+               bsendmsg(ua, _("Unable move recycled Volume in full " 
+                              "Pool \"%s\" MaxVols=%d\n"),
+                        newpr.Name, newpr.MaxVols);
+
+            } else {            /* move media */
+               update_vol_pool(ua, newpr.Name, mr, &oldpr);
+            }
+         } else {
+            bsendmsg(ua, "%s", db_strerror(ua->db));
+         }
+      }
       /* Send message to Job report, if it is a *real* job */           
       if (jcr && jcr->JobId > 0) {
          Jmsg1(jcr, M_INFO, 0, _("All records pruned from Volume \"%s\"; marking it \"Purged\"\n"),