]>
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, 1995, 1996
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 char copyright
[] =
43 "@(#) Copyright (c) 1983, 1993\n\
44 The Regents of the University of California. All rights reserved.\n";
48 static char sccsid
[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
51 #include <sys/param.h>
56 #include <linux/ext2_fs.h>
57 #include <bsdcompat.h>
59 #include <ufs/ufs/dinode.h>
60 #include <ufs/ffs/fs.h>
61 #endif /* __linux__ */
62 #include <protocols/dumprestore.h>
73 #include <ext2fs/ext2fs.h>
77 #include "pathnames.h"
81 int bflag
= 0, cvtflag
= 0, dflag
= 0, vflag
= 0, yflag
= 0;
82 int hflag
= 1, mflag
= 1, Nflag
= 0;
93 int compare_ignore_not_found
;
95 char *tmpdir
= _PATH_TMP
;
101 static void obsolete
__P((int *, char **[]));
102 static void usage
__P((void));
111 char *inputdev
= _PATH_DEFTAPE
;
112 char *symtbl
= "./restoresymtable";
113 char *p
, name
[MAXPATHLEN
];
119 __progname
= argv
[0];
122 obsolete(&argc
, &argv
);
123 while ((ch
= getopt(argc
, argv
, "b:CcdD:f:himNRrs:tT:vxy")) != EOF
)
126 /* Change default tape blocksize. */
128 ntrec
= strtol(optarg
, &p
, 10);
130 errx(1, "illegal blocksize -- %s", optarg
);
132 errx(1, "block size must be greater than 0");
160 "%c and %c options are mutually exclusive",
171 /* Dumpnum (skip to) for multifile dump tapes. */
172 dumpnum
= strtol(optarg
, &p
, 10);
174 errx(1, "illegal dump number -- %s", optarg
);
176 errx(1, "dump number must be greater than 0");
191 errx(1, "none of C, i, R, r, t or x options specified");
193 if (signal(SIGINT
, onintr
) == SIG_IGN
)
194 (void) signal(SIGINT
, SIG_IGN
);
195 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
196 (void) signal(SIGTERM
, SIG_IGN
);
208 * Compare contents of tape.
213 vprintf(stdout
, "Begin compare restore\n");
214 compare_ignore_not_found
= 0;
216 printf("filesys = %s\n", filesys
);
217 if (stat(filesys
, &stbuf
) < 0) {
218 fprintf(stderr
, "cannot stat directory %s: %s\n",
219 filesys
, strerror(errno
));
222 if (chdir(filesys
) < 0) {
223 fprintf(stderr
, "cannot cd to %s: %s\n",
224 filesys
, strerror(errno
));
228 compare_ignore_not_found
= dumptime
> 0;
229 initsymtable((char *)0);
231 treescan(".", ROOTINO
, nodeupdates
);
247 * Incremental restoration of a file system.
253 * This is an incremental dump tape.
255 vprintf(stdout
, "Begin incremental restore\n");
256 initsymtable(symtbl
);
259 vprintf(stdout
, "Calculate node updates.\n");
260 treescan(".", ROOTINO
, nodeupdates
);
265 * This is a level zero dump tape.
267 vprintf(stdout
, "Begin level 0 restore\n");
268 initsymtable((char *)0);
270 vprintf(stdout
, "Calculate extraction list.\n");
271 treescan(".", ROOTINO
, nodeupdates
);
273 createleaves(symtbl
);
278 vprintf(stdout
, "Verify the directory structure\n");
279 treescan(".", ROOTINO
, verifyfile
);
281 dumpsymtable(symtbl
, (long)1);
284 * Resume an incremental file system restoration.
287 initsymtable(symtbl
);
290 createleaves(symtbl
);
294 dumpsymtable(symtbl
, (long)1);
297 * List contents of tape.
302 initsymtable((char *)0);
304 canon(*argv
++, name
);
305 ino
= dirlookup(name
);
308 treescan(name
, ino
, listfile
);
312 * Batch extraction of tape contents.
317 initsymtable((char *)0);
319 canon(*argv
++, name
);
320 ino
= dirlookup(name
);
325 treescan(name
, ino
, addfile
);
341 (void)fprintf(stderr
, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
342 "restore -i [-chmvy] [-b blocksize] [-f file] [-s fileno]",
343 "restore -r [-cvy] [-b blocksize] [-f file] [-s fileno]",
344 "restore -R [-cvy] [-b blocksize] [-f file] [-s fileno]",
345 "restore -x [-chmvy] [-b blocksize] [-f file] [-s fileno] [file ...]", "restore -t [-chvy] [-b blocksize] [-f file] [-s fileno] [file ...]");
351 * Change set of key letters and ordered arguments into something
352 * getopt(3) will like.
355 obsolete(argcp
, argvp
)
360 char *ap
, **argv
, *flagsp
, **nargv
, *p
;
366 /* Return if no arguments or first argument has leading dash. */
368 if (argc
== 1 || *ap
== '-')
371 /* Allocate space for new arguments. */
372 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
373 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
379 for (flags
= 0; *ap
; ++ap
) {
385 warnx("option requires an argument -- %c", *ap
);
388 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
392 (void)strcpy(&nargv
[0][2], *argv
);
406 /* Terminate flags. */
412 /* Copy remaining arguments. */
413 while (*nargv
++ = *argv
++);
415 /* Update argument count. */
416 *argcp
= nargv
- *argvp
- 1;