Imported Upstream version 3.2.0
[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 "holding.h"
35 #include "infofile.h"
36 #include "server_util.h"
37
38 /* Utility funcitons */
39
40 /* Call open_infofile() with the infofile from the configuration
41  */
42 static void
43 init_infofile(void)
44 {
45     char *conf_infofile = config_dir_relative(getconf_str(CNF_INFOFILE));
46     if (open_infofile(conf_infofile) < 0) {
47         error(_("could not open info db \"%s\""), conf_infofile);
48         /*NOTREACHED*/
49     }
50     amfree(conf_infofile);
51 }
52
53 /* A callback for holding_cleanup to mark corrupt DLEs with force_no_bump
54  * for their next run.
55  *
56  * @param hostname: hostname of DLE
57  * @param disk: disk of DLE
58  */
59 static void
60 corrupt_dle(
61     char *hostname,
62     char *disk)
63 {
64     info_t info;
65
66     dbprintf(_("Corrupted dump of DLE %s:%s found; setting force-no-bump.\n"),
67         hostname, disk);
68
69     get_info(hostname, disk, &info);
70     CLR(info.command, FORCE_BUMP);
71     SET(info.command, FORCE_NO_BUMP);
72     if(put_info(hostname, disk, &info)) {
73         dbprintf(_("could not put info record for %s:%s: %s"),
74               hostname, disk, strerror(errno));
75     }
76 }
77
78 int
79 main(
80     int         argc,
81     char **     argv)
82 {
83     FILE *verbose_output = NULL;
84     char *cfg_opt = NULL;
85     char *conf_diskfile;
86     disklist_t diskq;
87
88     /*
89      * Configure program for internationalization:
90      *   1) Only set the message locale for now.
91      *   2) Set textdomain for all amanda related programs to "amanda"
92      *      We don't want to be forced to support dozens of message catalogs.
93      */  
94     setlocale(LC_MESSAGES, "C");
95     textdomain("amanda"); 
96
97     safe_fd(-1, 0);
98     safe_cd();
99
100     set_pname("amcleanupdisk");
101
102     dbopen(DBG_SUBDIR_SERVER);
103
104     if(argc < 2) {
105         error(_("Usage: amcleanupdisk <config>"));
106         /*NOTREACHED*/
107     }
108
109     /* parse options */
110     if (argc >= 2 && strcmp(argv[1], "-v") == 0) {
111         verbose_output = stderr;
112         cfg_opt = argv[2];
113     } else {
114         cfg_opt = argv[1];
115     }
116
117     config_init(CONFIG_INIT_EXPLICIT_NAME,
118                 cfg_opt);
119
120     conf_diskfile = config_dir_relative(getconf_str(CNF_DISKFILE));
121     read_diskfile(conf_diskfile, &diskq);
122     /* diskq also ends up in a global, used by holding_cleanup */
123     amfree(conf_diskfile);
124
125     if (config_errors(NULL) >= CFGERR_WARNINGS) {
126         config_print_errors();
127         if (config_errors(NULL) >= CFGERR_ERRORS) {
128             g_critical(_("errors processing config file"));
129         }
130     }
131
132     check_running_as(RUNNING_AS_DUMPUSER);
133
134     dbrename(get_config_name(), DBG_SUBDIR_SERVER);
135
136     init_infofile();
137
138     /* actually perform the cleanup */
139     holding_cleanup(corrupt_dle, verbose_output);
140
141     close_infofile();
142     return 0;
143 }
144