]>
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
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
41 * $Id: main.c,v 1.5 1999/10/11 13:31:13 stelian Exp $
44 #include <sys/param.h>
49 #include <linux/ext2_fs.h>
50 #include <bsdcompat.h>
54 #include <ufs/ufs/dinode.h>
55 #endif /* __linux__ */
56 #include <protocols/dumprestore.h>
58 #include <compaterr.h>
64 #include <ext2fs/ext2fs.h>
68 #include "pathnames.h"
72 int bflag
= 0, cvtflag
= 0, dflag
= 0, vflag
= 0, yflag
= 0;
73 int hflag
= 1, mflag
= 1, Nflag
= 0;
87 int compare_ignore_not_found
;
94 static void obsolete
__P((int *, char **[]));
95 static void usage
__P((void));
98 main(int argc
, char *argv
[])
102 char *inputdev
= _PATH_DEFTAPE
;
103 char *symtbl
= "./restoresymtable";
104 char *p
, name
[MAXPATHLEN
];
106 /* Temp files should *not* be readable. We set permissions later. */
110 __progname
= argv
[0];
116 if ((inputdev
= getenv("TAPE")) == NULL
)
117 inputdev
= _PATH_DEFTAPE
;
118 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
120 if ((tmpdir
= strdup(tmpdir
)) == NULL
)
121 err(1, "malloc tmpdir");
122 for (p
= tmpdir
+ strlen(tmpdir
) - 1; p
>= tmpdir
&& *p
== '/'; p
--)
124 obsolete(&argc
, &argv
);
126 #define optlist "b:CcdD:f:hikmNRrs:tT:uvxy"
128 #define optlist "b:CcdD:f:himNRrs:tT:uvxy"
130 while ((ch
= getopt(argc
, argv
, optlist
)) != -1)
133 /* Change default tape blocksize. */
135 ntrec
= strtol(optarg
, &p
, 10);
137 errx(1, "illegal blocksize -- %s", optarg
);
139 errx(1, "block size must be greater than 0");
172 "%c and %c options are mutually exclusive",
183 /* Dumpnum (skip to) for multifile dump tapes. */
184 dumpnum
= strtol(optarg
, &p
, 10);
186 errx(1, "illegal dump number -- %s", optarg
);
188 errx(1, "dump number must be greater than 0");
206 errx(1, "none of C, i, R, r, t or x options specified");
208 if (signal(SIGINT
, onintr
) == SIG_IGN
)
209 (void) signal(SIGINT
, SIG_IGN
);
210 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
211 (void) signal(SIGTERM
, SIG_IGN
);
225 * Compare contents of tape.
230 Vprintf(stdout
, "Begin compare restore\n");
231 compare_ignore_not_found
= 0;
233 printf("filesys = %s\n", filesys
);
234 if (stat(filesys
, &stbuf
) < 0)
235 err(1, "cannot stat directory %s", filesys
);
236 if (chdir(filesys
) < 0)
237 err(1, "cannot cd to %s", filesys
);
238 compare_ignore_not_found
= dumptime
> 0;
239 initsymtable((char *)0);
241 treescan(".", ROOTINO
, nodeupdates
);
257 * Incremental restoration of a file system.
263 * This is an incremental dump tape.
265 Vprintf(stdout
, "Begin incremental restore\n");
266 initsymtable(symtbl
);
269 Vprintf(stdout
, "Calculate node updates.\n");
270 treescan(".", ROOTINO
, nodeupdates
);
275 * This is a level zero dump tape.
277 Vprintf(stdout
, "Begin level 0 restore\n");
278 initsymtable((char *)0);
280 Vprintf(stdout
, "Calculate extraction list.\n");
281 treescan(".", ROOTINO
, nodeupdates
);
283 createleaves(symtbl
);
288 Vprintf(stdout
, "Verify the directory structure\n");
289 treescan(".", ROOTINO
, verifyfile
);
291 dumpsymtable(symtbl
, (long)1);
294 * Resume an incremental file system restoration.
297 initsymtable(symtbl
);
300 createleaves(symtbl
);
304 dumpsymtable(symtbl
, (long)1);
307 * List contents of tape.
312 initsymtable((char *)0);
314 canon(*argv
++, name
, sizeof(name
));
315 ino
= dirlookup(name
);
318 treescan(name
, ino
, listfile
);
322 * Batch extraction of tape contents.
327 initsymtable((char *)0);
329 canon(*argv
++, name
, sizeof(name
));
330 ino
= dirlookup(name
);
335 treescan(name
, ino
, addfile
);
346 return 0; /* gcc shut up */
357 (void)fprintf(stderr
, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
358 "restore -i [-ch" kerbflag
"muvy] [-b blocksize] [-f file] [-s fileno]",
359 "restore -r [-c" kerbflag
"uvy] [-b blocksize] [-f file] [-s fileno]",
360 "restore -R [-c" kerbflag
"uvy] [-b blocksize] [-f file] [-s fileno]",
361 "restore -x [-ch" kerbflag
"muvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
362 "restore -t [-ch" kerbflag
"kuvy] [-b blocksize] [-f file] [-s fileno] [file ...]");
368 * Change set of key letters and ordered arguments into something
369 * getopt(3) will like.
372 obsolete(int *argcp
, char **argvp
[])
375 char *ap
, **argv
, *flagsp
= NULL
, **nargv
, *p
= NULL
;
381 /* Return if no arguments or first argument has leading dash. */
383 if (argc
== 1 || *ap
== '-')
386 /* Allocate space for new arguments. */
387 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
388 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
389 err(1, "malloc args");
392 argv
+= 2, argc
-= 2;
394 for (flags
= 0; *ap
; ++ap
) {
400 warnx("option requires an argument -- %c", *ap
);
403 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
404 err(1, "malloc arg");
407 (void)strcpy(&nargv
[0][2], *argv
);
421 /* Terminate flags. */
427 /* Copy remaining arguments. */
428 while ((*nargv
++ = *argv
++));
430 /* Update argument count. */
431 *argcp
= nargv
- *argvp
- 1;