]>
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.24 2001/04/27 15:22:47 stelian Exp $";
48 #include <compatlfs.h>
49 #include <sys/param.h>
56 #ifdef HAVE_EXT2FS_EXT2_FS_H
57 #include <ext2fs/ext2_fs.h>
59 #include <linux/ext2_fs.h>
61 #include <bsdcompat.h>
65 #include <ufs/ufs/dinode.h>
66 #endif /* __linux__ */
67 #include <protocols/dumprestore.h>
69 #include <compaterr.h>
75 #include <ext2fs/ext2fs.h>
79 #include "pathnames.h"
83 int bflag
= 0, cvtflag
= 0, dflag
= 0, vflag
= 0, yflag
= 0;
84 int hflag
= 1, mflag
= 1, Nflag
= 0, zflag
= 0;
98 int compare_ignore_not_found
;
100 char filesys
[NAMELEN
];
101 static const char *stdin_opt
= NULL
;
107 static void obsolete
__P((int *, char **[]));
108 static void usage
__P((void));
109 static void use_stdin
__P((const char *));
112 main(int argc
, char *argv
[])
116 char *inputdev
= _PATH_DEFTAPE
;
117 char *symtbl
= "./restoresymtable";
118 char *p
, name
[MAXPATHLEN
];
119 FILE *filelist
= NULL
;
120 char fname
[MAXPATHLEN
];
125 time_t tistart
, tiend
, titaken
;
128 /* Temp files should *not* be readable. We set permissions later. */
132 __progname
= argv
[0];
138 if ((inputdev
= getenv("TAPE")) == NULL
)
139 inputdev
= _PATH_DEFTAPE
;
140 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
142 if ((tmpdir
= strdup(tmpdir
)) == NULL
)
143 err(1, "malloc tmpdir");
144 for (p
= tmpdir
+ strlen(tmpdir
) - 1; p
>= tmpdir
&& *p
== '/'; p
--)
146 obsolete(&argc
, &argv
);
147 while ((ch
= getopt(argc
, argv
,
156 "Rrs:tT:uvxX:y")) != -1)
159 /* Change default tape blocksize. */
161 ntrec
= strtol(optarg
, &p
, 10);
163 errx(1, "illegal blocksize -- %s", optarg
);
165 errx(1, "block size must be greater than 0");
171 strncpy(filesys
, optarg
, NAMELEN
);
172 filesys
[NAMELEN
- 1] = '\0';
181 if( !strcmp(optarg
,"-") )
201 "%c and %c options are mutually exclusive",
216 gTapeposfile
= optarg
;
221 /* Dumpnum (skip to) for multifile dump tapes. */
222 dumpnum
= strtol(optarg
, &p
, 10);
224 errx(1, "illegal dump number -- %s", optarg
);
226 errx(1, "dump number must be greater than 0");
235 if( !strcmp(optarg
,"-") ) {
240 if ( !(filelist
= fopen(optarg
,"r")) )
241 errx(1, "can't open file for reading -- %s", optarg
);
253 errx(1, "none of C, i, R, r, t or x options specified");
256 if (!mflag
&& tapeposflag
)
257 errx(1, "m and Q options are mutually exclusive");
260 if (signal(SIGINT
, onintr
) == SIG_IGN
)
261 (void) signal(SIGINT
, SIG_IGN
);
262 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
263 (void) signal(SIGTERM
, SIG_IGN
);
270 if (argc
== 0 && !filelist
) {
277 msg("reading QFA positions from %s\n", gTapeposfile
);
278 if ((gTapeposfp
= fopen(gTapeposfile
, "r")) == NULL
)
279 errx(1, "can't open file for reading -- %s",
281 /* start reading header info */
282 if (fgets(gTps
, sizeof(gTps
), gTapeposfp
) == NULL
)
283 errx(1, "not requested format of -- %s", gTapeposfile
);
284 gTps
[strlen(gTps
) - 1] = 0; /* delete end of line */
285 if (strcmp(gTps
, QFA_MAGIC
) != 0)
286 errx(1, "not requested format of -- %s", gTapeposfile
);
287 if (fgets(gTps
, sizeof(gTps
), gTapeposfp
) == NULL
)
288 errx(1, "not requested format of -- %s", gTapeposfile
);
289 gTps
[strlen(gTps
) - 1] = 0;
290 if (strcmp(gTps
, QFA_VERSION
) != 0)
291 errx(1, "not requested format of -- %s", gTapeposfile
);
293 if (fgets(gTps
, sizeof(gTps
), gTapeposfp
) == NULL
)
294 errx(1, "not requested format of -- %s", gTapeposfile
);
295 gTps
[strlen(gTps
) - 1] = 0;
296 /* TODO: check dumpdate from QFA file with current dump file's
298 /* if not equal either output warning and continue without QFA
300 /* read empty line */
301 if (fgets(gTps
, sizeof(gTps
), gTapeposfp
) == NULL
)
302 errx(1, "not requested format of -- %s", gTapeposfile
);
303 gTps
[strlen(gTps
) - 1] = 0;
304 /* read table header line */
305 if (fgets(gTps
, sizeof(gTps
), gTapeposfp
) == NULL
)
306 errx(1, "not requested format of -- %s", gTapeposfile
);
307 gTps
[strlen(gTps
) - 1] = 0;
308 /* end reading header info */
309 /* tape position table starts here */
310 gSeekstart
= ftell(gTapeposfp
); /* remember for later use */
316 * Compare contents of tape.
321 Vprintf(stdout
, "Begin compare restore\n");
322 compare_ignore_not_found
= 0;
325 printf("filesys = %s\n", filesys
);
326 if (STAT(filesys
, &stbuf
) < 0)
327 err(1, "cannot stat directory %s", filesys
);
328 if (chdir(filesys
) < 0)
329 err(1, "cannot cd to %s", filesys
);
330 compare_ignore_not_found
= dumptime
> 0;
331 initsymtable((char *)0);
333 treescan(".", ROOTINO
, nodeupdates
);
336 if (compare_errors
) {
337 printf("Some files were modified!\n");
353 * Incremental restoration of a file system.
359 * This is an incremental dump tape.
361 Vprintf(stdout
, "Begin incremental restore\n");
362 initsymtable(symtbl
);
365 Vprintf(stdout
, "Calculate node updates.\n");
366 treescan(".", ROOTINO
, nodeupdates
);
371 * This is a level zero dump tape.
373 Vprintf(stdout
, "Begin level 0 restore\n");
374 initsymtable((char *)0);
376 Vprintf(stdout
, "Calculate extraction list.\n");
377 treescan(".", ROOTINO
, nodeupdates
);
379 createleaves(symtbl
);
384 Vprintf(stdout
, "Verify the directory structure\n");
385 treescan(".", ROOTINO
, verifyfile
);
387 dumpsymtable(symtbl
, (long)1);
390 * Resume an incremental file system restoration.
393 initsymtable(symtbl
);
396 createleaves(symtbl
);
400 dumpsymtable(symtbl
, (long)1);
403 /* handle file names from either text file (-X) or the command line */
404 #define NEXTFILE(p) \
410 else if (filelist) { \
411 if ((p = fgets(fname, MAXPATHLEN, filelist))) { \
412 if ( *p && *(p + strlen(p) - 1) == '\n' ) /* possible null string */ \
413 *(p + strlen(p) - 1) = '\0'; \
414 if ( !*p ) /* skip empty lines */ \
420 * List contents of tape.
425 initsymtable((char *)0);
430 canon(p
, name
, sizeof(name
));
431 ino
= dirlookup(name
);
434 treescan(name
, ino
, listfile
);
438 * Batch extraction of tape contents.
442 tistart
= time(NULL
);
446 initsymtable((char *)0);
451 canon(p
, name
, sizeof(name
));
452 ino
= dirlookup(name
);
457 treescan(name
, ino
, addfile
);
466 titaken
= tiend
- tistart
;
467 msg("restore took %d:%02d:%02d\n", titaken
/ 3600,
468 (titaken
% 3600) / 60, titaken
% 60);
469 #endif /* USE_QFADEBUG */
474 return 0; /* gcc shut up */
481 const char *ext2ver
, *ext2date
;
483 ext2fs_get_library_version(&ext2ver
, &ext2date
);
484 (void)fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
485 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
487 (void)fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
497 #define qfaflag "[-Q file] "
502 (void)fprintf(stderr
,
503 "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",
504 __progname
, " -C [-c" kerbflag
"Mvy] [-b blocksize] [-D filesystem] [-f file] [-s fileno]",
505 __progname
, " -i [-ch" kerbflag
"mMuvy] [-b blocksize] [-f file] " qfaflag
"[-s fileno]",
506 __progname
, " -r [-c" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno] [-T directory]",
507 __progname
, " -R [-c" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno] [-T directory]",
508 __progname
, " -t [-ch" kerbflag
"Muvy] [-b blocksize] [-f file] " qfaflag
"[-s fileno] [-X filelist] [file ...]",
509 __progname
, " -x [-ch" kerbflag
"mMuvy] [-b blocksize] [-f file] " qfaflag
"[-s fileno] [-X filelist] [file ...]");
515 * Change set of key letters and ordered arguments into something
516 * getopt(3) will like.
519 obsolete(int *argcp
, char **argvp
[])
522 char *ap
, **argv
, *flagsp
= NULL
, **nargv
, *p
= NULL
;
528 /* Return if no arguments or first argument has leading dash. */
530 if (argc
== 1 || *ap
== '-')
533 /* Allocate space for new arguments. */
534 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
535 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
536 err(1, "malloc args");
539 argv
+= 2, argc
-= 2;
541 for (flags
= 0; *ap
; ++ap
) {
551 warnx("option requires an argument -- %c", *ap
);
554 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
555 err(1, "malloc arg");
558 (void)strcpy(&nargv
[0][2], *argv
);
572 /* Terminate flags. */
578 /* Copy remaining arguments. */
579 while ((*nargv
++ = *argv
++));
581 /* Update argument count. */
582 *argcp
= nargv
- *argvp
- 1;
587 * reserve stdin for opt (avoid conflicts)
590 use_stdin(const char *opt
)
593 errx(1, "can't handle standard input for both %s and %s",