]>
git.wh0rd.org - dump.git/blob - restore/main.c
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <pop@cybercable.fr>, 1999-2000
9 * Copyright (c) 1983, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 static const char rcsid
[] =
43 "$Id: main.c,v 1.11 2000/03/09 13:12:31 stelian Exp $";
46 #include <sys/param.h>
51 #include <linux/ext2_fs.h>
52 #include <bsdcompat.h>
56 #include <ufs/ufs/dinode.h>
57 #endif /* __linux__ */
58 #include <protocols/dumprestore.h>
60 #include <compaterr.h>
66 #include <ext2fs/ext2fs.h>
70 #include "pathnames.h"
74 int bflag
= 0, cvtflag
= 0, dflag
= 0, vflag
= 0, yflag
= 0;
75 int hflag
= 1, mflag
= 1, Nflag
= 0;
89 int compare_ignore_not_found
;
90 char filesys
[NAMELEN
];
91 static const char *stdin_opt
= NULL
;
97 static void obsolete
__P((int *, char **[]));
98 static void usage
__P((void));
99 static void use_stdin
__P((const char *));
102 main(int argc
, char *argv
[])
106 char *inputdev
= _PATH_DEFTAPE
;
107 char *symtbl
= "./restoresymtable";
108 char *p
, name
[MAXPATHLEN
];
109 FILE *filelist
= NULL
;
110 char fname
[MAXPATHLEN
];
112 /* Temp files should *not* be readable. We set permissions later. */
116 __progname
= argv
[0];
122 if ((inputdev
= getenv("TAPE")) == NULL
)
123 inputdev
= _PATH_DEFTAPE
;
124 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
126 if ((tmpdir
= strdup(tmpdir
)) == NULL
)
127 err(1, "malloc tmpdir");
128 for (p
= tmpdir
+ strlen(tmpdir
) - 1; p
>= tmpdir
&& *p
== '/'; p
--)
130 obsolete(&argc
, &argv
);
132 #define optlist "b:CcdD:f:hikmMNRrs:tT:uvxX:y"
134 #define optlist "b:CcdD:f:himMNRrs:tT:uvxX:y"
136 while ((ch
= getopt(argc
, argv
, optlist
)) != -1)
139 /* Change default tape blocksize. */
141 ntrec
= strtol(optarg
, &p
, 10);
143 errx(1, "illegal blocksize -- %s", optarg
);
145 errx(1, "block size must be greater than 0");
151 strncpy(filesys
, optarg
, NAMELEN
);
152 filesys
[NAMELEN
- 1] = '\0';
161 if( !strcmp(optarg
,"-") )
181 "%c and %c options are mutually exclusive",
195 /* Dumpnum (skip to) for multifile dump tapes. */
196 dumpnum
= strtol(optarg
, &p
, 10);
198 errx(1, "illegal dump number -- %s", optarg
);
200 errx(1, "dump number must be greater than 0");
209 if( !strcmp(optarg
,"-") ) {
214 if ( !(filelist
= fopen(optarg
,"r")) )
215 errx(1, "can't open file for reading -- %s", optarg
);
227 errx(1, "none of C, i, R, r, t or x options specified");
229 if (signal(SIGINT
, onintr
) == SIG_IGN
)
230 (void) signal(SIGINT
, SIG_IGN
);
231 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
232 (void) signal(SIGTERM
, SIG_IGN
);
239 if (argc
== 0 && !filelist
) {
246 * Compare contents of tape.
251 Vprintf(stdout
, "Begin compare restore\n");
252 compare_ignore_not_found
= 0;
254 printf("filesys = %s\n", filesys
);
255 if (stat(filesys
, &stbuf
) < 0)
256 err(1, "cannot stat directory %s", filesys
);
257 if (chdir(filesys
) < 0)
258 err(1, "cannot cd to %s", filesys
);
259 compare_ignore_not_found
= dumptime
> 0;
260 initsymtable((char *)0);
262 treescan(".", ROOTINO
, nodeupdates
);
278 * Incremental restoration of a file system.
284 * This is an incremental dump tape.
286 Vprintf(stdout
, "Begin incremental restore\n");
287 initsymtable(symtbl
);
290 Vprintf(stdout
, "Calculate node updates.\n");
291 treescan(".", ROOTINO
, nodeupdates
);
296 * This is a level zero dump tape.
298 Vprintf(stdout
, "Begin level 0 restore\n");
299 initsymtable((char *)0);
301 Vprintf(stdout
, "Calculate extraction list.\n");
302 treescan(".", ROOTINO
, nodeupdates
);
304 createleaves(symtbl
);
309 Vprintf(stdout
, "Verify the directory structure\n");
310 treescan(".", ROOTINO
, verifyfile
);
312 dumpsymtable(symtbl
, (long)1);
315 * Resume an incremental file system restoration.
318 initsymtable(symtbl
);
321 createleaves(symtbl
);
325 dumpsymtable(symtbl
, (long)1);
328 /* handle file names from either text file (-X) or the command line */
329 #define NEXTFILE(p) \
335 else if (filelist) { \
336 if ((p = fgets(fname, MAXPATHLEN, filelist))) { \
337 if ( *p && *(p + strlen(p) - 1) == '\n' ) /* possible null string */ \
338 *(p + strlen(p) - 1) = '\0'; \
339 if ( !*p ) /* skip empty lines */ \
345 * List contents of tape.
350 initsymtable((char *)0);
355 canon(p
, name
, sizeof(name
));
356 ino
= dirlookup(name
);
359 treescan(name
, ino
, listfile
);
363 * Batch extraction of tape contents.
368 initsymtable((char *)0);
373 canon(p
, name
, sizeof(name
));
374 ino
= dirlookup(name
);
379 treescan(name
, ino
, addfile
);
390 return 0; /* gcc shut up */
401 (void)fprintf(stderr
,
402 "%s %s\n", __progname
, _DUMP_VERSION
);
403 (void)fprintf(stderr
,
404 "usage:\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n",
405 __progname
, " -i [-ch" kerbflag
"mMuvy] [-b blocksize] [-f file] [-s fileno]",
406 __progname
, " -r [-c" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno]",
407 __progname
, " -R [-c" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno]",
408 __progname
, " -x [-ch" kerbflag
"mMuvy] [-b blocksize] [-f file] [-s fileno] [-X filelist] [file ...]",
409 __progname
, " -t [-ch" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno] [-X filelist] [file ...]");
415 * Change set of key letters and ordered arguments into something
416 * getopt(3) will like.
419 obsolete(int *argcp
, char **argvp
[])
422 char *ap
, **argv
, *flagsp
= NULL
, **nargv
, *p
= NULL
;
428 /* Return if no arguments or first argument has leading dash. */
430 if (argc
== 1 || *ap
== '-')
433 /* Allocate space for new arguments. */
434 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
435 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
436 err(1, "malloc args");
439 argv
+= 2, argc
-= 2;
441 for (flags
= 0; *ap
; ++ap
) {
450 warnx("option requires an argument -- %c", *ap
);
453 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
454 err(1, "malloc arg");
457 (void)strcpy(&nargv
[0][2], *argv
);
471 /* Terminate flags. */
477 /* Copy remaining arguments. */
478 while ((*nargv
++ = *argv
++));
480 /* Update argument count. */
481 *argcp
= nargv
- *argvp
- 1;
486 * reserve stdin for opt (avoid conflicts)
489 use_stdin(const char *opt
)
492 errx(1, "can't handle standard input for both %s and %s",