* Version $Id$
*/
/*
- Copyright (C) 2002-2006 Kern Sibbald
+ Bacula® - The Network Backup Solution
- 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 amended with additional clauses defined in the
- file LICENSE in the main source directory.
+ Copyright (C) 2002-2007 Free Software Foundation Europe e.V.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- the file LICENSE for additional details.
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation plus additions
+ that are listed in the file LICENSE.
- */
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
#include "bacula.h"
#include "dird.h"
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;
}
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;
}
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) {
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;
}
}
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;
}
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) {
POOL_MEM query(PM_MESSAGE);
char ed1[50];
+ /* Delete (or purge) records associated with the job */
+ purge_job_records_from_catalog(ua, JobId);
+
+ /* Now remove the Job record itself */
edit_int64(JobId, ed1);
Mmsg(query, "DELETE FROM Job WHERE JobId=%s", ed1);
db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
Dmsg1(050, "Delete Job sql=%s\n", query.c_str());
+}
+
+/*
+ * This removes all the records associated with a Job from
+ * the catalog (i.e. prunes it) without removing the Job
+ * record itself.
+ */
+void purge_job_records_from_catalog(UAContext *ua, JobId_t JobId)
+{
+ POOL_MEM query(PM_MESSAGE);
+ char ed1[50];
+ purge_files_from_job(ua, JobId);
+
+ edit_int64(JobId, ed1);
Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", ed1);
db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
Dmsg1(050, "Delete JobMedia sql=%s\n", query.c_str());
}
+
+/*
+ * Remove File records for a particular Job.
+ */
void purge_files_from_job(UAContext *ua, JobId_t JobId)
{
POOL_MEM query(PM_MESSAGE);
* could grow very large.
*/
Mmsg(query, upd_Purged, ed1);
+ db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL);
}
void purge_files_from_volume(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"),
+ mr->VolumeName);
+ }
return true;
} else {
bsendmsg(ua, _("Cannot purge Volume with VolStatus=%s\n"), mr->VolStatus);