3 * Bacula Director -- Automatic Pruning
4 * Applies retention periods
6 * Kern Sibbald, May MMII
11 Bacula® - The Network Backup Solution
13 Copyright (C) 2002-2006 Free Software Foundation Europe e.V.
15 The main author of Bacula is Kern Sibbald, with contributions from
16 many others, a complete list can be found in the file AUTHORS.
17 This program is Free Software; you can redistribute it and/or
18 modify it under the terms of version two of the GNU General Public
19 License as published by the Free Software Foundation plus additions
20 that are listed in the file LICENSE.
22 This program is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32 Bacula® is a registered trademark of John Walker.
33 The licensor of Bacula is the Free Software Foundation Europe
34 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
35 Switzerland, email:ftf@fsfeurope.org.
42 /* Forward referenced functions */
46 * Auto Prune Jobs and Files. This is called at the end of every
47 * Job. We do not prune volumes here.
49 void do_autoprune(JCR *jcr)
55 if (!jcr->client) { /* temp -- remove me */
59 ua = new_ua_context(jcr);
63 if (jcr->job->PruneJobs || jcr->client->AutoPrune) {
64 Jmsg(jcr, M_INFO, 0, _("Begin pruning Jobs.\n"));
65 prune_jobs(ua, client, jcr->JobType);
71 if (jcr->job->PruneFiles || jcr->client->AutoPrune) {
72 Jmsg(jcr, M_INFO, 0, _("Begin pruning Files.\n"));
73 prune_files(ua, client);
77 Jmsg(jcr, M_INFO, 0, _("End auto prune.\n\n"));
85 * Prune all volumes in current Pool. This is called from
86 * catreq.c when the Storage daemon is asking for another
87 * volume and no appendable volumes are available.
90 * number of Volumes Purged
92 int prune_volumes(JCR *jcr)
101 if (!jcr->job->PruneVolumes && !jcr->pool->AutoPrune) {
102 Dmsg0(100, "AutoPrune not set in Pool.\n");
105 memset(&mr, 0, sizeof(mr));
106 ua = new_ua_context(jcr);
110 /* Get the List of all media ids in the current Pool */
111 if (!db_get_media_ids(jcr, jcr->db, jcr->jr.PoolId, &num_ids, &ids)) {
112 Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
116 /* Visit each Volume and Prune it */
117 for (i=0; i<num_ids; i++) {
119 if (!db_get_media_record(jcr, jcr->db, &mr)) {
120 Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
123 /* Prune only Volumes from current Pool */
124 if (jcr->jr.PoolId != mr.PoolId) {
127 /* Don't prune archived volumes */
128 if (mr.Enabled == 2) {
131 /* Prune only Volumes with status "Full", or "Used" */
132 if (strcmp(mr.VolStatus, "Full") == 0 ||
133 strcmp(mr.VolStatus, "Used") == 0) {
134 Dmsg1(200, "Prune Volume %s\n", mr.VolumeName);
135 stat += prune_volume(ua, &mr);
136 Dmsg1(200, "Num pruned = %d\n", stat);