]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/recycle.c
kes Change Bacula trademark owner from John Walker to Kern Sibbald
[bacula/bacula] / bacula / src / dird / recycle.c
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2002-2007 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *
30  *   Bacula Director -- Automatic Recycling of Volumes
31  *      Recycles Volumes that have been purged
32  *
33  *     Kern Sibbald, May MMII
34  *
35  *   Version $Id$
36  */
37
38
39 #include "bacula.h"
40 #include "dird.h"
41 #include "ua.h"
42
43 /* Forward referenced functions */
44
45 bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr)
46 {
47    bstrncpy(mr->VolStatus, "Recycle", sizeof(mr->VolStatus));
48    if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
49       jcr->MediaId = mr->MediaId;
50       Dmsg1(20, "Find_next_vol MediaId=%u\n", jcr->MediaId);
51       pm_strcpy(jcr->VolumeName, mr->VolumeName);
52       return true;
53    }
54    return false;
55 }
56
57 /*
58  *   Look for oldest Purged volume
59  */
60 bool recycle_oldest_purged_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr)
61 {
62    bstrncpy(mr->VolStatus, "Purged", sizeof(mr->VolStatus));
63    if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
64       if (recycle_volume(jcr, mr)) {
65          Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\"\n"), mr->VolumeName);
66          Dmsg1(100, "return 1  recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
67          return true;
68       }
69    }
70    Dmsg0(100, "return 0  recycle_oldest_purged_volume end\n");
71    return false;
72 }
73
74 /*
75  * Recycle the specified volume
76  */
77 int recycle_volume(JCR *jcr, MEDIA_DBR *mr)
78 {
79    bstrncpy(mr->VolStatus, "Recycle", sizeof(mr->VolStatus));
80    mr->VolJobs = mr->VolFiles = mr->VolBlocks = mr->VolErrors = 0;
81    mr->VolBytes = 1;
82    mr->FirstWritten = mr->LastWritten = 0;
83    mr->RecycleCount++;
84    mr->set_first_written = true;
85    return db_update_media_record(jcr, jcr->db, mr);
86 }