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.22.2.1 2006/10/03 18:57:25 martinea Exp $
37 #include "server_util.h"
43 int main(int argc, char **argv);
44 void check_holdingdisk(char *diskdir, char *datestamp);
45 void check_disks(void);
62 set_pname("amcleanupdisk");
64 dbopen(DBG_SUBDIR_SERVER);
66 /* Don't die when child closes pipe */
67 signal(SIGPIPE, SIG_IGN);
70 error("Usage: amcleanupdisk%s <config>", versionsuffix());
74 config_name = main_argv[1];
76 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
78 conffile = stralloc2(config_dir, CONFFILE_NAME);
79 if(read_conffile(conffile)) {
80 error("errors processing config file \"%s\"", conffile);
85 dbrename(config_name, DBG_SUBDIR_SERVER);
87 conf_diskfile = getconf_str(CNF_DISKFILE);
88 if (*conf_diskfile == '/') {
89 conf_diskfile = stralloc(conf_diskfile);
91 conf_diskfile = stralloc2(config_dir, conf_diskfile);
93 if (read_diskfile(conf_diskfile, &diskq) < 0) {
94 error("could not load disklist %s", conf_diskfile);
97 amfree(conf_diskfile);
99 conf_infofile = getconf_str(CNF_INFOFILE);
100 if (*conf_infofile == '/') {
101 conf_infofile = stralloc(conf_infofile);
103 conf_infofile = stralloc2(config_dir, conf_infofile);
105 if (open_infofile(conf_infofile) < 0) {
106 error("could not open info db \"%s\"", conf_infofile);
109 amfree(conf_infofile);
111 datestamp = construct_datestamp(NULL);
113 dumpuser = getconf_str(CNF_DUMPUSER);
114 if((pw = getpwnam(dumpuser)) == NULL) {
115 error("dumpuser %s not found in password file", dumpuser);
119 if(pw->pw_uid != getuid()) {
120 error("must run amcleanupdisk as user %s", dumpuser);
124 holding_list = pick_all_datestamp(1);
130 free_sl(holding_list);
143 struct dirent *entry;
144 char *dirname = NULL;
145 char *tmpname = NULL;
146 char *destname = NULL;
147 char *hostname = NULL;
148 char *diskname = NULL;
155 dirname = vstralloc(diskdir, "/", datestamp, NULL);
156 dl = strlen(dirname);
158 if((workdir = opendir(dirname)) == NULL) {
163 while((entry = readdir(workdir)) != NULL) {
164 if(is_dot_or_dotdot(entry->d_name)) {
168 if((l = strlen(entry->d_name)) < 7 ) {
172 if(strncmp(&entry->d_name[l-4],".tmp",4) != 0) {
176 tmpname = newvstralloc(tmpname,
177 dirname, "/", entry->d_name,
180 destname = newstralloc(destname, tmpname);
181 destname[dl + 1 + l - 4] = '\0';
185 filetype = get_amanda_names(tmpname, &hostname, &diskname, &level);
187 if(filetype != F_DUMPFILE) {
191 dp = lookup_disk(hostname, diskname);
197 if(level < 0 || level > 9) {
201 if(rename_tmp_holding(destname, 0)) {
202 get_info(dp->host->hostname, dp->name, &info);
203 info.command &= ~FORCE_BUMP;
204 info.command |= FORCE_NO_BUMP;
205 if(put_info(dp->host->hostname, dp->name, &info)) {
206 error("could not put info record for %s:%s: %s",
207 dp->host->hostname, dp->name, strerror(errno));
211 fprintf(stderr,"rename_tmp_holding(%s) failed\n", destname);
216 /* try to zap the potentially empty working dir */
217 /* ignore any errors -- it either works or it doesn't */
218 (void) rmdir(dirname);
230 holdingdisk_t *hdisk;
233 for(dir = holding_list->first; dir !=NULL; dir = dir->next) {
234 for(hdisk = getconf_holdingdisks(); hdisk != NULL; hdisk = hdisk->next)
235 check_holdingdisk(holdingdisk_get_diskdir(hdisk), dir->name);