]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/recycle.c
a8665f9615df122eb73f8ae03f0d6e99d8175b62
[bacula/bacula] / bacula / src / dird / recycle.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 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  *
21  *   Bacula Director -- Automatic Recycling of Volumes
22  *      Recycles Volumes that have been purged
23  *
24  *     Kern Sibbald, May MMII
25  *
26  */
27
28
29 #include "bacula.h"
30 #include "dird.h"
31 #include "ua.h"
32
33 /* Forward referenced functions */
34
35 bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr,
36                           STORE *store)
37 {
38    bstrncpy(mr->VolStatus, "Recycle", sizeof(mr->VolStatus));
39    set_storageid_in_mr(store, mr);
40    if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
41       jcr->MediaId = mr->MediaId;
42       Dmsg1(20, "Find_next_vol MediaId=%u\n", jcr->MediaId);
43       pm_strcpy(jcr->VolumeName, mr->VolumeName);
44       set_storageid_in_mr(store, mr);
45       return true;
46    }
47    return false;
48 }
49
50 /*
51  *   Look for oldest Purged volume
52  */
53 bool recycle_oldest_purged_volume(JCR *jcr, bool InChanger,
54         MEDIA_DBR *mr, STORE *store)
55 {
56    bstrncpy(mr->VolStatus, "Purged", sizeof(mr->VolStatus));
57    if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
58       set_storageid_in_mr(store, mr);
59       if (recycle_volume(jcr, mr)) {
60          Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\"\n"), mr->VolumeName);
61          Dmsg1(100, "return 1  recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
62          return true;
63       }
64    }
65    Dmsg0(100, "return 0  recycle_oldest_purged_volume end\n");
66    return false;
67 }
68
69 /*
70  * Recycle the specified volume
71  */
72 int recycle_volume(JCR *jcr, MEDIA_DBR *mr)
73 {
74    bstrncpy(mr->VolStatus, "Recycle", sizeof(mr->VolStatus));
75    mr->VolJobs = mr->VolFiles = mr->VolBlocks = mr->VolErrors = 0;
76    mr->VolBytes = 1;
77    mr->FirstWritten = mr->LastWritten = 0;
78    mr->RecycleCount++;
79    mr->set_first_written = true;
80    set_storageid_in_mr(NULL, mr);
81    return db_update_media_record(jcr, jcr->db, mr);
82 }