]>
git.wh0rd.org - dump.git/blob - restore/main.c
f979560c0a3a5853cd13d1a227d125ffbd81d14b
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
10 * Copyright (c) 1983, 1993
11 * The Regents of the University of California. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 static const char copyright
[] =
44 "@(#) Copyright (c) 1983, 1993\n\
45 The Regents of the University of California. All rights reserved.\n";
50 static char sccsid
[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
52 static const char rcsid
[] =
53 "$Id: main.c,v 1.3 1999/10/11 12:59:20 stelian Exp $";
56 #include <sys/param.h>
61 #include <linux/ext2_fs.h>
62 #include <bsdcompat.h>
66 #include <ufs/ufs/dinode.h>
67 #endif /* __linux__ */
68 #include <protocols/dumprestore.h>
70 #include <compaterr.h>
76 #include <ext2fs/ext2fs.h>
80 #include "pathnames.h"
84 int bflag
= 0, cvtflag
= 0, dflag
= 0, vflag
= 0, yflag
= 0;
85 int hflag
= 1, mflag
= 1, Nflag
= 0;
99 int compare_ignore_not_found
;
100 char *filesys
= NULL
;
106 static void obsolete
__P((int *, char **[]));
107 static void usage
__P((void));
110 main(int argc
, char *argv
[])
114 char *inputdev
= _PATH_DEFTAPE
;
115 char *symtbl
= "./restoresymtable";
116 char *p
, name
[MAXPATHLEN
];
118 /* Temp files should *not* be readable. We set permissions later. */
122 __progname
= argv
[0];
128 if ((inputdev
= getenv("TAPE")) == NULL
)
129 inputdev
= _PATH_DEFTAPE
;
130 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
132 if ((tmpdir
= strdup(tmpdir
)) == NULL
)
133 err(1, "malloc tmpdir");
134 for (p
= tmpdir
+ strlen(tmpdir
) - 1; p
>= tmpdir
&& *p
== '/'; p
--)
136 obsolete(&argc
, &argv
);
138 #define optlist "b:CcdD:f:hikmNRrs:tT:uvxy"
140 #define optlist "b:CcdD:f:himNRrs:tT:uvxy"
142 while ((ch
= getopt(argc
, argv
, optlist
)) != -1)
145 /* Change default tape blocksize. */
147 ntrec
= strtol(optarg
, &p
, 10);
149 errx(1, "illegal blocksize -- %s", optarg
);
151 errx(1, "block size must be greater than 0");
184 "%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");
218 errx(1, "none of C, i, R, r, t or x options specified");
220 if (signal(SIGINT
, onintr
) == SIG_IGN
)
221 (void) signal(SIGINT
, SIG_IGN
);
222 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
223 (void) signal(SIGTERM
, SIG_IGN
);
237 * Compare contents of tape.
242 Vprintf(stdout
, "Begin compare restore\n");
243 compare_ignore_not_found
= 0;
245 printf("filesys = %s\n", filesys
);
246 if (stat(filesys
, &stbuf
) < 0)
247 err(1, "cannot stat directory %s", filesys
);
248 if (chdir(filesys
) < 0)
249 err(1, "cannot cd to %s", filesys
);
250 compare_ignore_not_found
= dumptime
> 0;
251 initsymtable((char *)0);
253 treescan(".", ROOTINO
, nodeupdates
);
269 * Incremental restoration of a file system.
275 * This is an incremental dump tape.
277 Vprintf(stdout
, "Begin incremental restore\n");
278 initsymtable(symtbl
);
281 Vprintf(stdout
, "Calculate node updates.\n");
282 treescan(".", ROOTINO
, nodeupdates
);
287 * This is a level zero dump tape.
289 Vprintf(stdout
, "Begin level 0 restore\n");
290 initsymtable((char *)0);
292 Vprintf(stdout
, "Calculate extraction list.\n");
293 treescan(".", ROOTINO
, nodeupdates
);
295 createleaves(symtbl
);
300 Vprintf(stdout
, "Verify the directory structure\n");
301 treescan(".", ROOTINO
, verifyfile
);
303 dumpsymtable(symtbl
, (long)1);
306 * Resume an incremental file system restoration.
309 initsymtable(symtbl
);
312 createleaves(symtbl
);
316 dumpsymtable(symtbl
, (long)1);
319 * List contents of tape.
324 initsymtable((char *)0);
326 canon(*argv
++, name
, sizeof(name
));
327 ino
= dirlookup(name
);
330 treescan(name
, ino
, listfile
);
334 * Batch extraction of tape contents.
339 initsymtable((char *)0);
341 canon(*argv
++, name
, sizeof(name
));
342 ino
= dirlookup(name
);
347 treescan(name
, ino
, addfile
);
358 return 0; /* gcc shut up */
364 (void)fprintf(stderr
, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
365 "restore -i [-chkmuvy] [-b blocksize] [-f file] [-s fileno]",
366 "restore -r [-ckuvy] [-b blocksize] [-f file] [-s fileno]",
367 "restore -R [-ckuvy] [-b blocksize] [-f file] [-s fileno]",
368 "restore -x [-chkmuvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
369 "restore -t [-chkuvy] [-b blocksize] [-f file] [-s fileno] [file ...]");
375 * Change set of key letters and ordered arguments into something
376 * getopt(3) will like.
379 obsolete(int *argcp
, char **argvp
[])
382 char *ap
, **argv
, *flagsp
= NULL
, **nargv
, *p
= NULL
;
388 /* Return if no arguments or first argument has leading dash. */
390 if (argc
== 1 || *ap
== '-')
393 /* Allocate space for new arguments. */
394 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
395 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
396 err(1, "malloc args");
399 argv
+= 2, argc
-= 2;
401 for (flags
= 0; *ap
; ++ap
) {
407 warnx("option requires an argument -- %c", *ap
);
410 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
411 err(1, "malloc arg");
414 (void)strcpy(&nargv
[0][2], *argv
);
428 /* Terminate flags. */
434 /* Copy remaining arguments. */
435 while ((*nargv
++ = *argv
++));
437 /* Update argument count. */
438 *argcp
= nargv
- *argvp
- 1;