]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/recycle.c
6ba990c1aa9fbf9584445c48359d98925c15fa55
[bacula/bacula] / bacula / src / dird / recycle.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2002-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  *
22  *   Bacula Director -- Automatic Recycling of Volumes
23  *      Recycles Volumes that have been purged
24  *
25  *     Kern Sibbald, May MMII
26  *
27  */
28
29
30 #include "bacula.h"
31 #include "dird.h"
32 #include "ua.h"
33
34 /* Forward referenced functions */
35
36 bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr,
37                           STORE *store)
38 {
39    bstrncpy(mr->VolStatus, "Recycle", sizeof(mr->VolStatus));
40    set_storageid_in_mr(store, mr);
41    if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
42       jcr->MediaId = mr->MediaId;
43       Dmsg1(20, "Find_next_vol MediaId=%u\n", jcr->MediaId);
44       pm_strcpy(jcr->VolumeName, mr->VolumeName);
45       set_storageid_in_mr(store, mr);
46       return true;
47    }
48    return false;
49 }
50
51 /*
52  *   Look for oldest Purged volume
53  */
54 bool recycle_oldest_purged_volume(JCR *jcr, bool InChanger,
55         MEDIA_DBR *mr, STORE *store)
56 {
57    bstrncpy(mr->VolStatus, "Purged", sizeof(mr->VolStatus));
58    if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
59       set_storageid_in_mr(store, mr);
60       if (recycle_volume(jcr, mr)) {
61          Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\"\n"), mr->VolumeName);
62          Dmsg1(100, "return 1  recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
63          return true;
64       }
65    }
66    Dmsg0(100, "return 0  recycle_oldest_purged_volume end\n");
67    return false;
68 }
69
70 /*
71  * Recycle the specified volume
72  */
73 int recycle_volume(JCR *jcr, MEDIA_DBR *mr)
74 {
75    bstrncpy(mr->VolStatus, "Recycle", sizeof(mr->VolStatus));
76    mr->VolJobs = mr->VolFiles = mr->VolBlocks = mr->VolErrors = 0;
77    mr->VolBytes = 1;
78    mr->FirstWritten = mr->LastWritten = 0;
79    mr->RecycleCount++;
80    mr->set_first_written = true;
81    set_storageid_in_mr(NULL, mr);
82    return db_update_media_record(jcr, jcr->db, mr);
83 }