a67154cbbf5657db027e1334de3f62e2558b2e15
[debian/amanda] / server-src / amcleanupdisk.c
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1998 University of Maryland at College Park
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of U.M. not be used in advertising or
11  * publicity pertaining to distribution of the software without specific,
12  * written prior permission.  U.M. makes no representations about the
13  * suitability of this software for any purpose.  It is provided "as is"
14  * without express or implied warranty.
15  *
16  * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Authors: the Amanda Development Team.  Its members are listed in a
24  * file named AUTHORS, in the root directory of this distribution.
25  */
26 /*
27  * $Id: amcleanupdisk.c 7238 2007-07-06 20:03:37Z dustin $
28  */
29 #include "amanda.h"
30
31 #include "conffile.h"
32 #include "diskfile.h"
33 #include "clock.h"
34 #include "version.h"
35 #include "holding.h"
36 #include "infofile.h"
37 #include "server_util.h"
38
39 /* Utility funcitons */
40
41 /* Call open_diskfile() with the diskfile from the configuration
42  */
43 static void
44 init_diskfile(void)
45 {
46     char *conf_diskfile = config_dir_relative(getconf_str(CNF_DISKFILE));
47     disklist_t diskq; /* never used, but required by read_diskfile */
48
49     if (read_diskfile(conf_diskfile, &diskq) < 0) {
50         error(_("could not load disklist %s"), conf_diskfile);
51         /*NOTREACHED*/
52     }
53     amfree(conf_diskfile);
54 }
55
56 /* Call open_infofile() with the infofile from the configuration
57  */
58 static void
59 init_infofile(void)
60 {
61     char *conf_infofile = config_dir_relative(getconf_str(CNF_INFOFILE));
62     if (open_infofile(conf_infofile) < 0) {
63         error(_("could not open info db \"%s\""), conf_infofile);
64         /*NOTREACHED*/
65     }
66     amfree(conf_infofile);
67 }
68
69 /* A callback for holding_cleanup to mark corrupt DLEs with force_no_bump
70  * for their next run.
71  *
72  * @param hostname: hostname of DLE
73  * @param disk: disk of DLE
74  */
75 static void
76 corrupt_dle(
77     char *hostname,
78     char *disk)
79 {
80     info_t info;
81
82     dbprintf(_("Corrupted dump of DLE %s:%s found; setting force-no-bump.\n"),
83         hostname, disk);
84
85     get_info(hostname, disk, &info);
86     info.command &= ~FORCE_BUMP;
87     info.command |= FORCE_NO_BUMP;
88     if(put_info(hostname, disk, &info)) {
89         dbprintf(_("could not put info record for %s:%s: %s"),
90               hostname, disk, strerror(errno));
91     }
92 }
93
94 int
95 main(
96     int         argc,
97     char **     argv)
98 {
99     FILE *verbose_output = NULL;
100     char *cfg_opt = NULL;
101
102     /*
103      * Configure program for internationalization:
104      *   1) Only set the message locale for now.
105      *   2) Set textdomain for all amanda related programs to "amanda"
106      *      We don't want to be forced to support dozens of message catalogs.
107      */  
108     setlocale(LC_MESSAGES, "C");
109     textdomain("amanda"); 
110
111     safe_fd(-1, 0);
112     safe_cd();
113
114     set_pname("amcleanupdisk");
115
116     dbopen(DBG_SUBDIR_SERVER);
117
118     if(argc < 2) {
119         error(_("Usage: amcleanupdisk%s <config>"), versionsuffix());
120         /*NOTREACHED*/
121     }
122
123     /* parse options */
124     if (argc >= 2 && strcmp(argv[1], "-v") == 0) {
125         verbose_output = stderr;
126         cfg_opt = argv[2];
127     } else {
128         cfg_opt = argv[1];
129     }
130
131     config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_FATAL,
132                 cfg_opt);
133
134     check_running_as(RUNNING_AS_DUMPUSER);
135
136     dbrename(config_name, DBG_SUBDIR_SERVER);
137
138     init_diskfile();
139     init_infofile();
140
141     /* actually perform the cleanup */
142     holding_cleanup(corrupt_dle, verbose_output);
143
144     close_infofile();
145     return 0;
146 }
147