]>
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@noos.fr>, 1999-2000
6 * Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
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 rcsid
[] =
44 "$Id: main.c,v 1.22 2001/04/24 15:04:59 stelian Exp $";
48 #include <sys/param.h>
55 #ifdef HAVE_EXT2FS_EXT2_FS_H
56 #include <ext2fs/ext2_fs.h>
58 #include <linux/ext2_fs.h>
60 #include <bsdcompat.h>
64 #include <ufs/ufs/dinode.h>
65 #endif /* __linux__ */
66 #include <protocols/dumprestore.h>
68 #include <compaterr.h>
74 #include <ext2fs/ext2fs.h>
78 #include "pathnames.h"
82 int bflag
= 0, cvtflag
= 0, dflag
= 0, vflag
= 0, yflag
= 0;
83 int hflag
= 1, mflag
= 1, Nflag
= 0, zflag
= 0;
97 int compare_ignore_not_found
;
99 char filesys
[NAMELEN
];
100 static const char *stdin_opt
= NULL
;
106 static void obsolete
__P((int *, char **[]));
107 static void usage
__P((void));
108 static void use_stdin
__P((const char *));
111 main(int argc
, char *argv
[])
115 char *inputdev
= _PATH_DEFTAPE
;
116 char *symtbl
= "./restoresymtable";
117 char *p
, name
[MAXPATHLEN
];
118 FILE *filelist
= NULL
;
119 char fname
[MAXPATHLEN
];
121 time_t tistart
, tiend
, titaken
;
125 /* Temp files should *not* be readable. We set permissions later. */
129 __progname
= argv
[0];
135 if ((inputdev
= getenv("TAPE")) == NULL
)
136 inputdev
= _PATH_DEFTAPE
;
137 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
139 if ((tmpdir
= strdup(tmpdir
)) == NULL
)
140 err(1, "malloc tmpdir");
141 for (p
= tmpdir
+ strlen(tmpdir
) - 1; p
>= tmpdir
&& *p
== '/'; p
--)
143 obsolete(&argc
, &argv
);
144 while ((ch
= getopt(argc
, argv
,
153 "Rrs:tT:uvxX:y")) != -1)
156 /* Change default tape blocksize. */
158 ntrec
= strtol(optarg
, &p
, 10);
160 errx(1, "illegal blocksize -- %s", optarg
);
162 errx(1, "block size must be greater than 0");
168 strncpy(filesys
, optarg
, NAMELEN
);
169 filesys
[NAMELEN
- 1] = '\0';
178 if( !strcmp(optarg
,"-") )
198 "%c and %c options are mutually exclusive",
213 gTapeposfile
= optarg
;
218 /* Dumpnum (skip to) for multifile dump tapes. */
219 dumpnum
= strtol(optarg
, &p
, 10);
221 errx(1, "illegal dump number -- %s", optarg
);
223 errx(1, "dump number must be greater than 0");
232 if( !strcmp(optarg
,"-") ) {
237 if ( !(filelist
= fopen(optarg
,"r")) )
238 errx(1, "can't open file for reading -- %s", optarg
);
250 errx(1, "none of C, i, R, r, t or x options specified");
253 if (!mflag
&& tapeposflag
)
254 errx(1, "m and Q options are mutually exclusive"):
257 if (signal(SIGINT
, onintr
) == SIG_IGN
)
258 (void) signal(SIGINT
, SIG_IGN
);
259 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
260 (void) signal(SIGTERM
, SIG_IGN
);
267 if (argc
== 0 && !filelist
) {
274 msg("reading QFA positions from %s\n", gTapeposfile
);
275 if ((gTapeposfp
= fopen(gTapeposfile
, "r")) == NULL
)
276 errx(1, "can't open file for reading -- %s",
278 /* start reading header info */
279 if (fgets(gTps
, sizeof(gTps
), gTapeposfp
) == NULL
)
280 errx(1, "not requested format of -- %s", gTapeposfile
);
281 gTps
[strlen(gTps
) - 1] = 0; /* delete end of line */
282 if (strcmp(gTps
, QFA_MAGIC
) != 0)
283 errx(1, "not requested format of -- %s", gTapeposfile
);
284 if (fgets(gTps
, sizeof(gTps
), gTapeposfp
) == NULL
)
285 errx(1, "not requested format of -- %s", gTapeposfile
);
286 gTps
[strlen(gTps
) - 1] = 0;
287 if (strcmp(gTps
, QFA_VERSION
) != 0)
288 errx(1, "not requested format of -- %s", gTapeposfile
);
290 if (fgets(gTps
, sizeof(gTps
), gTapeposfp
) == NULL
)
291 errx(1, "not requested format of -- %s", gTapeposfile
);
292 gTps
[strlen(gTps
) - 1] = 0;
293 /* TODO: check dumpdate from QFA file with current dump file's
295 /* if not equal either output warning and continue without QFA
297 /* read empty line */
298 if (fgets(gTps
, sizeof(gTps
), gTapeposfp
) == NULL
)
299 errx(1, "not requested format of -- %s", gTapeposfile
);
300 gTps
[strlen(gTps
) - 1] = 0;
301 /* read table header line */
302 if (fgets(gTps
, sizeof(gTps
), gTapeposfp
) == NULL
)
303 errx(1, "not requested format of -- %s", gTapeposfile
);
304 gTps
[strlen(gTps
) - 1] = 0;
305 /* end reading header info */
306 /* tape position table starts here */
307 gSeekstart
= ftell(gTapeposfp
); /* remember for later use */
313 * Compare contents of tape.
318 Vprintf(stdout
, "Begin compare restore\n");
319 compare_ignore_not_found
= 0;
322 printf("filesys = %s\n", filesys
);
323 if (stat(filesys
, &stbuf
) < 0)
324 err(1, "cannot stat directory %s", filesys
);
325 if (chdir(filesys
) < 0)
326 err(1, "cannot cd to %s", filesys
);
327 compare_ignore_not_found
= dumptime
> 0;
328 initsymtable((char *)0);
330 treescan(".", ROOTINO
, nodeupdates
);
333 if (compare_errors
) {
334 printf("Some files were modified!\n");
350 * Incremental restoration of a file system.
356 * This is an incremental dump tape.
358 Vprintf(stdout
, "Begin incremental restore\n");
359 initsymtable(symtbl
);
362 Vprintf(stdout
, "Calculate node updates.\n");
363 treescan(".", ROOTINO
, nodeupdates
);
368 * This is a level zero dump tape.
370 Vprintf(stdout
, "Begin level 0 restore\n");
371 initsymtable((char *)0);
373 Vprintf(stdout
, "Calculate extraction list.\n");
374 treescan(".", ROOTINO
, nodeupdates
);
376 createleaves(symtbl
);
381 Vprintf(stdout
, "Verify the directory structure\n");
382 treescan(".", ROOTINO
, verifyfile
);
384 dumpsymtable(symtbl
, (long)1);
387 * Resume an incremental file system restoration.
390 initsymtable(symtbl
);
393 createleaves(symtbl
);
397 dumpsymtable(symtbl
, (long)1);
400 /* handle file names from either text file (-X) or the command line */
401 #define NEXTFILE(p) \
407 else if (filelist) { \
408 if ((p = fgets(fname, MAXPATHLEN, filelist))) { \
409 if ( *p && *(p + strlen(p) - 1) == '\n' ) /* possible null string */ \
410 *(p + strlen(p) - 1) = '\0'; \
411 if ( !*p ) /* skip empty lines */ \
417 * List contents of tape.
422 initsymtable((char *)0);
427 canon(p
, name
, sizeof(name
));
428 ino
= dirlookup(name
);
431 treescan(name
, ino
, listfile
);
435 * Batch extraction of tape contents.
439 tistart
= time(NULL
);
443 initsymtable((char *)0);
448 canon(p
, name
, sizeof(name
));
449 ino
= dirlookup(name
);
454 treescan(name
, ino
, addfile
);
463 titaken
= tiend
- tistart
;
465 msg("restore took %d:%02d:%02d\n", titaken
/ 3600,
466 (titaken
% 3600) / 60, titaken
% 60);
473 return 0; /* gcc shut up */
480 const char *ext2ver
, *ext2date
;
482 ext2fs_get_library_version(&ext2ver
, &ext2date
);
483 (void)fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
484 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
486 (void)fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
496 #define qfaflag "[-Q file] "
501 (void)fprintf(stderr
,
502 "usage:\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n",
503 __progname
, " -C [-c" kerbflag
"Mvy] [-b blocksize] [-D filesystem] [-f file] [-s fileno]",
504 __progname
, " -i [-ch" kerbflag
"mMuvy] [-b blocksize] [-f file] " qfaflag
"[-s fileno]",
505 __progname
, " -r [-c" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno] [-T directory]",
506 __progname
, " -R [-c" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno] [-T directory]",
507 __progname
, " -t [-ch" kerbflag
"Muvy] [-b blocksize] [-f file] " qfaflag
"[-s fileno] [-X filelist] [file ...]",
508 __progname
, " -x [-ch" kerbflag
"mMuvy] [-b blocksize] [-f file] " qfaflag
"[-s fileno] [-X filelist] [file ...]");
514 * Change set of key letters and ordered arguments into something
515 * getopt(3) will like.
518 obsolete(int *argcp
, char **argvp
[])
521 char *ap
, **argv
, *flagsp
= NULL
, **nargv
, *p
= NULL
;
527 /* Return if no arguments or first argument has leading dash. */
529 if (argc
== 1 || *ap
== '-')
532 /* Allocate space for new arguments. */
533 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
534 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
535 err(1, "malloc args");
538 argv
+= 2, argc
-= 2;
540 for (flags
= 0; *ap
; ++ap
) {
550 warnx("option requires an argument -- %c", *ap
);
553 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
554 err(1, "malloc arg");
557 (void)strcpy(&nargv
[0][2], *argv
);
571 /* Terminate flags. */
577 /* Copy remaining arguments. */
578 while ((*nargv
++ = *argv
++));
580 /* Update argument count. */
581 *argcp
= nargv
- *argvp
- 1;
586 * reserve stdin for opt (avoid conflicts)
589 use_stdin(const char *opt
)
592 errx(1, "can't handle standard input for both %s and %s",