2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
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.
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.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: amcleanupdisk.c,v 1.16 2006/01/14 04:37:19 paddy_s Exp $
37 #include "server_util.h"
43 int main P((int argc, char **argv));
44 void check_holdingdisk P((char *diskdir, char *datestamp));
45 void check_disks P((void));
47 int main(main_argc, main_argv)
61 set_pname("amcleanupdisk");
63 /* Don't die when child closes pipe */
64 signal(SIGPIPE, SIG_IGN);
67 error("Usage: amcleanupdisk%s <confdir>", versionsuffix());
69 config_name = main_argv[1];
71 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
73 conffile = stralloc2(config_dir, CONFFILE_NAME);
74 if(read_conffile(conffile))
75 error("errors processing config file \"%s\"", conffile);
78 conf_diskfile = getconf_str(CNF_DISKFILE);
79 if (*conf_diskfile == '/') {
80 conf_diskfile = stralloc(conf_diskfile);
82 conf_diskfile = stralloc2(config_dir, conf_diskfile);
84 if (read_diskfile(conf_diskfile, &diskq) < 0)
85 error("could not load disklist %s", conf_diskfile);
86 amfree(conf_diskfile);
88 conf_infofile = getconf_str(CNF_INFOFILE);
89 if (*conf_infofile == '/') {
90 conf_infofile = stralloc(conf_infofile);
92 conf_infofile = stralloc2(config_dir, conf_infofile);
94 if (open_infofile(conf_infofile) < 0)
95 error("could not open info db \"%s\"", conf_infofile);
96 amfree(conf_infofile);
98 datestamp = construct_datestamp(NULL);
100 dumpuser = getconf_str(CNF_DUMPUSER);
101 if((pw = getpwnam(dumpuser)) == NULL)
102 error("dumpuser %s not found in password file", dumpuser);
103 if(pw->pw_uid != getuid())
104 error("must run amcleanupdisk as user %s", dumpuser);
106 holding_list = pick_all_datestamp(1);
112 free_sl(holding_list);
119 void check_holdingdisk(diskdir, datestamp)
120 char *diskdir, *datestamp;
123 struct dirent *entry;
124 char *dirname = NULL;
125 char *tmpname = NULL;
126 char *destname = NULL;
127 char *hostname = NULL;
128 char *diskname = NULL;
135 dirname = vstralloc(diskdir, "/", datestamp, NULL);
136 dl = strlen(dirname);
138 if((workdir = opendir(dirname)) == NULL) {
143 while((entry = readdir(workdir)) != NULL) {
144 if(is_dot_or_dotdot(entry->d_name)) {
148 if((l = strlen(entry->d_name)) < 7 ) {
152 if(strncmp(&entry->d_name[l-4],".tmp",4) != 0) {
156 tmpname = newvstralloc(tmpname,
157 dirname, "/", entry->d_name,
160 destname = newstralloc(destname, tmpname);
161 destname[dl + 1 + l - 4] = '\0';
165 filetype = get_amanda_names(tmpname, &hostname, &diskname, &level);
166 if(filetype != F_DUMPFILE) {
170 dp = lookup_disk(hostname, diskname);
176 if(level < 0 || level > 9) {
180 if(rename_tmp_holding(destname, 0)) {
181 get_info(dp->host->hostname, dp->name, &info);
182 info.command &= ~FORCE_BUMP;
183 info.command |= FORCE_NO_BUMP;
184 if(put_info(dp->host->hostname, dp->name, &info)) {
185 error("could not put info record for %s:%s: %s",
186 dp->host->hostname, dp->name, strerror(errno));
189 fprintf(stderr,"rename_tmp_holding(%s) failed\n", destname);
194 /* try to zap the potentially empty working dir */
195 /* ignore any errors -- it either works or it doesn't */
196 (void) rmdir(dirname);
207 holdingdisk_t *hdisk;
210 for(dir = holding_list->first; dir !=NULL; dir = dir->next) {
211 for(hdisk = getconf_holdingdisks(); hdisk != NULL; hdisk = hdisk->next)
212 check_holdingdisk(hdisk->diskdir, dir->name);