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.1.2.6.4.3.2.2 2002/11/05 01:59:23 martinea 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)
59 for(fd = 3; fd < FD_SETSIZE; fd++) {
61 * Make sure nobody spoofs us with a lot of extra open files
62 * that would cause an open we do to get a very high file
63 * descriptor, which in turn might be used as an index into
64 * an array (e.g. an fd_set).
71 set_pname("amcleanupdisk");
74 error("Usage: amcleanupdisk%s <confdir>", versionsuffix());
77 config_name = main_argv[1];
79 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
80 conffile = stralloc2(config_dir, CONFFILE_NAME);
81 if(read_conffile(conffile)) {
82 error("errors processing config file \"%s\"", conffile);
85 conf_diskfile = getconf_str(CNF_DISKFILE);
86 if (*conf_diskfile == '/') {
87 conf_diskfile = stralloc(conf_diskfile);
89 conf_diskfile = stralloc2(config_dir, conf_diskfile);
91 if((diskqp = read_diskfile(conf_diskfile)) == NULL) {
92 error("could not load disklist %s", conf_diskfile);
94 amfree(conf_diskfile);
95 conf_infofile = getconf_str(CNF_INFOFILE);
96 if (*conf_infofile == '/') {
97 conf_infofile = stralloc(conf_infofile);
99 conf_infofile = stralloc2(config_dir, conf_infofile);
101 if(open_infofile(conf_infofile)) {
102 error("could not open info db \"%s\"", conf_infofile);
104 amfree(conf_infofile);
106 datestamp = construct_datestamp(NULL);
108 dumpuser = getconf_str(CNF_DUMPUSER);
109 if((pw = getpwnam(dumpuser)) == NULL) {
110 error("dumpuser %s not found in password file", dumpuser);
112 if(pw->pw_uid != getuid()) {
113 error("must run amcleanupdisk as user %s", dumpuser);
116 holding_list = pick_all_datestamp(1);
122 free_sl(holding_list);
129 void check_holdingdisk(diskdir, datestamp)
130 char *diskdir, *datestamp;
133 struct dirent *entry;
134 char *dirname = NULL;
135 char *tmpname = NULL;
136 char *destname = NULL;
137 char *hostname = NULL;
138 char *diskname = NULL;
145 dirname = vstralloc(diskdir, "/", datestamp, NULL);
146 dl = strlen(dirname);
148 if((workdir = opendir(dirname)) == NULL) {
153 while((entry = readdir(workdir)) != NULL) {
154 if(is_dot_or_dotdot(entry->d_name)) {
158 if((l = strlen(entry->d_name)) < 7 ) {
162 if(strncmp(&entry->d_name[l-4],".tmp",4) != 0) {
166 tmpname = newvstralloc(tmpname,
167 dirname, "/", entry->d_name,
170 destname = newstralloc(destname, tmpname);
171 destname[dl + 1 + l - 4] = '\0';
175 filetype = get_amanda_names(tmpname, &hostname, &diskname, &level);
176 if(filetype != F_DUMPFILE) {
180 dp = lookup_disk(hostname, diskname);
186 if(level < 0 || level > 9) {
190 if(rename_tmp_holding(destname, 0)) {
191 get_info(dp->host->hostname, dp->name, &info);
192 info.command &= ~FORCE_BUMP;
193 info.command |= FORCE_NO_BUMP;
194 if(put_info(dp->host->hostname, dp->name, &info)) {
195 error("could not put info record for %s:%s: %s",
196 dp->host->hostname, dp->name, strerror(errno));
199 fprintf(stderr,"rename_tmp_holding(%s) failed\n", destname);
204 /* try to zap the potentially empty working dir */
205 /* ignore any errors -- it either works or it doesn't */
206 (void) rmdir(dirname);
217 holdingdisk_t *hdisk;
220 for(dir = holding_list->first; dir !=NULL; dir = dir->next) {
221 for(hdisk = getconf_holdingdisks(); hdisk != NULL; hdisk = hdisk->next)
222 check_holdingdisk(hdisk->diskdir, dir->name);