]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/newvol.c
Retention period updates
[bacula/bacula] / bacula / src / dird / newvol.c
1 /*
2  *
3  *   Bacula Director -- newvol.c -- creates new Volumes in
4  *    catalog Media table from the LabelFormat specification.
5  *
6  *     Kern Sibbald, May MMI
7  *
8  *    This routine runs as a thread and must be thread reentrant.
9  *
10  *  Basic tasks done here:
11  *      If possible create a new Media entry
12  *
13  */
14 /*
15    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
16
17    This program is free software; you can redistribute it and/or
18    modify it under the terms of the GNU General Public License as
19    published by the Free Software Foundation; either version 2 of
20    the License, or (at your option) any later version.
21
22    This program is distributed in the hope that it will be useful,
23    but WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25    General Public License for more details.
26
27    You should have received a copy of the GNU General Public
28    License along with this program; if not, write to the Free
29    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30    MA 02111-1307, USA.
31
32  */
33
34 #include "bacula.h"
35 #include "dird.h"
36
37 /*
38  * Really crude automatic Volume name creation using
39  *  LabelFormat
40  */
41 int newVolume(JCR *jcr)
42 {
43    MEDIA_DBR mr; 
44    POOL_DBR pr;
45    char name[MAXSTRING];
46
47    memset(&mr, 0, sizeof(mr));
48    memset(&pr, 0, sizeof(pr));
49
50    /* See if we can create a new Volume */
51    pr.PoolId = jcr->PoolId;
52    if (db_get_pool_record(jcr->db, &pr) && pr.LabelFormat[0] &&
53        pr.LabelFormat[0] != '*') {
54       if (pr.MaxVols == 0 || pr.NumVols < pr.MaxVols) {
55          memset(&mr, 0, sizeof(mr));
56          mr.PoolId = jcr->PoolId;
57          strcpy(mr.MediaType, jcr->store->media_type);
58          strcpy(name, pr.LabelFormat);   
59          strcat(name, "%04d");
60          sprintf(mr.VolumeName, name, ++pr.NumVols);
61          strcpy(mr.VolStatus, "Append");
62          mr.Recycle = pr.Recycle;
63          mr.VolRetention = pr.VolumeRetention;
64          if (db_create_media_record(jcr->db, &mr) &&
65             db_update_pool_record(jcr->db, &pr) == 1) {
66             Dmsg1(90, "Created new Volume=%s\n", mr.VolumeName);
67             return 1;
68          } else {
69             Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
70          }
71       }
72    }
73    return 0;   
74 }