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.2.1 2005/09/20 21:31:52 jrjackson 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");
64 error("Usage: amcleanupdisk%s <confdir>", versionsuffix());
67 config_name = main_argv[1];
69 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
70 conffile = stralloc2(config_dir, CONFFILE_NAME);
71 if(read_conffile(conffile)) {
72 error("errors processing config file \"%s\"", conffile);
75 conf_diskfile = getconf_str(CNF_DISKFILE);
76 if (*conf_diskfile == '/') {
77 conf_diskfile = stralloc(conf_diskfile);
79 conf_diskfile = stralloc2(config_dir, conf_diskfile);
81 if((diskqp = read_diskfile(conf_diskfile)) == NULL) {
82 error("could not load disklist %s", conf_diskfile);
84 amfree(conf_diskfile);
85 conf_infofile = getconf_str(CNF_INFOFILE);
86 if (*conf_infofile == '/') {
87 conf_infofile = stralloc(conf_infofile);
89 conf_infofile = stralloc2(config_dir, conf_infofile);
91 if(open_infofile(conf_infofile)) {
92 error("could not open info db \"%s\"", conf_infofile);
94 amfree(conf_infofile);
96 datestamp = construct_datestamp(NULL);
98 dumpuser = getconf_str(CNF_DUMPUSER);
99 if((pw = getpwnam(dumpuser)) == NULL) {
100 error("dumpuser %s not found in password file", dumpuser);
102 if(pw->pw_uid != getuid()) {
103 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);