|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #ifndef lint
8: char copyright[] =
9: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
10: All rights reserved.\n";
11: #endif not lint
12:
13: #ifndef lint
14: static char sccsid[] = "@(#)main.c 5.4 (Berkeley) 5/13/88";
15: #endif not lint
16:
17: /*
18: * Modified to recursively extract all files within a subtree
19: * (supressed by the h option) and recreate the heirarchical
20: * structure of that subtree and move extracted files to their
21: * proper homes (supressed by the m option).
22: * Includes the s (skip files) option for use with multiple
23: * dumps on a single tape.
24: * 8/29/80 by Mike Litzkow
25: *
26: * Modified to work on the new file system and to recover from
27: * tape read errors.
28: * 1/19/82 by Kirk McKusick
29: *
30: * Full incremental restore running entirely in user code and
31: * interactive tape browser.
32: * 1/19/83 by Kirk McKusick
33: */
34:
35: #include "restore.h"
36: #include <protocols/dumprestore.h>
37: #include <signal.h>
38:
39: int bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
40: int hflag = 1, mflag = 1, Nflag = 0;
41: char command = '\0';
42: long dumpnum = 1;
43: long volno = 0;
44: long ntrec;
45: char *dumpmap;
46: char *clrimap;
47: ino_t maxino;
48: time_t dumptime;
49: time_t dumpdate;
50: FILE *terminal;
51:
52: main(argc, argv)
53: int argc;
54: char *argv[];
55: {
56: register char *cp;
57: ino_t ino;
58: char *inputdev = "/dev/rmt8";
59: char *symtbl = "./restoresymtable";
60: char name[MAXPATHLEN];
61: int (*signal())();
62: extern int onintr();
63:
64: if (signal(SIGINT, onintr) == SIG_IGN)
65: (void) signal(SIGINT, SIG_IGN);
66: if (signal(SIGTERM, onintr) == SIG_IGN)
67: (void) signal(SIGTERM, SIG_IGN);
68: setlinebuf(stderr);
69: if (argc < 2) {
70: usage:
71: fprintf(stderr, "Usage:\n%s%s%s%s%s",
72: "\trestore tfhsvy [file file ...]\n",
73: "\trestore xfhmsvy [file file ...]\n",
74: "\trestore ifhmsvy\n",
75: "\trestore rfsvy\n",
76: "\trestore Rfsvy\n");
77: done(1);
78: }
79: argv++;
80: argc -= 2;
81: command = '\0';
82: for (cp = *argv++; *cp; cp++) {
83: switch (*cp) {
84: case '-':
85: break;
86: case 'c':
87: cvtflag++;
88: break;
89: case 'd':
90: dflag++;
91: break;
92: case 'h':
93: hflag = 0;
94: break;
95: case 'm':
96: mflag = 0;
97: break;
98: case 'N':
99: Nflag++;
100: break;
101: case 'v':
102: vflag++;
103: break;
104: case 'y':
105: yflag++;
106: break;
107: case 'f':
108: if (argc < 1) {
109: fprintf(stderr, "missing device specifier\n");
110: done(1);
111: }
112: inputdev = *argv++;
113: argc--;
114: break;
115: case 'b':
116: /*
117: * change default tape blocksize
118: */
119: bflag++;
120: if (argc < 1) {
121: fprintf(stderr, "missing block size\n");
122: done(1);
123: }
124: ntrec = atoi(*argv++);
125: if (ntrec <= 0) {
126: fprintf(stderr, "Block size must be a positive integer\n");
127: done(1);
128: }
129: argc--;
130: break;
131: case 's':
132: /*
133: * dumpnum (skip to) for multifile dump tapes
134: */
135: if (argc < 1) {
136: fprintf(stderr, "missing dump number\n");
137: done(1);
138: }
139: dumpnum = atoi(*argv++);
140: if (dumpnum <= 0) {
141: fprintf(stderr, "Dump number must be a positive integer\n");
142: done(1);
143: }
144: argc--;
145: break;
146: case 't':
147: case 'R':
148: case 'r':
149: case 'x':
150: case 'i':
151: if (command != '\0') {
152: fprintf(stderr,
153: "%c and %c are mutually exclusive\n",
154: *cp, command);
155: goto usage;
156: }
157: command = *cp;
158: break;
159: default:
160: fprintf(stderr, "Bad key character %c\n", *cp);
161: goto usage;
162: }
163: }
164: if (command == '\0') {
165: fprintf(stderr, "must specify i, t, r, R, or x\n");
166: goto usage;
167: }
168: setinput(inputdev);
169: if (argc == 0) {
170: argc = 1;
171: *--argv = ".";
172: }
173: switch (command) {
174: /*
175: * Interactive mode.
176: */
177: case 'i':
178: setup();
179: extractdirs(1);
180: initsymtable((char *)0);
181: runcmdshell();
182: done(0);
183: /*
184: * Incremental restoration of a file system.
185: */
186: case 'r':
187: setup();
188: if (dumptime > 0) {
189: /*
190: * This is an incremental dump tape.
191: */
192: vprintf(stdout, "Begin incremental restore\n");
193: initsymtable(symtbl);
194: extractdirs(1);
195: removeoldleaves();
196: vprintf(stdout, "Calculate node updates.\n");
197: treescan(".", ROOTINO, nodeupdates);
198: findunreflinks();
199: removeoldnodes();
200: } else {
201: /*
202: * This is a level zero dump tape.
203: */
204: vprintf(stdout, "Begin level 0 restore\n");
205: initsymtable((char *)0);
206: extractdirs(1);
207: vprintf(stdout, "Calculate extraction list.\n");
208: treescan(".", ROOTINO, nodeupdates);
209: }
210: createleaves(symtbl);
211: createlinks();
212: setdirmodes();
213: checkrestore();
214: if (dflag) {
215: vprintf(stdout, "Verify the directory structure\n");
216: treescan(".", ROOTINO, verifyfile);
217: }
218: dumpsymtable(symtbl, (long)1);
219: done(0);
220: /*
221: * Resume an incremental file system restoration.
222: */
223: case 'R':
224: initsymtable(symtbl);
225: skipmaps();
226: skipdirs();
227: createleaves(symtbl);
228: createlinks();
229: setdirmodes();
230: checkrestore();
231: dumpsymtable(symtbl, (long)1);
232: done(0);
233: /*
234: * List contents of tape.
235: */
236: case 't':
237: setup();
238: extractdirs(0);
239: initsymtable((char *)0);
240: while (argc--) {
241: canon(*argv++, name);
242: ino = dirlookup(name);
243: if (ino == 0)
244: continue;
245: treescan(name, ino, listfile);
246: }
247: done(0);
248: /*
249: * Batch extraction of tape contents.
250: */
251: case 'x':
252: setup();
253: extractdirs(1);
254: initsymtable((char *)0);
255: while (argc--) {
256: canon(*argv++, name);
257: ino = dirlookup(name);
258: if (ino == 0)
259: continue;
260: if (mflag)
261: pathcheck(name);
262: treescan(name, ino, addfile);
263: }
264: createfiles();
265: createlinks();
266: setdirmodes();
267: if (dflag)
268: checkrestore();
269: done(0);
270: }
271: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.