]>
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
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.6 1999/10/13 09:57:21 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
;
96 static void obsolete
__P((int *, char **[]));
97 static void usage
__P((void));
100 main(int argc
, char *argv
[])
104 char *inputdev
= _PATH_DEFTAPE
;
105 char *symtbl
= "./restoresymtable";
106 char *p
, name
[MAXPATHLEN
];
108 /* Temp files should *not* be readable. We set permissions later. */
112 __progname
= argv
[0];
118 if ((inputdev
= getenv("TAPE")) == NULL
)
119 inputdev
= _PATH_DEFTAPE
;
120 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
122 if ((tmpdir
= strdup(tmpdir
)) == NULL
)
123 err(1, "malloc tmpdir");
124 for (p
= tmpdir
+ strlen(tmpdir
) - 1; p
>= tmpdir
&& *p
== '/'; p
--)
126 obsolete(&argc
, &argv
);
128 #define optlist "b:CcdD:f:hikmNRrs:tT:uvxy"
130 #define optlist "b:CcdD:f:himNRrs:tT:uvxy"
132 while ((ch
= getopt(argc
, argv
, optlist
)) != -1)
135 /* Change default tape blocksize. */
137 ntrec
= strtol(optarg
, &p
, 10);
139 errx(1, "illegal blocksize -- %s", optarg
);
141 errx(1, "block size must be greater than 0");
174 "%c and %c options are mutually exclusive",
185 /* Dumpnum (skip to) for multifile dump tapes. */
186 dumpnum
= strtol(optarg
, &p
, 10);
188 errx(1, "illegal dump number -- %s", optarg
);
190 errx(1, "dump number must be greater than 0");
208 errx(1, "none of C, i, R, r, t or x options specified");
210 if (signal(SIGINT
, onintr
) == SIG_IGN
)
211 (void) signal(SIGINT
, SIG_IGN
);
212 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
213 (void) signal(SIGTERM
, SIG_IGN
);
227 * Compare contents of tape.
232 Vprintf(stdout
, "Begin compare restore\n");
233 compare_ignore_not_found
= 0;
235 printf("filesys = %s\n", filesys
);
236 if (stat(filesys
, &stbuf
) < 0)
237 err(1, "cannot stat directory %s", filesys
);
238 if (chdir(filesys
) < 0)
239 err(1, "cannot cd to %s", filesys
);
240 compare_ignore_not_found
= dumptime
> 0;
241 initsymtable((char *)0);
243 treescan(".", ROOTINO
, nodeupdates
);
259 * Incremental restoration of a file system.
265 * This is an incremental dump tape.
267 Vprintf(stdout
, "Begin incremental restore\n");
268 initsymtable(symtbl
);
271 Vprintf(stdout
, "Calculate node updates.\n");
272 treescan(".", ROOTINO
, nodeupdates
);
277 * This is a level zero dump tape.
279 Vprintf(stdout
, "Begin level 0 restore\n");
280 initsymtable((char *)0);
282 Vprintf(stdout
, "Calculate extraction list.\n");
283 treescan(".", ROOTINO
, nodeupdates
);
285 createleaves(symtbl
);
290 Vprintf(stdout
, "Verify the directory structure\n");
291 treescan(".", ROOTINO
, verifyfile
);
293 dumpsymtable(symtbl
, (long)1);
296 * Resume an incremental file system restoration.
299 initsymtable(symtbl
);
302 createleaves(symtbl
);
306 dumpsymtable(symtbl
, (long)1);
309 * List contents of tape.
314 initsymtable((char *)0);
316 canon(*argv
++, name
, sizeof(name
));
317 ino
= dirlookup(name
);
320 treescan(name
, ino
, listfile
);
324 * Batch extraction of tape contents.
329 initsymtable((char *)0);
331 canon(*argv
++, name
, sizeof(name
));
332 ino
= dirlookup(name
);
337 treescan(name
, ino
, addfile
);
348 return 0; /* gcc shut up */
359 (void)fprintf(stderr
,
360 "%s %s\n", __progname
, _DUMP_VERSION
);
361 (void)fprintf(stderr
,
362 "usage:\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n",
363 __progname
, " -i [-ch" kerbflag
"muvy] [-b blocksize] [-f file] [-s fileno]",
364 __progname
, " -r [-c" kerbflag
"uvy] [-b blocksize] [-f file] [-s fileno]",
365 __progname
, " -R [-c" kerbflag
"uvy] [-b blocksize] [-f file] [-s fileno]",
366 __progname
, " -x [-ch" kerbflag
"muvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
367 __progname
, " -t [-ch" kerbflag
"kuvy] [-b blocksize] [-f file] [-s fileno] [file ...]");
373 * Change set of key letters and ordered arguments into something
374 * getopt(3) will like.
377 obsolete(int *argcp
, char **argvp
[])
380 char *ap
, **argv
, *flagsp
= NULL
, **nargv
, *p
= NULL
;
386 /* Return if no arguments or first argument has leading dash. */
388 if (argc
== 1 || *ap
== '-')
391 /* Allocate space for new arguments. */
392 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
393 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
394 err(1, "malloc args");
397 argv
+= 2, argc
-= 2;
399 for (flags
= 0; *ap
; ++ap
) {
405 warnx("option requires an argument -- %c", *ap
);
408 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
409 err(1, "malloc arg");
412 (void)strcpy(&nargv
[0][2], *argv
);
426 /* Terminate flags. */
432 /* Copy remaining arguments. */
433 while ((*nargv
++ = *argv
++));
435 /* Update argument count. */
436 *argcp
= nargv
- *argvp
- 1;