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