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