2 Bacula® - The Network Backup Solution
4 Copyright (C) 2002-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
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.
14 Bacula® is a registered trademark of Kern Sibbald.
18 * Bacula Director -- Automatic Recycling of Volumes
19 * Recycles Volumes that have been purged
21 * Kern Sibbald, May MMII
30 /* Forward referenced functions */
32 bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr,
35 bstrncpy(mr->VolStatus, "Recycle", sizeof(mr->VolStatus));
36 set_storageid_in_mr(store, mr);
37 if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
38 jcr->MediaId = mr->MediaId;
39 Dmsg1(20, "Find_next_vol MediaId=%u\n", jcr->MediaId);
40 pm_strcpy(jcr->VolumeName, mr->VolumeName);
41 set_storageid_in_mr(store, mr);
48 * Look for oldest Purged volume
50 bool recycle_oldest_purged_volume(JCR *jcr, bool InChanger,
51 MEDIA_DBR *mr, STORE *store)
53 bstrncpy(mr->VolStatus, "Purged", sizeof(mr->VolStatus));
54 if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
55 set_storageid_in_mr(store, mr);
56 if (recycle_volume(jcr, mr)) {
57 Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\"\n"), mr->VolumeName);
58 Dmsg1(100, "return 1 recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
62 Dmsg0(100, "return 0 recycle_oldest_purged_volume end\n");
67 * Recycle the specified volume
69 int recycle_volume(JCR *jcr, MEDIA_DBR *mr)
71 bstrncpy(mr->VolStatus, "Recycle", sizeof(mr->VolStatus));
72 mr->VolJobs = mr->VolFiles = mr->VolBlocks = mr->VolErrors = 0;
74 mr->FirstWritten = mr->LastWritten = 0;
76 mr->set_first_written = true;
77 set_storageid_in_mr(NULL, mr);
78 return db_update_media_record(jcr, jcr->db, mr);