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