1 | /***************************************************************************
|
---|
2 | $Id: mondorestore.c 3374 2015-04-27 14:25:29Z bruno $
|
---|
3 | restores mondoarchive data
|
---|
4 | The main file for mondorestore.
|
---|
5 | ***************************************************************************/
|
---|
6 |
|
---|
7 | /**************************************************************************
|
---|
8 | * #include statements *
|
---|
9 | **************************************************************************/
|
---|
10 | #include <pthread.h>
|
---|
11 | #include "my-stuff.h"
|
---|
12 | #include "mr_mem.h"
|
---|
13 | #include "../common/mondostructures.h"
|
---|
14 | #include "../common/libmondo.h"
|
---|
15 | #include "mr-externs.h"
|
---|
16 | #include "mondorestore.h"
|
---|
17 | #include "mondo-rstr-compare-EXT.h"
|
---|
18 | #include "mondo-rstr-tools-EXT.h"
|
---|
19 | #include <utime.h>
|
---|
20 |
|
---|
21 | extern void wait_until_software_raids_are_prepped(char *, int);
|
---|
22 |
|
---|
23 | extern void twenty_seconds_til_yikes(void);
|
---|
24 |
|
---|
25 | /* We don't have a cleanup function yet */
|
---|
26 | void (*mr_cleanup)(void) = NULL;
|
---|
27 |
|
---|
28 | /* Reference to global bkpinfo */
|
---|
29 | struct s_bkpinfo *bkpinfo;
|
---|
30 |
|
---|
31 | char which_restore_mode(void);
|
---|
32 |
|
---|
33 | /* For use in other programs (ex. XMondo) */
|
---|
34 | #ifdef MONDORESTORE_MODULE
|
---|
35 | #define main __mondorestore_main
|
---|
36 | #define g_ISO_restore_mode __mondorestore_g_ISO_restore_mode
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | //static char cvsid[] = "$Id: mondorestore.c 3374 2015-04-27 14:25:29Z bruno $";
|
---|
40 |
|
---|
41 | /**************************************************************************
|
---|
42 | * Globals *
|
---|
43 | **************************************************************************/
|
---|
44 | /*
|
---|
45 | extern char *g_tmpfs_mountpt; // declared in libmondo-tools.c
|
---|
46 | */
|
---|
47 | extern bool g_text_mode;
|
---|
48 | extern FILE *g_fprep;
|
---|
49 | extern double g_kernel_version;
|
---|
50 | extern int g_partition_table_locked_up;
|
---|
51 | extern int g_noof_rows;
|
---|
52 |
|
---|
53 | extern int partition_everything(struct mountlist_itself *mountlist);
|
---|
54 | extern int handle_incoming_parameters(int argc, char *argv[]);
|
---|
55 | extern int mount_media();
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * @name Restore-Time Globals
|
---|
59 | * @ingroup globalGroup
|
---|
60 | * @{
|
---|
61 | */
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * If TRUE, then we're restoring from ISOs or an NFS server.
|
---|
65 | * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.)
|
---|
66 | */
|
---|
67 | bool g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */
|
---|
68 |
|
---|
69 | /* Whether we should fail immediately at first error */
|
---|
70 | bool g_fail_immediately = FALSE;
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * If TRUE, then we have had a successful "nuke" restore.
|
---|
74 | */
|
---|
75 | bool g_I_have_just_nuked = FALSE;
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
|
---|
79 | */
|
---|
80 | char *g_biggielist_txt;
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * The location of 'filelist.full', containing all files (<em>including biggiefiles</em>) on
|
---|
84 | * the current archive set.
|
---|
85 | */
|
---|
86 | char *g_filelist_full;
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * The location of a file containing a list of the devices that were archived
|
---|
90 | * as images, not as individual files.
|
---|
91 | */
|
---|
92 | char *g_filelist_imagedevs;
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * The location of a file containing a list of imagedevs to actually restore.
|
---|
96 | * @see g_filelist_imagedevs
|
---|
97 | */
|
---|
98 | char *g_imagedevs_restthese;
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * The location of 'mondorestore.cfg', containing the metadata
|
---|
102 | * information for this backup.
|
---|
103 | */
|
---|
104 | char *g_mondo_cfg_file;
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * The location of 'mountlist.txt', containing the information on the
|
---|
108 | * user's partitions and hard drives.
|
---|
109 | */
|
---|
110 | char *g_mountlist_fname;
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Mondo's home directory during backup. Unused in mondorestore; included
|
---|
114 | * to avoid link errors.
|
---|
115 | */
|
---|
116 | char *g_mondo_home;
|
---|
117 |
|
---|
118 | extern char *g_getfacl;
|
---|
119 | extern char *g_getfattr;
|
---|
120 |
|
---|
121 | /* @} - end of "Restore-Time Globals" in globalGroup */
|
---|
122 |
|
---|
123 |
|
---|
124 |
|
---|
125 | extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
|
---|
126 | char direction);
|
---|
127 |
|
---|
128 |
|
---|
129 | /**************************************************************************
|
---|
130 | * COMPAQ ProLiant Stuff: needs some special help *
|
---|
131 | **************************************************************************/
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * The message to display if we detect that the user is using a Compaq ProLiant.
|
---|
135 | */
|
---|
136 | #define COMPAQ_PROLIANTS_SUCK "Partition and format your disk using Compaq's disaster recovery CD. After you've done that, please reboot with your Mondo media in Interactive Mode."
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Determine whether @p mountlist contains a Compaq diagnostic partition.
|
---|
140 | * @param mountlist The mountlist to examine.
|
---|
141 | * @return TRUE if there's a Compaq diagnostic partition; FALSE if not.
|
---|
142 | * @ingroup restoreUtilityGroup
|
---|
143 | */
|
---|
144 | bool
|
---|
145 | partition_table_contains_Compaq_diagnostic_partition(struct mountlist_itself * mountlist) {
|
---|
146 |
|
---|
147 | int i;
|
---|
148 |
|
---|
149 | assert(mountlist != NULL);
|
---|
150 |
|
---|
151 | for (i = 0; i < mountlist->entries; i++) {
|
---|
152 | if (strstr(mountlist->el[i].format, "ompaq")) {
|
---|
153 | log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)", i, mountlist->el[i].device, mountlist->el[i].format);
|
---|
154 |
|
---|
155 | return (TRUE);
|
---|
156 | }
|
---|
157 | }
|
---|
158 | return (FALSE);
|
---|
159 | }
|
---|
160 |
|
---|
161 | /**************************************************************************
|
---|
162 | *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION *
|
---|
163 | **************************************************************************/
|
---|
164 |
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Allow the user to abort the backup if we find that there is a Compaq diagnostic partition.
|
---|
168 | * @note This function does not actually check for the presence of a Compaq partition.
|
---|
169 | * @ingroup restoreUtilityGroup
|
---|
170 | */
|
---|
171 | void offer_to_abort_because_Compaq_ProLiants_suck(void)
|
---|
172 | {
|
---|
173 | popup_and_OK(COMPAQ_PROLIANTS_SUCK);
|
---|
174 | if (ask_me_yes_or_no("Would you like to reboot and use your Compaq CD to prep your hard drive?"))
|
---|
175 | {
|
---|
176 | fatal_error("Aborting. Please reboot and prep your hard drive with your Compaq CD.");
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | /**************************************************************************
|
---|
181 | *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK *
|
---|
182 | **************************************************************************/
|
---|
183 |
|
---|
184 |
|
---|
185 | static void clean_blkid() {
|
---|
186 |
|
---|
187 | char *tmp1 = NULL;
|
---|
188 |
|
---|
189 | /* Clean up blkid cache file if they exist */
|
---|
190 | mr_asprintf(tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path);
|
---|
191 | (void)unlink(tmp1);
|
---|
192 | paranoid_free(tmp1);
|
---|
193 | mr_asprintf(tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path);
|
---|
194 | (void)unlink(tmp1);
|
---|
195 | paranoid_free(tmp1);
|
---|
196 | }
|
---|
197 |
|
---|
198 |
|
---|
199 | static void clean_multipathconf() {
|
---|
200 |
|
---|
201 | char *tmp1 = NULL;
|
---|
202 | char *editor = NULL;
|
---|
203 |
|
---|
204 | /* Clean up multiconf cache file if they exist */
|
---|
205 | mr_asprintf(tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path);
|
---|
206 | (void)unlink(tmp1);
|
---|
207 | paranoid_free(tmp1);
|
---|
208 |
|
---|
209 | /* Edit multipath.conf if needed to adapt wwid */
|
---|
210 | mr_asprintf(tmp1,"%s/etc/multipath.conf", MNT_RESTORING);
|
---|
211 | if (does_file_exist(tmp1)) {
|
---|
212 | log_msg(2, "We may need to clean /etc/multipath.conf");
|
---|
213 | } else {
|
---|
214 | paranoid_free(tmp1);
|
---|
215 | return;
|
---|
216 | }
|
---|
217 | paranoid_free(tmp1);
|
---|
218 |
|
---|
219 | if (bkpinfo->restore_mode != nuke) {
|
---|
220 | mr_asprintf(editor, "%s", find_my_editor());
|
---|
221 | mr_asprintf(tmp1,"chroot %s %s /etc/multipath.conf", MNT_RESTORING, editor);
|
---|
222 | popup_and_OK("You will now edit multipath.conf");
|
---|
223 | if (!g_text_mode) {
|
---|
224 | newtSuspend();
|
---|
225 | }
|
---|
226 | paranoid_system(tmp1);
|
---|
227 | if (!g_text_mode) {
|
---|
228 | newtResume();
|
---|
229 | }
|
---|
230 | paranoid_free(tmp1);
|
---|
231 | paranoid_free(editor);
|
---|
232 | } else {
|
---|
233 | log_to_screen("Non-interactive mode: no way to give you the keyboard so that you edit your multipath.conf. Hope it's OK");
|
---|
234 | log_msg(1,"Non-interactive mode: no way to give you the keyboard so that you edit your multipath.conf. Hope it's OK");
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Restore biggiefile @p bigfileno from the currently mounted CD.
|
---|
241 | * @param bkpinfo The backup information structure. Fields used:
|
---|
242 | * - @c bkpinfo->backup_media_type
|
---|
243 | * - @c bkpinfo->restore_path
|
---|
244 | * @param bigfileno The biggiefile number (starting from 0) to restore.
|
---|
245 | * @param filelist The node structure containing the list of files to restore.
|
---|
246 | * If the biggiefile is not in this list, it will be skipped (return value will
|
---|
247 | * still indicate success).
|
---|
248 | * @return 0 for success (or skip), nonzero for failure.
|
---|
249 | */
|
---|
250 | int restore_a_biggiefile_from_CD(long bigfileno,
|
---|
251 | struct s_node *filelist,
|
---|
252 | char *pathname_of_last_file_restored)
|
---|
253 | {
|
---|
254 | FILE *fin;
|
---|
255 | FILE *fout;
|
---|
256 | FILE *fbzip2;
|
---|
257 |
|
---|
258 | /** malloc ***/
|
---|
259 | char *checksum = NULL;
|
---|
260 | char *outfile_fname = NULL;
|
---|
261 | char *tmp = NULL;
|
---|
262 | char *bzip2_command = NULL;
|
---|
263 | char *suffix = NULL;
|
---|
264 | char *sz_devfile = NULL;
|
---|
265 | char *bigblk;
|
---|
266 | char *mds = NULL;
|
---|
267 | int retval = 0;
|
---|
268 | int finished = FALSE;
|
---|
269 | long sliceno;
|
---|
270 | long siz;
|
---|
271 | char *ntfsprog_fifo = NULL;
|
---|
272 | char *file_to_openout = NULL;
|
---|
273 | struct s_filename_and_lstat_info biggiestruct;
|
---|
274 | struct utimbuf the_utime_buf, *ubuf;
|
---|
275 | bool use_ntfsprog_hack = FALSE;
|
---|
276 | pid_t pid;
|
---|
277 | int res = 0;
|
---|
278 | int old_loglevel;
|
---|
279 | struct s_node *node;
|
---|
280 |
|
---|
281 | old_loglevel = g_loglevel;
|
---|
282 | ubuf = &the_utime_buf;
|
---|
283 | assert(bkpinfo != NULL);
|
---|
284 |
|
---|
285 | pathname_of_last_file_restored[0] = '\0';
|
---|
286 | if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
|
---|
287 | fatal_error("Cannot malloc bigblk");
|
---|
288 | }
|
---|
289 |
|
---|
290 | if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
|
---|
291 | log_to_screen("Cannot even open bigfile's info file");
|
---|
292 | return (1);
|
---|
293 | }
|
---|
294 |
|
---|
295 | memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
|
---|
296 | if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
|
---|
297 | sizeof(biggiestruct)) {
|
---|
298 | log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
|
---|
299 | bigfileno + 1);
|
---|
300 | }
|
---|
301 | paranoid_fclose(fin);
|
---|
302 |
|
---|
303 | mr_asprintf(checksum, "%s", biggiestruct.checksum);
|
---|
304 | if (!checksum[0]) {
|
---|
305 | log_msg(3, "Warning - bigfile %ld does not have a checksum", bigfileno + 1);
|
---|
306 | }
|
---|
307 | mr_free(checksum);
|
---|
308 |
|
---|
309 | if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :)
|
---|
310 | {
|
---|
311 | mr_asprintf(outfile_fname, "%s", biggiestruct.filename);
|
---|
312 | } else {
|
---|
313 | mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename);
|
---|
314 | }
|
---|
315 |
|
---|
316 | /* skip file if we have a selective restore subset & it doesn't match */
|
---|
317 | if (filelist != NULL) {
|
---|
318 | node = find_string_at_node(filelist, biggiestruct.filename);
|
---|
319 | if (!node) {
|
---|
320 | log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename);
|
---|
321 | pathname_of_last_file_restored[0] = '\0';
|
---|
322 | return (0);
|
---|
323 | } else if (!(node->selected)) {
|
---|
324 | log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);
|
---|
325 | pathname_of_last_file_restored[0] = '\0';
|
---|
326 | return (0);
|
---|
327 | }
|
---|
328 | }
|
---|
329 |
|
---|
330 | /* otherwise, continue */
|
---|
331 | log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
|
---|
332 | if (biggiestruct.use_ntfsprog) {
|
---|
333 | if (strncmp(biggiestruct.filename, "/dev/", 5)) {
|
---|
334 | log_msg(1, "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
|
---|
335 | log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
|
---|
336 | biggiestruct.use_ntfsprog = FALSE;
|
---|
337 | }
|
---|
338 | }
|
---|
339 |
|
---|
340 | if (biggiestruct.use_ntfsprog) // if it's an NTFS device
|
---|
341 | {
|
---|
342 | g_loglevel = 4;
|
---|
343 | use_ntfsprog_hack = TRUE;
|
---|
344 | log_msg(2, "Calling ntfsclone in background because %s is an NTFS /dev entry", outfile_fname);
|
---|
345 | mr_asprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), (int) (random() % 32768));
|
---|
346 | mkfifo(sz_devfile, 0x770);
|
---|
347 | mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
|
---|
348 | mr_free(sz_devfile);
|
---|
349 | file_to_openout = ntfsprog_fifo;
|
---|
350 | switch (pid = fork()) {
|
---|
351 | case -1:
|
---|
352 | fatal_error("Fork failure");
|
---|
353 | case 0:
|
---|
354 | log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", biggiestruct.filename, ntfsprog_fifo);
|
---|
355 | res = feed_outfrom_ntfsprog(biggiestruct.filename, ntfsprog_fifo);
|
---|
356 | mr_free(ntfsprog_fifo);
|
---|
357 | exit(res);
|
---|
358 | break;
|
---|
359 | default:
|
---|
360 | log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
|
---|
361 | }
|
---|
362 | mr_free(ntfsprog_fifo);
|
---|
363 | } else {
|
---|
364 | use_ntfsprog_hack = FALSE;
|
---|
365 | file_to_openout = outfile_fname;
|
---|
366 | if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
|
---|
367 | {
|
---|
368 | make_hole_for_file(outfile_fname);
|
---|
369 | }
|
---|
370 | }
|
---|
371 |
|
---|
372 | log_msg(2, "Reassembling big file %ld (%s)", bigfileno + 1, outfile_fname);
|
---|
373 |
|
---|
374 | /*
|
---|
375 | last slice is zero-length and uncompressed; when we find it, we stop.
|
---|
376 | We DON'T wait until there are no more slices; if we did that,
|
---|
377 | We might stop at end of CD, not at last slice (which is 0-len and uncompd)
|
---|
378 | */
|
---|
379 |
|
---|
380 | strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN - 1);
|
---|
381 | pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
|
---|
382 |
|
---|
383 | log_msg(3, "file_to_openout = %s", file_to_openout);
|
---|
384 | if (!(fout = fopen(file_to_openout, "w"))) {
|
---|
385 | log_to_screen("Cannot openout outfile_fname - hard disk full?");
|
---|
386 | return (1);
|
---|
387 | }
|
---|
388 | log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
|
---|
389 |
|
---|
390 | for (sliceno = 1, finished = FALSE; !finished;) {
|
---|
391 | if (!does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) &&
|
---|
392 | !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo")) &&
|
---|
393 | !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz")) &&
|
---|
394 | !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzma")) &&
|
---|
395 | !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
|
---|
396 | log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number);
|
---|
397 | g_current_media_number++;
|
---|
398 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
399 | log_msg(2, "Asking for %s #%d so that I may read slice #%ld\n", mds, g_current_media_number, sliceno);
|
---|
400 | mr_free(mds);
|
---|
401 |
|
---|
402 | log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
|
---|
403 |
|
---|
404 | insist_on_this_cd_number(g_current_media_number);
|
---|
405 | log_to_screen("Continuing to restore.");
|
---|
406 | } else {
|
---|
407 | mr_asprintf(tmp, "%s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
|
---|
408 | if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
|
---|
409 | log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno);
|
---|
410 | finished = TRUE;
|
---|
411 | mr_free(tmp);
|
---|
412 | continue;
|
---|
413 | } else {
|
---|
414 | if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
|
---|
415 | mr_asprintf(bzip2_command, "lzop");
|
---|
416 | mr_asprintf(suffix, "lzo");
|
---|
417 | } else
|
---|
418 | if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
|
---|
419 | mr_asprintf(bzip2_command, "gzip");
|
---|
420 | mr_asprintf(suffix, "gz");
|
---|
421 | } else
|
---|
422 | if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzma"))) {
|
---|
423 | mr_asprintf(bzip2_command, "lzma");
|
---|
424 | mr_asprintf(suffix, "lzma");
|
---|
425 | } else
|
---|
426 | if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
|
---|
427 | mr_asprintf(bzip2_command, "bzip2");
|
---|
428 | mr_asprintf(suffix, "bz2");
|
---|
429 | } else
|
---|
430 | if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))) {
|
---|
431 | mr_asprintf(bzip2_command, "");
|
---|
432 | mr_asprintf(suffix, "");
|
---|
433 | } else {
|
---|
434 | log_to_screen("OK, that's pretty fsck0red...");
|
---|
435 | mr_free(tmp);
|
---|
436 | return (1);
|
---|
437 | }
|
---|
438 | }
|
---|
439 | mr_free(tmp);
|
---|
440 | if (bzip2_command != NULL) {
|
---|
441 | mr_strcat(bzip2_command, " -dc %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
|
---|
442 | } else {
|
---|
443 | mr_asprintf(bzip2_command, "cat %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
|
---|
444 | }
|
---|
445 | mr_free(suffix);
|
---|
446 |
|
---|
447 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
448 | mr_asprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", mds, g_current_media_number, bigfileno + 1, sliceno);
|
---|
449 | mr_free(mds);
|
---|
450 | log_msg(2, tmp);
|
---|
451 |
|
---|
452 | if (!g_text_mode) {
|
---|
453 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
454 | newtRefresh();
|
---|
455 | strip_spaces(tmp);
|
---|
456 | update_progress_form(tmp);
|
---|
457 | }
|
---|
458 | mr_free(tmp);
|
---|
459 |
|
---|
460 | if (!(fbzip2 = popen(bzip2_command, "r"))) {
|
---|
461 | fatal_error("Can't run popen command");
|
---|
462 | }
|
---|
463 | mr_free(bzip2_command);
|
---|
464 |
|
---|
465 | while (!feof(fbzip2)) {
|
---|
466 | siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
|
---|
467 | if (siz > 0) {
|
---|
468 | siz = fwrite(bigblk, 1, siz, fout);
|
---|
469 | }
|
---|
470 | }
|
---|
471 | paranoid_pclose(fbzip2);
|
---|
472 |
|
---|
473 |
|
---|
474 | sliceno++;
|
---|
475 | g_current_progress++;
|
---|
476 | }
|
---|
477 | }
|
---|
478 | paranoid_fclose(fout);
|
---|
479 | g_loglevel = old_loglevel;
|
---|
480 |
|
---|
481 | if (use_ntfsprog_hack) {
|
---|
482 | log_msg(3, "Waiting for ntfsclone to finish");
|
---|
483 | mr_asprintf(tmp, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
|
---|
484 | while (system(tmp) == 0) {
|
---|
485 | sleep(1);
|
---|
486 | }
|
---|
487 | mr_free(tmp);
|
---|
488 | log_it("OK, ntfsclone has really finished");
|
---|
489 | }
|
---|
490 |
|
---|
491 | if (strcmp(outfile_fname, "/dev/null")) {
|
---|
492 | if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) {
|
---|
493 | // FIXME
|
---|
494 | }
|
---|
495 | chmod(outfile_fname, biggiestruct.properties.st_mode);
|
---|
496 | ubuf->actime = biggiestruct.properties.st_atime;
|
---|
497 | ubuf->modtime = biggiestruct.properties.st_mtime;
|
---|
498 | utime(outfile_fname, ubuf);
|
---|
499 | }
|
---|
500 | mr_free(outfile_fname);
|
---|
501 | paranoid_free(bigblk);
|
---|
502 |
|
---|
503 | return (retval);
|
---|
504 | }
|
---|
505 |
|
---|
506 | /**************************************************************************
|
---|
507 | *END_ RESTORE_A_BIGGIEFILE_FROM_CD *
|
---|
508 | **************************************************************************/
|
---|
509 |
|
---|
510 |
|
---|
511 | /**
|
---|
512 | * Restore all biggiefiles from all media in this CD backup.
|
---|
513 | * The CD with the last afioball should be currently mounted.
|
---|
514 | * @param bkpinfo The backup information structure. @c backup_media_type is the
|
---|
515 | * only field used in this function.
|
---|
516 | * @param filelist The node structure containing the list of files to be
|
---|
517 | * restored. If a prospective biggiefile is not in this list, it will be ignored.
|
---|
518 | * @return 0 for success, nonzero for failure.
|
---|
519 | */
|
---|
520 | int restore_all_biggiefiles_from_CD(struct s_node *filelist) {
|
---|
521 |
|
---|
522 | int retval = 0;
|
---|
523 | int res = 0;
|
---|
524 | long noof_biggiefiles, bigfileno = 0, total_slices;
|
---|
525 | /** malloc **/
|
---|
526 | char *tmp = NULL;
|
---|
527 | char *tmp1 = NULL;
|
---|
528 | char *mds = NULL;
|
---|
529 | bool just_changed_cds = FALSE;
|
---|
530 | char *xattr_fname = NULL;
|
---|
531 | char *acl_fname = NULL;
|
---|
532 | char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
|
---|
533 | char *pathname_of_last_biggie_restored;
|
---|
534 | FILE *fbw = NULL;
|
---|
535 |
|
---|
536 | malloc_string(pathname_of_last_biggie_restored);
|
---|
537 | malloc_string(tmp);
|
---|
538 | assert(bkpinfo != NULL);
|
---|
539 |
|
---|
540 | mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
|
---|
541 | if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
|
---|
542 | log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
|
---|
543 | }
|
---|
544 |
|
---|
545 | read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
|
---|
546 | total_slices = atol(tmp);
|
---|
547 | mr_free(tmp);
|
---|
548 |
|
---|
549 | mr_asprintf(tmp1, "Reassembling large files ");
|
---|
550 | mvaddstr_and_log_it(g_currentY, 0, tmp1);
|
---|
551 | mr_free(tmp1);
|
---|
552 |
|
---|
553 | if (length_of_file(BIGGIELIST) < 6) {
|
---|
554 | log_msg(1, "OK, no biggielist; not restoring biggiefiles");
|
---|
555 | return (0);
|
---|
556 | }
|
---|
557 | noof_biggiefiles = count_lines_in_file(BIGGIELIST);
|
---|
558 | if (noof_biggiefiles <= 0) {
|
---|
559 | log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles");
|
---|
560 | return (0);
|
---|
561 | }
|
---|
562 | log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
|
---|
563 |
|
---|
564 | open_progress_form("Reassembling large files",
|
---|
565 | "I am now reassembling all the large files.",
|
---|
566 | "Please wait. This may take some time.",
|
---|
567 | "", total_slices);
|
---|
568 | for (bigfileno = 0 ; bigfileno < noof_biggiefiles ;) {
|
---|
569 | log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
|
---|
570 | if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
|
---|
571 | log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
|
---|
572 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
573 | log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno + 1, mds, g_current_media_number);
|
---|
574 | log_msg(3, "Slicename would have been %s",
|
---|
575 | slice_fname(bigfileno, 0, ARCHIVES_PATH, ""));
|
---|
576 | // I'm not positive 'just_changed_cds' is even necessary...
|
---|
577 | if (just_changed_cds) {
|
---|
578 | just_changed_cds = FALSE;
|
---|
579 | log_msg(3, "I'll continue to scan this CD for bigfiles to be restored.");
|
---|
580 | } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
|
---|
581 | insist_on_this_cd_number(++g_current_media_number);
|
---|
582 | log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
|
---|
583 | just_changed_cds = TRUE;
|
---|
584 | } else {
|
---|
585 | /* That big file doesn't exist, but the followings may */
|
---|
586 | /* So we need to continue looping */
|
---|
587 | log_msg(2, "There was no bigfile #%ld. That's OK.", bigfileno + 1);
|
---|
588 | log_msg(2, "I'm going to stop restoring bigfiles now.");
|
---|
589 | retval++;
|
---|
590 | bigfileno++;
|
---|
591 | }
|
---|
592 | mr_free(mds);
|
---|
593 | } else {
|
---|
594 | just_changed_cds = FALSE;
|
---|
595 | mr_asprintf(tmp1, "Restoring big file %ld", bigfileno + 1);
|
---|
596 | update_progress_form(tmp1);
|
---|
597 | mr_free(tmp1);
|
---|
598 | res = restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored);
|
---|
599 | log_it("%s",pathname_of_last_biggie_restored);
|
---|
600 | if (fbw && pathname_of_last_biggie_restored[0]) {
|
---|
601 | fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
|
---|
602 | }
|
---|
603 | retval += res;
|
---|
604 | bigfileno++;
|
---|
605 |
|
---|
606 | }
|
---|
607 | }
|
---|
608 |
|
---|
609 | if (fbw) {
|
---|
610 | fclose(fbw);
|
---|
611 | if (g_getfattr) {
|
---|
612 | mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
|
---|
613 | if (length_of_file(xattr_fname) > 0) {
|
---|
614 | set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
|
---|
615 | }
|
---|
616 | mr_free(xattr_fname);
|
---|
617 | }
|
---|
618 | if (g_getfacl) {
|
---|
619 | mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
|
---|
620 | if (length_of_file(acl_fname) > 0) {
|
---|
621 | set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
|
---|
622 | }
|
---|
623 | mr_free(acl_fname);
|
---|
624 | }
|
---|
625 | }
|
---|
626 | mr_free(biggies_whose_EXATs_we_should_set);
|
---|
627 |
|
---|
628 | if (does_file_exist("/PAUSE")) {
|
---|
629 | popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
|
---|
630 | }
|
---|
631 | close_progress_form();
|
---|
632 | if (retval) {
|
---|
633 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
634 | } else {
|
---|
635 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
636 | }
|
---|
637 | paranoid_free(pathname_of_last_biggie_restored);
|
---|
638 | return (retval);
|
---|
639 | }
|
---|
640 |
|
---|
641 | /**************************************************************************
|
---|
642 | *END_RESTORE_ALL_BIGGIFILES_FROM_CD *
|
---|
643 | **************************************************************************/
|
---|
644 |
|
---|
645 |
|
---|
646 |
|
---|
647 | /**
|
---|
648 | * Restore @p tarball_fname from CD.
|
---|
649 | * @param tarball_fname The filename of the tarball to restore (in /mnt/cdrom).
|
---|
650 | * This will be used unmodified.
|
---|
651 | * @param current_tarball_number The number (starting from 0) of the fileset
|
---|
652 | * we're restoring now.
|
---|
653 | * @param filelist The node structure containing the list of files to be
|
---|
654 | * restored. If no file in the afioball is in this list, afio will still be
|
---|
655 | * called, but nothing will be written.
|
---|
656 | * @return 0 for success, nonzero for failure.
|
---|
657 | */
|
---|
658 | int
|
---|
659 | restore_a_tarball_from_CD(char *tarball_fname,
|
---|
660 | long current_tarball_number,
|
---|
661 | struct s_node *filelist)
|
---|
662 | {
|
---|
663 | int retval = 0;
|
---|
664 | int res;
|
---|
665 | char *p;
|
---|
666 |
|
---|
667 | /** malloc **/
|
---|
668 | char *command = NULL;
|
---|
669 | char *tmp = NULL;
|
---|
670 | char *filelist_name = NULL;
|
---|
671 | char *filelist_subset_fname = NULL;
|
---|
672 | char *executable = NULL;
|
---|
673 | char *temp_log = NULL;
|
---|
674 | long matches = 0;
|
---|
675 | bool use_star;
|
---|
676 | char *xattr_fname = NULL;
|
---|
677 | char *acl_fname = NULL;
|
---|
678 |
|
---|
679 | assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
|
---|
680 | assert(bkpinfo != NULL);
|
---|
681 |
|
---|
682 | log_msg(5, "Entering");
|
---|
683 | use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
|
---|
684 | mr_asprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
|
---|
685 | run_program_and_log_output(command, 9);
|
---|
686 | paranoid_free(command);
|
---|
687 |
|
---|
688 | mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", current_tarball_number);
|
---|
689 | if (length_of_file(filelist_name) <= 2) {
|
---|
690 | log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name);
|
---|
691 | log_msg(2, "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
|
---|
692 | log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");
|
---|
693 | retval = 0;
|
---|
694 | mr_free(filelist_name);
|
---|
695 | log_msg(5, "Leaving");
|
---|
696 | return(0);
|
---|
697 | }
|
---|
698 | if (count_lines_in_file(filelist_name) <= 0 || length_of_file(tarball_fname) <= 0) {
|
---|
699 | log_msg(3, "length_of_file(%s) = %llu", tarball_fname, length_of_file(tarball_fname));
|
---|
700 | log_msg(3, "count_lines_in_file(%s) = %llu", tarball_fname, count_lines_in_file(tarball_fname));
|
---|
701 | log_to_screen("Unable to restore fileset #%ld (CD I/O error)", current_tarball_number);
|
---|
702 | mr_free(filelist_name);
|
---|
703 | log_msg(5, "Leaving");
|
---|
704 | return(1);
|
---|
705 | }
|
---|
706 |
|
---|
707 | if (filelist) {
|
---|
708 | mr_asprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);
|
---|
709 | if ((matches =
|
---|
710 | save_filelist_entries_in_common(filelist_name, filelist,
|
---|
711 | filelist_subset_fname,
|
---|
712 | use_star)) <= 0) {
|
---|
713 | log_msg(1, "Skipping fileset %ld", current_tarball_number);
|
---|
714 | } else {
|
---|
715 | log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);
|
---|
716 | }
|
---|
717 | log_to_screen("Tarball #%ld --- %ld matches", current_tarball_number, matches);
|
---|
718 | }
|
---|
719 | mr_free(filelist_name);
|
---|
720 |
|
---|
721 | if (filelist == NULL || matches > 0) {
|
---|
722 | if (g_getfattr) {
|
---|
723 | mr_asprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
|
---|
724 | }
|
---|
725 | if (g_getfacl) {
|
---|
726 | mr_asprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
|
---|
727 | }
|
---|
728 | if (strstr(tarball_fname, ".bz2")) {
|
---|
729 | mr_asprintf(executable, "bzip2");
|
---|
730 | } else if (strstr(tarball_fname, ".lzma")) {
|
---|
731 | mr_asprintf(executable, "lzma");
|
---|
732 | } else if (strstr(tarball_fname, ".gz")) {
|
---|
733 | mr_asprintf(executable, "gzip");
|
---|
734 | } else if (strstr(tarball_fname, ".lzo")) {
|
---|
735 | mr_asprintf(executable, "lzop");
|
---|
736 | }
|
---|
737 | if (bkpinfo->compression_level == 0) {
|
---|
738 | mr_asprintf(executable, "%s", "");
|
---|
739 | } else {
|
---|
740 | if (executable) {
|
---|
741 | mr_asprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
|
---|
742 | res = run_program_and_log_output(tmp, FALSE);
|
---|
743 | mr_free(tmp);
|
---|
744 |
|
---|
745 | if (res) {
|
---|
746 | log_to_screen("(compare_a_tarball) Compression program %s not found - oh no!", executable);
|
---|
747 | paranoid_MR_finish(1);
|
---|
748 | }
|
---|
749 | tmp = executable;
|
---|
750 | mr_asprintf(executable, "-P %s -Z", tmp);
|
---|
751 | mr_free(tmp);
|
---|
752 | }
|
---|
753 | }
|
---|
754 | #ifdef __FreeBSD__
|
---|
755 | #define BUFSIZE 512
|
---|
756 | #else
|
---|
757 | #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
|
---|
758 | #endif
|
---|
759 |
|
---|
760 | if (use_star) {
|
---|
761 | mr_asprintf(command, "star -x -force-remove -sparse -U " STAR_ACL_SZ " file=%s", tarball_fname);
|
---|
762 | if (strstr(tarball_fname, ".bz2")) {
|
---|
763 | mr_strcat(command, " -bz");
|
---|
764 | }
|
---|
765 | } else {
|
---|
766 | if (! executable) {
|
---|
767 | log_msg(2, "No executable, this shouldn't happen !");
|
---|
768 | } else {
|
---|
769 | if (filelist_subset_fname != NULL) {
|
---|
770 | mr_asprintf(command, "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, filelist_subset_fname, tarball_fname);
|
---|
771 | } else {
|
---|
772 | mr_asprintf(command, "afio -i -b %ld -c %ld -M 8m %s %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, tarball_fname);
|
---|
773 | }
|
---|
774 | }
|
---|
775 | }
|
---|
776 | mr_free(executable);
|
---|
777 |
|
---|
778 | #undef BUFSIZE
|
---|
779 | mr_asprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), (int) (random() % 32768));
|
---|
780 |
|
---|
781 | mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
|
---|
782 | log_msg(1, "command = '%s'", command);
|
---|
783 | unlink(temp_log);
|
---|
784 | res = system(command);
|
---|
785 | if (res) {
|
---|
786 | p = strstr(command, "-acl ");
|
---|
787 | if (p) {
|
---|
788 | p[0] = p[1] = p[2] = p[3] = ' ';
|
---|
789 | log_msg(1, "new command = '%s'", command);
|
---|
790 | res = system(command);
|
---|
791 | }
|
---|
792 | }
|
---|
793 | paranoid_free(command);
|
---|
794 |
|
---|
795 | if (res && length_of_file(temp_log) < 5) {
|
---|
796 | res = 0;
|
---|
797 | }
|
---|
798 |
|
---|
799 | if (! use_star) {
|
---|
800 | if (g_getfattr) {
|
---|
801 | log_msg(1, "Setting fattr list %s", xattr_fname);
|
---|
802 | if (length_of_file(xattr_fname) > 0) {
|
---|
803 | res = set_fattr_list(filelist_subset_fname, xattr_fname);
|
---|
804 | if (res) {
|
---|
805 | log_to_screen("Errors occurred while setting extended attributes");
|
---|
806 | } else {
|
---|
807 | log_msg(1, "I set xattr OK");
|
---|
808 | }
|
---|
809 | retval += res;
|
---|
810 | }
|
---|
811 | }
|
---|
812 | if (g_getfacl) {
|
---|
813 | log_msg(1, "Setting acl list %s", acl_fname);
|
---|
814 | if (length_of_file(acl_fname) > 0) {
|
---|
815 | res = set_acl_list(filelist_subset_fname, acl_fname);
|
---|
816 | if (res) {
|
---|
817 | log_to_screen("Errors occurred while setting access control lists");
|
---|
818 | } else {
|
---|
819 | log_msg(1, "I set ACL OK");
|
---|
820 | }
|
---|
821 | retval += res;
|
---|
822 | }
|
---|
823 | }
|
---|
824 | } else {
|
---|
825 | retval = res;
|
---|
826 | }
|
---|
827 | // Be verbose for star
|
---|
828 | if (retval || use_star) {
|
---|
829 | mr_asprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
|
---|
830 | paranoid_system(command);
|
---|
831 | paranoid_free(command);
|
---|
832 |
|
---|
833 | if (retval) {
|
---|
834 | log_msg(2, "Errors occurred while processing fileset #%d", current_tarball_number);
|
---|
835 | }
|
---|
836 | } else {
|
---|
837 | log_msg(2, "Fileset #%d processed OK", current_tarball_number);
|
---|
838 | }
|
---|
839 | unlink(temp_log);
|
---|
840 | mr_free(temp_log);
|
---|
841 | }
|
---|
842 | if (does_file_exist("/PAUSE")) {
|
---|
843 | popup_and_OK
|
---|
844 | ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
|
---|
845 | }
|
---|
846 | unlink(filelist_subset_fname);
|
---|
847 | mr_free(filelist_subset_fname);
|
---|
848 | if (g_getfattr) {
|
---|
849 | unlink(xattr_fname);
|
---|
850 | mr_free(xattr_fname);
|
---|
851 | }
|
---|
852 | if (g_getfacl) {
|
---|
853 | unlink(acl_fname);
|
---|
854 | mr_free(acl_fname);
|
---|
855 | }
|
---|
856 |
|
---|
857 | log_msg(5, "Leaving");
|
---|
858 | return (retval);
|
---|
859 | }
|
---|
860 |
|
---|
861 | /**************************************************************************
|
---|
862 | *END_RESTORE_A_TARBALL_FROM_CD *
|
---|
863 | **************************************************************************/
|
---|
864 |
|
---|
865 |
|
---|
866 |
|
---|
867 | /**
|
---|
868 | * Restore all afioballs from all CDs in the backup.
|
---|
869 | * The first CD should be inserted (if not, it will be asked for).
|
---|
870 | * @param bkpinfo The backup information structure. @c backup_media_type is the
|
---|
871 | * only field used in @e this function.
|
---|
872 | * @param filelist The node structure containing the list of files to be
|
---|
873 | * restored. If no file in some particular afioball is in this list, afio will
|
---|
874 | * still be called for that fileset, but nothing will be written.
|
---|
875 | * @return 0 for success, or the number of filesets that failed.
|
---|
876 | */
|
---|
877 | int
|
---|
878 | restore_all_tarballs_from_CD(struct s_node *filelist)
|
---|
879 | {
|
---|
880 | int retval = 0;
|
---|
881 | int res;
|
---|
882 | int attempts;
|
---|
883 | long current_tarball_number = 0L;
|
---|
884 | long max_val;
|
---|
885 | /**malloc ***/
|
---|
886 | char *mds = NULL;
|
---|
887 | char *tmp = NULL;
|
---|
888 | char *tmp1 = NULL;
|
---|
889 | char *tarball_fname = NULL;
|
---|
890 | char *progress_str = NULL;
|
---|
891 |
|
---|
892 | assert(bkpinfo != NULL);
|
---|
893 |
|
---|
894 | malloc_string(tmp);
|
---|
895 | mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
|
---|
896 | log_msg(2, "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER");
|
---|
897 | if (g_current_media_number != 1) {
|
---|
898 | log_msg(3, "OK, that's jacked up.");
|
---|
899 | g_current_media_number = 1;
|
---|
900 | }
|
---|
901 | insist_on_this_cd_number(g_current_media_number);
|
---|
902 | read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
|
---|
903 | max_val = atol(tmp) + 1;
|
---|
904 | paranoid_free(tmp);
|
---|
905 |
|
---|
906 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
907 | mr_asprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);
|
---|
908 |
|
---|
909 | log_to_screen(progress_str);
|
---|
910 | open_progress_form("Restoring from archives",
|
---|
911 | "Restoring data from the archives.",
|
---|
912 | "Please wait. This may take some time.",
|
---|
913 | progress_str, max_val);
|
---|
914 | for (;;) {
|
---|
915 | insist_on_this_cd_number(g_current_media_number);
|
---|
916 | update_progress_form(progress_str);
|
---|
917 | mr_free(progress_str);
|
---|
918 |
|
---|
919 | mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", current_tarball_number);
|
---|
920 | if (!does_file_exist(tarball_fname)) {
|
---|
921 | mr_free(tarball_fname);
|
---|
922 | mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz", current_tarball_number);
|
---|
923 | }
|
---|
924 | if (!does_file_exist(tarball_fname)) {
|
---|
925 | mr_free(tarball_fname);
|
---|
926 | mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzma", current_tarball_number);
|
---|
927 | }
|
---|
928 | if (!does_file_exist(tarball_fname)) {
|
---|
929 | mr_free(tarball_fname);
|
---|
930 | mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", current_tarball_number);
|
---|
931 | }
|
---|
932 | if (!does_file_exist(tarball_fname)) {
|
---|
933 | mr_free(tarball_fname);
|
---|
934 | mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.", current_tarball_number);
|
---|
935 | }
|
---|
936 | if (!does_file_exist(tarball_fname)) {
|
---|
937 | mr_free(tarball_fname);
|
---|
938 | mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", current_tarball_number);
|
---|
939 | }
|
---|
940 | if (!does_file_exist(tarball_fname)) {
|
---|
941 | mr_free(tarball_fname);
|
---|
942 | mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", current_tarball_number);
|
---|
943 | }
|
---|
944 | if (!does_file_exist(tarball_fname)) {
|
---|
945 | if (current_tarball_number == 0) {
|
---|
946 | log_to_screen
|
---|
947 | ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
|
---|
948 | mr_free(tarball_fname);
|
---|
949 | return (0);
|
---|
950 | }
|
---|
951 | if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
|
---|
952 | || system("find " MNT_CDROM
|
---|
953 | "/archives/slice* > /dev/null 2> /dev/null") ==
|
---|
954 | 0) {
|
---|
955 | break;
|
---|
956 | }
|
---|
957 | g_current_media_number++;
|
---|
958 | mr_asprintf(progress_str, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
|
---|
959 | log_to_screen(progress_str);
|
---|
960 | } else {
|
---|
961 | mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_tarball_number, mds, g_current_media_number);
|
---|
962 | for (res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) {
|
---|
963 | res = restore_a_tarball_from_CD(tarball_fname, current_tarball_number, filelist);
|
---|
964 | }
|
---|
965 | mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ", mds, g_current_media_number, current_tarball_number);
|
---|
966 | if (res) {
|
---|
967 | mr_strcat(tmp1, "reported errors");
|
---|
968 | } else if (attempts > 1) {
|
---|
969 | mr_strcat(tmp1, "succeeded");
|
---|
970 | } else {
|
---|
971 | mr_strcat(tmp1, "succeeded");
|
---|
972 | }
|
---|
973 | if (attempts > 1) {
|
---|
974 | mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
|
---|
975 | }
|
---|
976 | if (attempts > 1) {
|
---|
977 | log_to_screen(tmp1);
|
---|
978 | }
|
---|
979 | mr_free(tmp1);
|
---|
980 |
|
---|
981 | retval += res;
|
---|
982 | current_tarball_number++;
|
---|
983 | g_current_progress++;
|
---|
984 | }
|
---|
985 | mr_free(tarball_fname);
|
---|
986 |
|
---|
987 | /* Now we need to umount the current media to have the next mounted by insist_on_this_cd_number */
|
---|
988 | /* run_program_and_log_output("umount " MNT_CDROM, FALSE); */
|
---|
989 | }
|
---|
990 | mr_free(mds);
|
---|
991 | mr_free(progress_str);
|
---|
992 |
|
---|
993 | close_progress_form();
|
---|
994 | if (retval) {
|
---|
995 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
996 | } else {
|
---|
997 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
998 | }
|
---|
999 |
|
---|
1000 | return (retval);
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | /**************************************************************************
|
---|
1004 | *END_RESTORE_ALL_TARBALLS_FROM_CD *
|
---|
1005 | **************************************************************************/
|
---|
1006 |
|
---|
1007 |
|
---|
1008 | /**
|
---|
1009 | * Restore a biggiefile from the currently opened stream.
|
---|
1010 | * @param bkpinfo The backup information structure. Fields used:
|
---|
1011 | * - @c bkpinfo->restore_path
|
---|
1012 | * - @c bkpinfo->zip_exe
|
---|
1013 | * @param orig_bf_fname The original filename of the biggiefile.
|
---|
1014 | * @param biggiefile_number The number of the biggiefile (starting from 0).
|
---|
1015 | * @param orig_checksum Unused.
|
---|
1016 | * @param biggiefile_size Unused.
|
---|
1017 | * @param filelist The node structure containing the list of files to be restored.
|
---|
1018 | * If @p orig_bf_fname is not in the list, it will be ignored.
|
---|
1019 | * @return 0 for success (or skip), nonzero for failure.
|
---|
1020 | * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL).
|
---|
1021 | */
|
---|
1022 | int restore_a_biggiefile_from_stream(char *orig_bf_fname, long biggiefile_number, char *orig_checksum, //UNUSED
|
---|
1023 | long long biggiefile_size, //UNUSED
|
---|
1024 | struct s_node *filelist,
|
---|
1025 | int use_ntfsprog,
|
---|
1026 | char *pathname_of_last_file_restored)
|
---|
1027 | {
|
---|
1028 | FILE *pout;
|
---|
1029 | FILE *fin;
|
---|
1030 |
|
---|
1031 | /** mallocs ********/
|
---|
1032 | char *tmp = NULL;
|
---|
1033 | char *tmp1 = NULL;
|
---|
1034 | char *command = NULL;
|
---|
1035 | char *outfile_fname = NULL;
|
---|
1036 | char *sz_devfile = NULL;
|
---|
1037 | char *ntfsprog_fifo = NULL;
|
---|
1038 | char *file_to_openout = NULL;
|
---|
1039 |
|
---|
1040 | struct s_node *node;
|
---|
1041 |
|
---|
1042 | int old_loglevel;
|
---|
1043 | long current_slice_number = 0;
|
---|
1044 | int retval = 0;
|
---|
1045 | int res = 0;
|
---|
1046 | int ctrl_chr = '\0';
|
---|
1047 | long long slice_siz;
|
---|
1048 | bool dummy_restore = FALSE;
|
---|
1049 | bool use_ntfsprog_hack = FALSE;
|
---|
1050 | pid_t pid;
|
---|
1051 | struct s_filename_and_lstat_info biggiestruct;
|
---|
1052 | struct utimbuf the_utime_buf, *ubuf;
|
---|
1053 | ubuf = &the_utime_buf;
|
---|
1054 |
|
---|
1055 | malloc_string(tmp);
|
---|
1056 | old_loglevel = g_loglevel;
|
---|
1057 | assert(bkpinfo != NULL);
|
---|
1058 | assert(orig_bf_fname != NULL);
|
---|
1059 | assert(orig_checksum != NULL);
|
---|
1060 |
|
---|
1061 | pathname_of_last_file_restored[0] = '\0';
|
---|
1062 | if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
|
---|
1063 | use_ntfsprog = 1;
|
---|
1064 | log_msg(1, "%s --- pih=YES", orig_bf_fname);
|
---|
1065 | } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
|
---|
1066 | use_ntfsprog = 0;
|
---|
1067 | log_msg(1, "%s --- pih=NO", orig_bf_fname);
|
---|
1068 | } else {
|
---|
1069 | use_ntfsprog = 0;
|
---|
1070 | log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | strncpy(pathname_of_last_file_restored, orig_bf_fname,
|
---|
1074 | MAX_STR_LEN - 1);
|
---|
1075 | pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
|
---|
1076 |
|
---|
1077 | /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
|
---|
1078 |
|
---|
1079 | if (filelist != NULL) {
|
---|
1080 | node = find_string_at_node(filelist, orig_bf_fname);
|
---|
1081 | if (!node) {
|
---|
1082 | dummy_restore = TRUE;
|
---|
1083 | log_msg(1,
|
---|
1084 | "Skipping big file %ld (%s) - not in biggielist subset",
|
---|
1085 | biggiefile_number + 1, orig_bf_fname);
|
---|
1086 | pathname_of_last_file_restored[0] = '\0';
|
---|
1087 | } else if (!(node->selected)) {
|
---|
1088 | dummy_restore = TRUE;
|
---|
1089 | log_msg(1, "Skipping %s (name isn't in biggielist subset)",
|
---|
1090 | orig_bf_fname);
|
---|
1091 | pathname_of_last_file_restored[0] = '\0';
|
---|
1092 | }
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | if (use_ntfsprog) {
|
---|
1096 | if (strncmp(orig_bf_fname, "/dev/", 5)) {
|
---|
1097 | log_msg(1,
|
---|
1098 | "I was in error when I set use_ntfsprog to TRUE.");
|
---|
1099 | log_msg(1, "%s isn't even in /dev", orig_bf_fname);
|
---|
1100 | use_ntfsprog = FALSE;
|
---|
1101 | }
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | if (use_ntfsprog) {
|
---|
1105 | g_loglevel = 4;
|
---|
1106 | mr_asprintf(outfile_fname, "%s", orig_bf_fname);
|
---|
1107 | use_ntfsprog_hack = TRUE;
|
---|
1108 | log_msg(2, "Calling ntfsclone in background because %s is a /dev entry", outfile_fname);
|
---|
1109 | mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
|
---|
1110 | mkfifo(sz_devfile, 0x770);
|
---|
1111 | mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
|
---|
1112 | mr_free(sz_devfile);
|
---|
1113 |
|
---|
1114 | file_to_openout = ntfsprog_fifo;
|
---|
1115 | switch (pid = fork()) {
|
---|
1116 | case -1:
|
---|
1117 | fatal_error("Fork failure");
|
---|
1118 | case 0:
|
---|
1119 | log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", outfile_fname, ntfsprog_fifo);
|
---|
1120 | res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
|
---|
1121 | mr_free(ntfsprog_fifo);
|
---|
1122 | exit(res);
|
---|
1123 | break;
|
---|
1124 | default:
|
---|
1125 | log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
|
---|
1126 | }
|
---|
1127 | mr_free(ntfsprog_fifo);
|
---|
1128 | } else {
|
---|
1129 | if (!strncmp(orig_bf_fname, "/dev/", 5)) {
|
---|
1130 | // non-NTFS partition
|
---|
1131 | mr_asprintf(outfile_fname, "%s", orig_bf_fname);
|
---|
1132 | } else {
|
---|
1133 | // biggiefile
|
---|
1134 | mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname);
|
---|
1135 | }
|
---|
1136 | use_ntfsprog_hack = FALSE;
|
---|
1137 | file_to_openout = outfile_fname;
|
---|
1138 | if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
|
---|
1139 | {
|
---|
1140 | make_hole_for_file(outfile_fname);
|
---|
1141 | }
|
---|
1142 | log_msg(2, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname);
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | if (dummy_restore) {
|
---|
1146 | mr_free(outfile_fname);
|
---|
1147 | mr_asprintf(outfile_fname, "/dev/null");
|
---|
1148 | }
|
---|
1149 |
|
---|
1150 | if (!bkpinfo->zip_exe[0]) {
|
---|
1151 | mr_asprintf(command, "cat > \"%s\"", file_to_openout);
|
---|
1152 | } else {
|
---|
1153 | mr_asprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE);
|
---|
1154 | if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
|
---|
1155 | /* Ignore SIGPIPE for gzip as it causes errors on big files
|
---|
1156 | * Cf: http://trac.mondorescue.org/ticket/244 */
|
---|
1157 | signal(SIGPIPE,SIG_IGN);
|
---|
1158 | }
|
---|
1159 | }
|
---|
1160 | log_msg(3, "Pipe command = '%s'", command);
|
---|
1161 |
|
---|
1162 | /* restore biggiefile, one slice at a time */
|
---|
1163 | if (!(pout = popen(command, "w"))) {
|
---|
1164 | fatal_error("Cannot pipe out");
|
---|
1165 | }
|
---|
1166 | mr_free(command);
|
---|
1167 |
|
---|
1168 | for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
|
---|
1169 | ctrl_chr != BLK_STOP_A_BIGGIE;
|
---|
1170 | res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
|
---|
1171 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
1172 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
1173 | }
|
---|
1174 | log_msg(2, "Working on file #%ld, slice #%ld ", biggiefile_number + 1, current_slice_number);
|
---|
1175 | if (!g_text_mode) {
|
---|
1176 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
1177 | newtRefresh();
|
---|
1178 | }
|
---|
1179 | strip_spaces(tmp);
|
---|
1180 | update_progress_form(tmp);
|
---|
1181 | if (current_slice_number == 0) {
|
---|
1182 | res =
|
---|
1183 | read_file_from_stream_to_file("/tmp/biggie-blah.txt",
|
---|
1184 | slice_siz);
|
---|
1185 | if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
|
---|
1186 | log_OS_error("blah blah");
|
---|
1187 | } else {
|
---|
1188 | if (fread
|
---|
1189 | ((void *) &biggiestruct, 1, sizeof(biggiestruct),
|
---|
1190 | fin) < sizeof(biggiestruct)) {
|
---|
1191 | log_msg(2,
|
---|
1192 | "Warning - unable to get biggiestruct of bigfile #%d",
|
---|
1193 | biggiefile_number + 1);
|
---|
1194 | }
|
---|
1195 | paranoid_fclose(fin);
|
---|
1196 | }
|
---|
1197 | } else {
|
---|
1198 | res =
|
---|
1199 | read_file_from_stream_to_stream(pout, slice_siz);
|
---|
1200 | }
|
---|
1201 | retval += res;
|
---|
1202 | res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
|
---|
1203 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
|
---|
1204 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
1205 | }
|
---|
1206 | current_slice_number++;
|
---|
1207 | g_current_progress++;
|
---|
1208 | }
|
---|
1209 | paranoid_pclose(pout);
|
---|
1210 |
|
---|
1211 | if (bkpinfo->zip_exe[0]) {
|
---|
1212 | if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
|
---|
1213 | /* Re-enable SIGPIPE for gzip */
|
---|
1214 | signal(SIGPIPE, terminate_daemon);
|
---|
1215 | }
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | log_msg(1, "pathname_of_last_file_restored is now %s",
|
---|
1219 | pathname_of_last_file_restored);
|
---|
1220 |
|
---|
1221 | if (use_ntfsprog_hack) {
|
---|
1222 | log_msg(3, "Waiting for ntfsclone to finish");
|
---|
1223 | mr_asprintf(tmp1, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
|
---|
1224 | while (system(tmp1) == 0) {
|
---|
1225 | sleep(1);
|
---|
1226 | }
|
---|
1227 | mr_free(tmp1);
|
---|
1228 | log_msg(3, "OK, ntfsclone has really finished");
|
---|
1229 | }
|
---|
1230 |
|
---|
1231 | log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
|
---|
1232 | log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
|
---|
1233 | if (strcmp(outfile_fname, "/dev/null")) {
|
---|
1234 | chmod(outfile_fname, biggiestruct.properties.st_mode);
|
---|
1235 | if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) {
|
---|
1236 | // FIXME
|
---|
1237 | }
|
---|
1238 | ubuf->actime = biggiestruct.properties.st_atime;
|
---|
1239 | ubuf->modtime = biggiestruct.properties.st_mtime;
|
---|
1240 | utime(outfile_fname, ubuf);
|
---|
1241 | }
|
---|
1242 | mr_free(outfile_fname);
|
---|
1243 |
|
---|
1244 | paranoid_free(tmp);
|
---|
1245 | g_loglevel = old_loglevel;
|
---|
1246 | return (retval);
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | /**************************************************************************
|
---|
1250 | *END_RESTORE_A_BIGGIEFILE_FROM_STREAM *
|
---|
1251 | **************************************************************************/
|
---|
1252 |
|
---|
1253 |
|
---|
1254 |
|
---|
1255 | /**
|
---|
1256 | * Restore all biggiefiles from the currently opened stream.
|
---|
1257 | * @param bkpinfo The backup information structure. Passed to other functions.
|
---|
1258 | * @param filelist The node structure containing the list of files to be
|
---|
1259 | * restored. If a prospective biggiefile is not in the list, it will be ignored.
|
---|
1260 | * @return 0 for success, or the number of biggiefiles that failed.
|
---|
1261 | */
|
---|
1262 | int
|
---|
1263 | restore_all_biggiefiles_from_stream(struct s_node *filelist)
|
---|
1264 | {
|
---|
1265 | long noof_biggiefiles;
|
---|
1266 | long current_bigfile_number = 0;
|
---|
1267 | long total_slices;
|
---|
1268 |
|
---|
1269 | int retval = 0;
|
---|
1270 | int res = 0;
|
---|
1271 | int ctrl_chr;
|
---|
1272 |
|
---|
1273 | /** malloc add ****/
|
---|
1274 | char *tmp = NULL;
|
---|
1275 | char *tmp1 = NULL;
|
---|
1276 | char *biggie_fname;
|
---|
1277 | char *biggie_cksum;
|
---|
1278 | char *xattr_fname = NULL;
|
---|
1279 | char *acl_fname = NULL;
|
---|
1280 | char *p;
|
---|
1281 | char *pathname_of_last_biggie_restored;
|
---|
1282 | char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
|
---|
1283 | long long biggie_size;
|
---|
1284 | FILE *fbw = NULL;
|
---|
1285 |
|
---|
1286 | malloc_string(tmp);
|
---|
1287 | malloc_string(biggie_fname);
|
---|
1288 | malloc_string(biggie_cksum);
|
---|
1289 | malloc_string(pathname_of_last_biggie_restored);
|
---|
1290 | assert(bkpinfo != NULL);
|
---|
1291 |
|
---|
1292 | read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
|
---|
1293 |
|
---|
1294 | total_slices = atol(tmp);
|
---|
1295 |
|
---|
1296 | if (g_getfattr) {
|
---|
1297 | mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
1298 | }
|
---|
1299 | if (g_getfacl) {
|
---|
1300 | mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
1301 | }
|
---|
1302 | mr_asprintf(tmp1, "Reassembling large files ");
|
---|
1303 | mvaddstr_and_log_it(g_currentY, 0, tmp1);
|
---|
1304 | mr_free(tmp1);
|
---|
1305 |
|
---|
1306 | mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
|
---|
1307 | if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
|
---|
1308 | log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
|
---|
1309 | }
|
---|
1310 |
|
---|
1311 | // get xattr and acl files if they're there
|
---|
1312 | res = read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr);
|
---|
1313 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
|
---|
1314 | res = read_EXAT_files_from_tape(&biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname);
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | noof_biggiefiles = atol(biggie_fname);
|
---|
1318 | log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
|
---|
1319 | open_progress_form("Reassembling large files",
|
---|
1320 | "I am now reassembling all the large files.",
|
---|
1321 | "Please wait. This may take some time.",
|
---|
1322 | "", total_slices);
|
---|
1323 |
|
---|
1324 | for (res =
|
---|
1325 | read_header_block_from_stream(&biggie_size, biggie_fname,
|
---|
1326 | &ctrl_chr);
|
---|
1327 | ctrl_chr != BLK_STOP_BIGGIEFILES;
|
---|
1328 | res =
|
---|
1329 | read_header_block_from_stream(&biggie_size, biggie_fname,
|
---|
1330 | &ctrl_chr)) {
|
---|
1331 | if (ctrl_chr != BLK_START_A_NORMBIGGIE
|
---|
1332 | && ctrl_chr != BLK_START_A_PIHBIGGIE) {
|
---|
1333 | wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
|
---|
1334 | }
|
---|
1335 | p = strrchr(biggie_fname, '/');
|
---|
1336 | if (!p) {
|
---|
1337 | p = biggie_fname;
|
---|
1338 | } else {
|
---|
1339 | p++;
|
---|
1340 | }
|
---|
1341 | mr_asprintf(tmp1, "Restoring big file %ld (%lld K)", current_bigfile_number + 1, biggie_size / 1024);
|
---|
1342 | update_progress_form(tmp1);
|
---|
1343 | mr_free(tmp1);
|
---|
1344 | res = restore_a_biggiefile_from_stream(biggie_fname,
|
---|
1345 | current_bigfile_number,
|
---|
1346 | biggie_cksum,
|
---|
1347 | biggie_size,
|
---|
1348 | filelist, ctrl_chr,
|
---|
1349 | pathname_of_last_biggie_restored);
|
---|
1350 | log_msg(1, "I believe I have restored %s",
|
---|
1351 | pathname_of_last_biggie_restored);
|
---|
1352 | if (fbw && pathname_of_last_biggie_restored[0]) {
|
---|
1353 | fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
|
---|
1354 | }
|
---|
1355 | retval += res;
|
---|
1356 | current_bigfile_number++;
|
---|
1357 |
|
---|
1358 | }
|
---|
1359 | if (current_bigfile_number != noof_biggiefiles
|
---|
1360 | && noof_biggiefiles != 0) {
|
---|
1361 | log_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", current_bigfile_number, noof_biggiefiles);
|
---|
1362 | } else {
|
---|
1363 | log_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", noof_biggiefiles, current_bigfile_number);
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | if (fbw) {
|
---|
1367 | fclose(fbw);
|
---|
1368 | if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
|
---|
1369 | log_it("Setting biggie-EXATs");
|
---|
1370 | if (g_getfattr) {
|
---|
1371 | if (length_of_file(xattr_fname) > 0) {
|
---|
1372 | log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname);
|
---|
1373 | set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
|
---|
1374 | }
|
---|
1375 | }
|
---|
1376 | if (g_getfacl) {
|
---|
1377 | if (length_of_file(acl_fname) > 0) {
|
---|
1378 | log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname);
|
---|
1379 | set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
|
---|
1380 | }
|
---|
1381 | }
|
---|
1382 | } else {
|
---|
1383 | log_it("No biggiefiles selected. So, no biggie-EXATs to set.");
|
---|
1384 | }
|
---|
1385 | }
|
---|
1386 | mr_free(xattr_fname);
|
---|
1387 | mr_free(acl_fname);
|
---|
1388 | mr_free(biggies_whose_EXATs_we_should_set);
|
---|
1389 |
|
---|
1390 | if (does_file_exist("/PAUSE")) {
|
---|
1391 | popup_and_OK
|
---|
1392 | ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
|
---|
1393 | }
|
---|
1394 |
|
---|
1395 | close_progress_form();
|
---|
1396 | if (retval) {
|
---|
1397 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
1398 | } else {
|
---|
1399 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
1400 | }
|
---|
1401 | paranoid_free(pathname_of_last_biggie_restored);
|
---|
1402 | paranoid_free(biggie_fname);
|
---|
1403 | paranoid_free(biggie_cksum);
|
---|
1404 | paranoid_free(tmp);
|
---|
1405 | return (retval);
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | /**************************************************************************
|
---|
1409 | *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM *
|
---|
1410 | **************************************************************************/
|
---|
1411 |
|
---|
1412 |
|
---|
1413 |
|
---|
1414 |
|
---|
1415 | /**
|
---|
1416 | * Restore a tarball from the currently opened stream.
|
---|
1417 | * @param bkpinfo The backup information structure. Fields used:
|
---|
1418 | * - @c bkpinfo->backup_media_type
|
---|
1419 | * - @c bkpinfo->media_device
|
---|
1420 | * - @c bkpinfo->zip_exe
|
---|
1421 | * @param tarball_fname The filename of the afioball to restore.
|
---|
1422 | * @param current_tarball_number The number (starting from 0) of the fileset
|
---|
1423 | * we're restoring now.
|
---|
1424 | * @param filelist The node structure containing the list of files to be
|
---|
1425 | * restored. If no file in the afioball is in this list, afio will still be
|
---|
1426 | * called, but nothing will be written.
|
---|
1427 | * @param size The size (in @b bytes) of the afioball.
|
---|
1428 | * @return 0 for success, nonzero for failure.
|
---|
1429 | */
|
---|
1430 | int
|
---|
1431 | restore_a_tarball_from_stream(char *tarball_fname,
|
---|
1432 | long current_tarball_number,
|
---|
1433 | struct s_node *filelist,
|
---|
1434 | long long size, char *xattr_fname,
|
---|
1435 | char *acl_fname)
|
---|
1436 | {
|
---|
1437 | int retval = 0;
|
---|
1438 | int res = 0;
|
---|
1439 |
|
---|
1440 | /** malloc add ***/
|
---|
1441 | char *mds = NULL;
|
---|
1442 | char *command = NULL;
|
---|
1443 | char *afio_fname = NULL;
|
---|
1444 | char *filelist_fname = NULL;
|
---|
1445 | char *filelist_subset_fname = NULL;
|
---|
1446 | char *executable = NULL;
|
---|
1447 | long matches = 0;
|
---|
1448 | bool restore_this_fileset = FALSE;
|
---|
1449 | bool use_star;
|
---|
1450 |
|
---|
1451 | assert(bkpinfo != NULL);
|
---|
1452 | assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
|
---|
1453 |
|
---|
1454 | /* to do it with a file... */
|
---|
1455 | use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
|
---|
1456 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
---|
1457 | log_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d",
|
---|
1458 | current_tarball_number, (long) size >> 10, mds, g_current_media_number);
|
---|
1459 | mr_free(mds);
|
---|
1460 |
|
---|
1461 | run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
|
---|
1462 |
|
---|
1463 | /****************************************************************************
|
---|
1464 | * Use RAMDISK's /tmp; saves time; oh wait, it's too small *
|
---|
1465 | * Well, pipe from tape to afio, then; oh wait, can't do that either: bug *
|
---|
1466 | * in afio or someting; oh darn.. OK, use tmpfs :-) *
|
---|
1467 | ****************************************************************************/
|
---|
1468 | mr_asprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number);
|
---|
1469 | mr_asprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number);
|
---|
1470 | mr_asprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number);
|
---|
1471 |
|
---|
1472 | res = read_file_from_stream_to_file(afio_fname, size);
|
---|
1473 | if (strstr(tarball_fname, ".star")) {
|
---|
1474 | bkpinfo->use_star = TRUE;
|
---|
1475 | }
|
---|
1476 | if (res) {
|
---|
1477 | log_msg(1, "Warning - error reading afioball from tape");
|
---|
1478 | }
|
---|
1479 | if (bkpinfo->compression_level == 0) {
|
---|
1480 | mr_asprintf(executable, "%s", "");
|
---|
1481 | } else {
|
---|
1482 | if (bkpinfo->use_star) {
|
---|
1483 | mr_asprintf(executable, "%s", " -bz");
|
---|
1484 | } else {
|
---|
1485 | mr_asprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
|
---|
1486 | }
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | if (!filelist) // if unconditional restore then restore entire fileset
|
---|
1490 | {
|
---|
1491 | restore_this_fileset = TRUE;
|
---|
1492 | } else // If restoring selectively then get TOC from tarball
|
---|
1493 | {
|
---|
1494 | if (strstr(tarball_fname, ".star.")) {
|
---|
1495 | use_star = TRUE;
|
---|
1496 | mr_asprintf(command, "star -sparse -t file=%s %s", afio_fname, executable);
|
---|
1497 | } else {
|
---|
1498 | use_star = FALSE;
|
---|
1499 | mr_asprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, executable, afio_fname);
|
---|
1500 | }
|
---|
1501 | mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
|
---|
1502 | log_msg(1, "command = %s", command);
|
---|
1503 | if (system(command)) {
|
---|
1504 | log_msg(4, "Warning - error occurred while retrieving TOC");
|
---|
1505 | }
|
---|
1506 | mr_free(command);
|
---|
1507 |
|
---|
1508 | if ((matches =
|
---|
1509 | save_filelist_entries_in_common(filelist_fname, filelist,
|
---|
1510 | filelist_subset_fname,
|
---|
1511 | use_star))
|
---|
1512 | <= 0 || length_of_file(filelist_subset_fname) < 2) {
|
---|
1513 | if (length_of_file(filelist_subset_fname) < 2) {
|
---|
1514 | log_msg(1, "No matches found in fileset %ld",
|
---|
1515 | current_tarball_number);
|
---|
1516 | }
|
---|
1517 | log_msg(2, "Skipping fileset %ld", current_tarball_number);
|
---|
1518 | restore_this_fileset = FALSE;
|
---|
1519 | } else {
|
---|
1520 | log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
|
---|
1521 | matches, current_tarball_number,
|
---|
1522 | filelist_subset_fname);
|
---|
1523 | restore_this_fileset = TRUE;
|
---|
1524 | }
|
---|
1525 | }
|
---|
1526 |
|
---|
1527 | // Concoct the call to star/afio to restore files
|
---|
1528 | if (strstr(tarball_fname, ".star.")) {
|
---|
1529 | // star
|
---|
1530 | mr_asprintf(command, "star -sparse -x file=%s %s", afio_fname, executable);
|
---|
1531 | if (filelist) {
|
---|
1532 | mr_strcat(command, " list=%s", filelist_subset_fname);
|
---|
1533 | }
|
---|
1534 | } else {
|
---|
1535 | // afio
|
---|
1536 | mr_asprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable);
|
---|
1537 | if (filelist) {
|
---|
1538 | mr_strcat(command, " -w %s", filelist_subset_fname);
|
---|
1539 | }
|
---|
1540 | mr_strcat(command, " %s", afio_fname);
|
---|
1541 | }
|
---|
1542 | mr_strcat(command, " 2>> %s", MONDO_LOGFILE);
|
---|
1543 | mr_free(executable);
|
---|
1544 |
|
---|
1545 | // Call if IF there are files to restore (selectively/unconditionally)
|
---|
1546 | if (restore_this_fileset) {
|
---|
1547 | log_msg(1, "Calling command='%s'", command);
|
---|
1548 | paranoid_system(command);
|
---|
1549 |
|
---|
1550 | if (g_getfattr) {
|
---|
1551 | log_it("Restoring xattr stuff");
|
---|
1552 | res = set_fattr_list(filelist_subset_fname, xattr_fname);
|
---|
1553 | if (res) {
|
---|
1554 | log_msg(1, "Errors occurred while setting xattr");
|
---|
1555 | } else {
|
---|
1556 | log_msg(1, "I set xattr OK");
|
---|
1557 | }
|
---|
1558 | retval += res;
|
---|
1559 | }
|
---|
1560 |
|
---|
1561 | if (g_getfacl) {
|
---|
1562 | log_it("Restoring acl stuff");
|
---|
1563 | res = set_acl_list(filelist_subset_fname, acl_fname);
|
---|
1564 | if (res) {
|
---|
1565 | log_msg(1, "Errors occurred while setting ACL");
|
---|
1566 | } else {
|
---|
1567 | log_msg(1, "I set ACL OK");
|
---|
1568 | }
|
---|
1569 | retval += res;
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | } else {
|
---|
1573 | log_msg(1, "NOT CALLING '%s'", command);
|
---|
1574 | }
|
---|
1575 | mr_free(command);
|
---|
1576 |
|
---|
1577 | if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
|
---|
1578 | log_to_screen("Paused after set %ld", current_tarball_number);
|
---|
1579 | popup_and_OK("Pausing. Press ENTER to continue.");
|
---|
1580 | }
|
---|
1581 |
|
---|
1582 | unlink(filelist_subset_fname);
|
---|
1583 | mr_free(filelist_subset_fname);
|
---|
1584 | unlink(filelist_fname);
|
---|
1585 | mr_free(filelist_fname);
|
---|
1586 | unlink(afio_fname);
|
---|
1587 | mr_free(afio_fname);
|
---|
1588 |
|
---|
1589 | return (retval);
|
---|
1590 | }
|
---|
1591 |
|
---|
1592 | /**************************************************************************
|
---|
1593 | *END_RESTORE_A_TARBALL_FROM_STREAM *
|
---|
1594 | **************************************************************************/
|
---|
1595 |
|
---|
1596 |
|
---|
1597 |
|
---|
1598 |
|
---|
1599 |
|
---|
1600 | /**
|
---|
1601 | * Restore all afioballs from the currently opened tape stream.
|
---|
1602 | * @param bkpinfo The backup information structure. Fields used:
|
---|
1603 | * - @c bkpinfo->backup_media_type
|
---|
1604 | * - @c bkpinfo->restore_path
|
---|
1605 | * @param filelist The node structure containing the list of files to be
|
---|
1606 | * restored. If no file in an afioball is in this list, afio will still be
|
---|
1607 | * called for that fileset, but nothing will be written.
|
---|
1608 | * @return 0 for success, or the number of filesets that failed.
|
---|
1609 | */
|
---|
1610 | int restore_all_tarballs_from_stream(struct s_node *filelist)
|
---|
1611 | {
|
---|
1612 | int retval = 0;
|
---|
1613 | int res;
|
---|
1614 | long current_afioball_number = 0;
|
---|
1615 | int ctrl_chr;
|
---|
1616 | long max_val /*, total_noof_files */ ;
|
---|
1617 |
|
---|
1618 | /** malloc **/
|
---|
1619 | char *tmp = NULL;
|
---|
1620 | char *mds = NULL;
|
---|
1621 | char *progress_str = NULL;
|
---|
1622 | char *tmp_fname;
|
---|
1623 | char *xattr_fname = NULL;
|
---|
1624 | char *acl_fname = NULL;
|
---|
1625 |
|
---|
1626 | long long tmp_size;
|
---|
1627 |
|
---|
1628 | malloc_string(tmp);
|
---|
1629 | malloc_string(tmp_fname);
|
---|
1630 | assert(bkpinfo != NULL);
|
---|
1631 | mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
|
---|
1632 | read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
|
---|
1633 | max_val = atol(tmp) + 1;
|
---|
1634 |
|
---|
1635 | if (chdir(bkpinfo->restore_path)) { /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
|
---|
1636 | //FIXME
|
---|
1637 | }
|
---|
1638 |
|
---|
1639 | run_program_and_log_output("pwd", 5);
|
---|
1640 |
|
---|
1641 | mr_asprintf(progress_str, "Restoring from media #%d", g_current_media_number);
|
---|
1642 | log_to_screen(progress_str);
|
---|
1643 | open_progress_form("Restoring from archives",
|
---|
1644 | "Restoring data from the archives.",
|
---|
1645 | "Please wait. This may take some time.",
|
---|
1646 | progress_str, max_val);
|
---|
1647 |
|
---|
1648 | log_msg(3, "hey");
|
---|
1649 |
|
---|
1650 | res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
|
---|
1651 | if (res) {
|
---|
1652 | log_msg(2, "Warning - error reading afioball from tape");
|
---|
1653 | }
|
---|
1654 | retval += res;
|
---|
1655 | if (ctrl_chr != BLK_START_AFIOBALLS) {
|
---|
1656 | wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
|
---|
1657 | }
|
---|
1658 | log_msg(2, "ho");
|
---|
1659 | res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
|
---|
1660 | while (ctrl_chr != BLK_STOP_AFIOBALLS) {
|
---|
1661 | update_progress_form(progress_str);
|
---|
1662 | if (g_getfattr) {
|
---|
1663 | mr_asprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
|
---|
1664 | unlink(xattr_fname);
|
---|
1665 | }
|
---|
1666 | if (g_getfacl) {
|
---|
1667 | mr_asprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
|
---|
1668 | unlink(acl_fname);
|
---|
1669 | }
|
---|
1670 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
|
---|
1671 | log_it("Reading EXAT files from tape");
|
---|
1672 | res = read_EXAT_files_from_tape(&tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname);
|
---|
1673 | }
|
---|
1674 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
1675 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
1676 | }
|
---|
1677 | log_msg(4, "Restoring from fileset #%ld (name=%s, size=%ld K)", current_afioball_number, tmp_fname, (long) tmp_size >> 10);
|
---|
1678 | res = restore_a_tarball_from_stream(tmp_fname, current_afioball_number, filelist, tmp_size, xattr_fname, acl_fname);
|
---|
1679 | retval += res;
|
---|
1680 | if (res) {
|
---|
1681 | log_to_screen("Fileset %ld - errors occurred", current_afioball_number);
|
---|
1682 | }
|
---|
1683 | res =
|
---|
1684 | read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
|
---|
1685 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
|
---|
1686 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
1687 | }
|
---|
1688 |
|
---|
1689 | current_afioball_number++;
|
---|
1690 | g_current_progress++;
|
---|
1691 | mds = media_descriptor_string(bkpinfo->backup_media_type),
|
---|
1692 |
|
---|
1693 | mr_free(progress_str);
|
---|
1694 | mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_afioball_number, mds, g_current_media_number);
|
---|
1695 | mr_free(mds);
|
---|
1696 | res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
|
---|
1697 | if (g_getfattr) {
|
---|
1698 | unlink(xattr_fname);
|
---|
1699 | }
|
---|
1700 | if (g_getfacl) {
|
---|
1701 | unlink(acl_fname);
|
---|
1702 | }
|
---|
1703 | } // next
|
---|
1704 | mr_free(progress_str);
|
---|
1705 | if (g_getfattr) {
|
---|
1706 | mr_free(xattr_fname);
|
---|
1707 | }
|
---|
1708 | if (g_getfacl) {
|
---|
1709 | mr_free(acl_fname);
|
---|
1710 | }
|
---|
1711 |
|
---|
1712 | log_msg(1, "All done with afioballs");
|
---|
1713 | close_progress_form();
|
---|
1714 | if (retval) {
|
---|
1715 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
1716 | } else {
|
---|
1717 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
1718 | }
|
---|
1719 | paranoid_free(tmp);
|
---|
1720 | paranoid_free(tmp_fname);
|
---|
1721 | return (retval);
|
---|
1722 | }
|
---|
1723 |
|
---|
1724 | /**************************************************************************
|
---|
1725 | *END_ RESTORE_ALL_TARBALLS_FROM_STREAM *
|
---|
1726 | **************************************************************************/
|
---|
1727 |
|
---|
1728 | /* @} - end of LLrestoreGroup */
|
---|
1729 |
|
---|
1730 |
|
---|
1731 | /**
|
---|
1732 | * Restore all files in @p filelist.
|
---|
1733 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
1734 | * @param filelist The node structure containing the list of files to be
|
---|
1735 | * restored.
|
---|
1736 | * @return 0 for success, or the number of afioballs and biggiefiles that failed.
|
---|
1737 | * @ingroup restoreGroup
|
---|
1738 | */
|
---|
1739 | int restore_everything(struct s_node *filelist)
|
---|
1740 | {
|
---|
1741 | int resA;
|
---|
1742 | int resB;
|
---|
1743 |
|
---|
1744 | /** mallco ***/
|
---|
1745 | char *cwd;
|
---|
1746 | char *newpath;
|
---|
1747 | char *tmp = NULL;
|
---|
1748 | assert(bkpinfo != NULL);
|
---|
1749 |
|
---|
1750 | malloc_string(cwd);
|
---|
1751 | malloc_string(newpath);
|
---|
1752 | log_msg(2, "restore_everything() --- starting");
|
---|
1753 | g_current_media_number = 1;
|
---|
1754 | if (getcwd(cwd, MAX_STR_LEN - 1)) {
|
---|
1755 | // FIXME
|
---|
1756 | }
|
---|
1757 | mr_asprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
|
---|
1758 | run_program_and_log_output(tmp, FALSE);
|
---|
1759 | mr_free(tmp);
|
---|
1760 |
|
---|
1761 | log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
|
---|
1762 | if (chdir(bkpinfo->restore_path)) {
|
---|
1763 | //FIXME
|
---|
1764 | }
|
---|
1765 | if (getcwd(newpath, MAX_STR_LEN - 1)) {
|
---|
1766 | // FIXME
|
---|
1767 | }
|
---|
1768 | log_msg(1, "path is now %s", newpath);
|
---|
1769 | log_msg(1, "restoring everything");
|
---|
1770 | if (!find_home_of_exe("petris") && !g_text_mode) {
|
---|
1771 | newtDrawRootText(0, g_noof_rows - 2,
|
---|
1772 | "Press ALT-<left cursor> twice to play Petris :-) ");
|
---|
1773 | newtRefresh();
|
---|
1774 | }
|
---|
1775 | mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
|
---|
1776 | mount_media();
|
---|
1777 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
1778 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
1779 | "Restoring OS and data from streaming media");
|
---|
1780 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
1781 | openin_cdstream();
|
---|
1782 | } else {
|
---|
1783 | assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
|
---|
1784 | openin_tape();
|
---|
1785 | }
|
---|
1786 | resA = restore_all_tarballs_from_stream(filelist);
|
---|
1787 | resB = restore_all_biggiefiles_from_stream(filelist);
|
---|
1788 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
1789 | closein_cdstream();
|
---|
1790 | } else {
|
---|
1791 | closein_tape();
|
---|
1792 | }
|
---|
1793 | } else {
|
---|
1794 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
1795 | "Restoring OS and data from CD/USB ");
|
---|
1796 | resA = restore_all_tarballs_from_CD(filelist);
|
---|
1797 | resB = restore_all_biggiefiles_from_CD(filelist);
|
---|
1798 | }
|
---|
1799 | if (chdir(cwd)) {
|
---|
1800 | //FIXME
|
---|
1801 | }
|
---|
1802 | if (resA + resB) {
|
---|
1803 | log_to_screen("Errors occurred while data was being restored.");
|
---|
1804 | }
|
---|
1805 | if (length_of_file("/etc/raidtab") > 0) {
|
---|
1806 | log_msg(2, "Copying local raidtab to restored filesystem");
|
---|
1807 | run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
|
---|
1808 | "/etc/raidtab", FALSE);
|
---|
1809 | }
|
---|
1810 | kill_petris();
|
---|
1811 | log_msg(2, "restore_everything() --- leaving");
|
---|
1812 | paranoid_free(cwd);
|
---|
1813 | paranoid_free(newpath);
|
---|
1814 | return (resA + resB);
|
---|
1815 | }
|
---|
1816 |
|
---|
1817 | /**************************************************************************
|
---|
1818 | *END_RESTORE_EVERYTHING *
|
---|
1819 | **************************************************************************/
|
---|
1820 |
|
---|
1821 |
|
---|
1822 | /**
|
---|
1823 | * @addtogroup restoreGroup
|
---|
1824 | * @{
|
---|
1825 | */
|
---|
1826 | /**
|
---|
1827 | * Restore the user's data, in a disaster recovery situation, prompting the
|
---|
1828 | * user about whether or not to do every step.
|
---|
1829 | * The user can edit the mountlist, choose files to restore, etc.
|
---|
1830 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
1831 | * @param mountlist The mountlist containing information about the user's partitions.
|
---|
1832 | * @param raidlist The raidlist to go with @p mountlist.
|
---|
1833 | * @return 0 for success, or the number of errors encountered.
|
---|
1834 | */
|
---|
1835 | int interactive_mode(struct mountlist_itself *mountlist, struct raidlist_itself *raidlist)
|
---|
1836 | {
|
---|
1837 | int retval = 0;
|
---|
1838 | int res;
|
---|
1839 | int ptn_errs = 0;
|
---|
1840 | int fmt_errs = 0;
|
---|
1841 |
|
---|
1842 | bool done;
|
---|
1843 | bool restore_all;
|
---|
1844 |
|
---|
1845 | /** needs malloc **********/
|
---|
1846 | char *tmp;
|
---|
1847 | char *tmp1 = NULL;
|
---|
1848 | char *fstab_fname = NULL;
|
---|
1849 | char *old_restpath = NULL;
|
---|
1850 |
|
---|
1851 | struct s_node *filelist;
|
---|
1852 |
|
---|
1853 | /* try to partition and format */
|
---|
1854 |
|
---|
1855 | log_msg(2, "interactive_mode --- starting (great, assertions OK)");
|
---|
1856 |
|
---|
1857 | malloc_string(tmp);
|
---|
1858 | assert(bkpinfo != NULL);
|
---|
1859 | assert(mountlist != NULL);
|
---|
1860 | assert(raidlist != NULL);
|
---|
1861 |
|
---|
1862 | log_msg(2, "interactive_mode --- assertions OK");
|
---|
1863 |
|
---|
1864 | if (g_text_mode) {
|
---|
1865 | if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?")) {
|
---|
1866 | fatal_error("Wise move.");
|
---|
1867 | }
|
---|
1868 | }
|
---|
1869 |
|
---|
1870 | log_it("About to load config file");
|
---|
1871 | get_cfg_file_from_archive_or_bust();
|
---|
1872 | read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
|
---|
1873 | log_it("Done loading config file; resizing ML");
|
---|
1874 |
|
---|
1875 | mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat "CMDLINE));
|
---|
1876 | if (strstr(tmp1, "noresize")) {
|
---|
1877 | log_msg(1, "Not resizing mountlist.");
|
---|
1878 | } else {
|
---|
1879 | resize_mountlist_proportionately_to_suit_new_drives(mountlist);
|
---|
1880 | }
|
---|
1881 | mr_free(tmp1);
|
---|
1882 |
|
---|
1883 | for (done = FALSE; !done;) {
|
---|
1884 | log_it("About to edit mountlist");
|
---|
1885 | if (g_text_mode) {
|
---|
1886 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
1887 | mr_asprintf(tmp1, "%s %s", find_my_editor(), g_mountlist_fname);
|
---|
1888 | res = system(tmp1);
|
---|
1889 | mr_free(tmp1);
|
---|
1890 | load_mountlist(mountlist, g_mountlist_fname);
|
---|
1891 | } else {
|
---|
1892 | res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
|
---|
1893 | }
|
---|
1894 | log_it("Finished editing mountlist");
|
---|
1895 | if (res) {
|
---|
1896 | paranoid_MR_finish(1);
|
---|
1897 | }
|
---|
1898 | log_msg(2, "Proceeding...");
|
---|
1899 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
1900 | save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
|
---|
1901 | mvaddstr_and_log_it(1, 30, "Restoring Interactively");
|
---|
1902 | if (bkpinfo->differential) {
|
---|
1903 | log_to_screen("Because this is a differential backup, disk");
|
---|
1904 | log_to_screen
|
---|
1905 | (" partitioning and formatting will not take place.");
|
---|
1906 | done = TRUE;
|
---|
1907 | } else {
|
---|
1908 | if (ask_me_yes_or_no
|
---|
1909 | ("Do you want to erase and partition your hard drives?")) {
|
---|
1910 | if (partition_table_contains_Compaq_diagnostic_partition
|
---|
1911 | (mountlist)) {
|
---|
1912 | offer_to_abort_because_Compaq_ProLiants_suck();
|
---|
1913 | done = TRUE;
|
---|
1914 | } else {
|
---|
1915 | twenty_seconds_til_yikes();
|
---|
1916 | g_fprep = fopen("/tmp/prep.sh", "w");
|
---|
1917 | ptn_errs = partition_everything(mountlist);
|
---|
1918 | if (ptn_errs) {
|
---|
1919 | log_to_screen
|
---|
1920 | ("Warning. Errors occurred during disk partitioning.");
|
---|
1921 | }
|
---|
1922 |
|
---|
1923 | fmt_errs = format_everything(mountlist, FALSE, raidlist);
|
---|
1924 | if (!fmt_errs) {
|
---|
1925 | log_to_screen
|
---|
1926 | ("Errors during disk partitioning were handled OK.");
|
---|
1927 | log_to_screen
|
---|
1928 | ("Partitions were formatted OK despite those errors.");
|
---|
1929 | ptn_errs = 0;
|
---|
1930 | }
|
---|
1931 | if (!ptn_errs && !fmt_errs) {
|
---|
1932 | done = TRUE;
|
---|
1933 | }
|
---|
1934 | }
|
---|
1935 | paranoid_fclose(g_fprep);
|
---|
1936 | } else {
|
---|
1937 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
1938 | "User opted not to partition the devices");
|
---|
1939 | if (ask_me_yes_or_no
|
---|
1940 | ("Do you want to format your hard drives?")) {
|
---|
1941 | fmt_errs = format_everything(mountlist, TRUE, raidlist);
|
---|
1942 | if (!fmt_errs) {
|
---|
1943 | done = TRUE;
|
---|
1944 | }
|
---|
1945 | } else {
|
---|
1946 | ptn_errs = fmt_errs = 0;
|
---|
1947 | done = TRUE;
|
---|
1948 | }
|
---|
1949 | }
|
---|
1950 | if (fmt_errs) {
|
---|
1951 | mvaddstr_and_log_it(g_currentY++,
|
---|
1952 | 0,
|
---|
1953 | "Errors occurred. Please repartition and format drives manually.");
|
---|
1954 | done = FALSE;
|
---|
1955 | }
|
---|
1956 | if (ptn_errs & !fmt_errs) {
|
---|
1957 | mvaddstr_and_log_it(g_currentY++,
|
---|
1958 | 0,
|
---|
1959 | "Errors occurred during partitioning. Formatting, however, went OK.");
|
---|
1960 | done = TRUE;
|
---|
1961 | }
|
---|
1962 | if (!done) {
|
---|
1963 | if (!ask_me_yes_or_no("Re-edit the mountlist?")) {
|
---|
1964 | retval++;
|
---|
1965 | goto end_of_func;
|
---|
1966 | }
|
---|
1967 | }
|
---|
1968 | }
|
---|
1969 | }
|
---|
1970 |
|
---|
1971 | /* mount */
|
---|
1972 | if (mount_all_devices(mountlist, TRUE)) {
|
---|
1973 | unmount_all_devices(mountlist);
|
---|
1974 | retval++;
|
---|
1975 | goto end_of_func;
|
---|
1976 | }
|
---|
1977 | /* restore */
|
---|
1978 | if ((restore_all = ask_me_yes_or_no("Do you want me to restore all of your data?"))) {
|
---|
1979 | log_msg(1, "Restoring all data");
|
---|
1980 | retval += restore_everything(NULL);
|
---|
1981 | } else if ((restore_all = ask_me_yes_or_no("Do you want me to restore _some_ of your data?"))) {
|
---|
1982 | mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
|
---|
1983 | for (done = FALSE; !done;) {
|
---|
1984 | unlink("/tmp/filelist.full");
|
---|
1985 | filelist = process_filelist_and_biggielist();
|
---|
1986 | /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
|
---|
1987 | the former is a list of regular files; the latter, biggiefiles and imagedevs.
|
---|
1988 | */
|
---|
1989 | if (filelist) {
|
---|
1990 | gotos_suck:
|
---|
1991 | strcpy(tmp, old_restpath);
|
---|
1992 | // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
|
---|
1993 | if (popup_and_get_string("Restore path", "Restore files to where?", tmp, MAX_STR_LEN / 4)) {
|
---|
1994 | if (!strcmp(tmp, "/")) {
|
---|
1995 | if (!ask_me_yes_or_no("Are you sure?")) {
|
---|
1996 | goto gotos_suck;
|
---|
1997 | }
|
---|
1998 | tmp[0] = '\0'; // so we restore to [blank]/file/name :)
|
---|
1999 | }
|
---|
2000 | strcpy(bkpinfo->restore_path, tmp);
|
---|
2001 | log_msg(1, "Restoring subset");
|
---|
2002 | retval += restore_everything(filelist);
|
---|
2003 | free_filelist(filelist);
|
---|
2004 | } else {
|
---|
2005 | strcpy(bkpinfo->restore_path, old_restpath);
|
---|
2006 | free_filelist(filelist);
|
---|
2007 | }
|
---|
2008 | if (!ask_me_yes_or_no("Restore another subset of your backup?")) {
|
---|
2009 | done = TRUE;
|
---|
2010 | }
|
---|
2011 | } else {
|
---|
2012 | done = TRUE;
|
---|
2013 | }
|
---|
2014 | }
|
---|
2015 | mr_free(old_restpath);
|
---|
2016 | } else {
|
---|
2017 | mvaddstr_and_log_it(g_currentY++, 0, "User opted not to restore any data. ");
|
---|
2018 | }
|
---|
2019 | if (retval) {
|
---|
2020 | mvaddstr_and_log_it(g_currentY++, 0, "Errors occurred during the restore phase. ");
|
---|
2021 | }
|
---|
2022 |
|
---|
2023 | clean_multipathconf();
|
---|
2024 | if (ask_me_yes_or_no("Initialize the boot loader?")) {
|
---|
2025 | run_boot_loader(TRUE);
|
---|
2026 | } else {
|
---|
2027 | mvaddstr_and_log_it(g_currentY++,
|
---|
2028 | 0,
|
---|
2029 | "User opted not to initialize the boot loader.");
|
---|
2030 | }
|
---|
2031 |
|
---|
2032 | clean_blkid();
|
---|
2033 | protect_against_braindead_sysadmins();
|
---|
2034 | retval += unmount_all_devices(mountlist);
|
---|
2035 |
|
---|
2036 | /* if (restore_some || restore_all || */
|
---|
2037 | if (ask_me_yes_or_no
|
---|
2038 | ("Label/Identify your ext2/ext3/ext4 partitions if necessary?")) {
|
---|
2039 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
2040 | "Using tune2fs/tune4fs to identify your ext2,3,4 partitions");
|
---|
2041 | if (does_file_exist("/tmp/fstab.new")) {
|
---|
2042 | mr_asprintf(fstab_fname, "/tmp/fstab.new");
|
---|
2043 | } else {
|
---|
2044 | mr_asprintf(fstab_fname, "/tmp/fstab");
|
---|
2045 | }
|
---|
2046 | mr_asprintf(tmp1, "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname, fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE);
|
---|
2047 | mr_free(fstab_fname);
|
---|
2048 |
|
---|
2049 | res = system(tmp1);
|
---|
2050 | mr_free(tmp1);
|
---|
2051 | if (res) {
|
---|
2052 | log_to_screen("label-partitions-as-necessary returned an error");
|
---|
2053 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
2054 | } else {
|
---|
2055 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
2056 | }
|
---|
2057 | retval += res;
|
---|
2058 | }
|
---|
2059 |
|
---|
2060 | log_it("About to leave interactive_mode()");
|
---|
2061 | if (retval) {
|
---|
2062 | mvaddstr_and_log_it(g_currentY++,
|
---|
2063 | 0,
|
---|
2064 | "Warning - errors occurred during the restore phase.");
|
---|
2065 | }
|
---|
2066 | end_of_func:
|
---|
2067 | paranoid_free(tmp);
|
---|
2068 | log_it("Leaving interactive_mode()");
|
---|
2069 | return (retval);
|
---|
2070 | }
|
---|
2071 |
|
---|
2072 | /**************************************************************************
|
---|
2073 | *END_INTERACTIVE_MODE *
|
---|
2074 | **************************************************************************/
|
---|
2075 |
|
---|
2076 |
|
---|
2077 |
|
---|
2078 | /**
|
---|
2079 | * Restore the user's data automatically (no prompts), after a twenty-second
|
---|
2080 | * warning period.
|
---|
2081 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
2082 | * @param mountlist The mountlist containing information about the user's partitions.
|
---|
2083 | * @param raidlist The raidlist that goes with @p mountlist.
|
---|
2084 | * @return 0 for success, or the number of errors encountered.
|
---|
2085 | * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b>
|
---|
2086 | */
|
---|
2087 | int nuke_mode(struct mountlist_itself *mountlist, struct raidlist_itself *raidlist)
|
---|
2088 | {
|
---|
2089 | int retval = 0;
|
---|
2090 | int res = 0;
|
---|
2091 | char *tmp = NULL;
|
---|
2092 | char *tmp1 = NULL;
|
---|
2093 | char *flaws_str = NULL;
|
---|
2094 |
|
---|
2095 | assert(bkpinfo != NULL);
|
---|
2096 | assert(mountlist != NULL);
|
---|
2097 | assert(raidlist != NULL);
|
---|
2098 |
|
---|
2099 | log_msg(2, "nuke_mode --- starting");
|
---|
2100 |
|
---|
2101 | get_cfg_file_from_archive_or_bust();
|
---|
2102 | load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist
|
---|
2103 | #ifdef __FreeBSD__
|
---|
2104 | if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize"))
|
---|
2105 | #else
|
---|
2106 | if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize"))
|
---|
2107 | #endif
|
---|
2108 | {
|
---|
2109 | log_msg(2, "Not resizing mountlist.");
|
---|
2110 | } else {
|
---|
2111 | resize_mountlist_proportionately_to_suit_new_drives(mountlist);
|
---|
2112 | }
|
---|
2113 | flaws_str = evaluate_mountlist(mountlist);
|
---|
2114 | if (flaws_str != NULL) {
|
---|
2115 | mr_asprintf(tmp, "Mountlist analyzed. Result: \"%s\" Switch to Interactive Mode?", flaws_str);
|
---|
2116 | mr_free(flaws_str);
|
---|
2117 | if (ask_me_yes_or_no(tmp)) {
|
---|
2118 | retval = interactive_mode(mountlist, raidlist);
|
---|
2119 | mr_free(tmp);
|
---|
2120 | goto after_the_nuke;
|
---|
2121 | } else {
|
---|
2122 | fatal_error("Nuke Mode aborted. ");
|
---|
2123 | }
|
---|
2124 | }
|
---|
2125 |
|
---|
2126 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
2127 | mvaddstr_and_log_it(1, 30, "Restoring Automatically");
|
---|
2128 | if (bkpinfo->differential) {
|
---|
2129 | log_to_screen("Because this is a differential backup, disk");
|
---|
2130 | log_to_screen("partitioning and formatting will not take place.");
|
---|
2131 | res = 0;
|
---|
2132 | } else {
|
---|
2133 | if (partition_table_contains_Compaq_diagnostic_partition
|
---|
2134 | (mountlist)) {
|
---|
2135 | offer_to_abort_because_Compaq_ProLiants_suck();
|
---|
2136 | } else {
|
---|
2137 | twenty_seconds_til_yikes();
|
---|
2138 | g_fprep = fopen("/tmp/prep.sh", "w");
|
---|
2139 | mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat "CMDLINE));
|
---|
2140 | if (strstr(tmp1, "nopart")) {
|
---|
2141 | log_msg(2, "Not partitioning drives due to 'nopart' option.");
|
---|
2142 | res = 0;
|
---|
2143 | } else {
|
---|
2144 | res = partition_everything(mountlist);
|
---|
2145 | if (res) {
|
---|
2146 | log_to_screen("Warning. Errors occurred during partitioning.");
|
---|
2147 | res = 0;
|
---|
2148 | }
|
---|
2149 | }
|
---|
2150 | mr_free(tmp1);
|
---|
2151 |
|
---|
2152 | retval += res;
|
---|
2153 | if (!res) {
|
---|
2154 | log_to_screen("Preparing to format your disk(s)");
|
---|
2155 | sleep(1);
|
---|
2156 | sync();
|
---|
2157 | log_to_screen("Please wait. This may take a few minutes.");
|
---|
2158 | res += format_everything(mountlist, FALSE, raidlist);
|
---|
2159 | }
|
---|
2160 | paranoid_fclose(g_fprep);
|
---|
2161 | }
|
---|
2162 | }
|
---|
2163 | retval += res;
|
---|
2164 | if (res) {
|
---|
2165 | mvaddstr_and_log_it(g_currentY++, 0, "Failed to partition and/or format your hard drives.");
|
---|
2166 |
|
---|
2167 | if (ask_me_yes_or_no("Try in interactive mode instead?")) {
|
---|
2168 | retval = interactive_mode(mountlist, raidlist);
|
---|
2169 | goto after_the_nuke;
|
---|
2170 | } else
|
---|
2171 | if (!ask_me_yes_or_no("Would you like to try to proceed anyway?")) {
|
---|
2172 | return (retval);
|
---|
2173 | }
|
---|
2174 | }
|
---|
2175 | retval = mount_all_devices(mountlist, TRUE);
|
---|
2176 | if (retval) {
|
---|
2177 | unmount_all_devices(mountlist);
|
---|
2178 | log_to_screen("Unable to mount all partitions. Sorry, I cannot proceed.");
|
---|
2179 | return (retval);
|
---|
2180 | }
|
---|
2181 | log_it("Restoring everything");
|
---|
2182 | retval += restore_everything(NULL);
|
---|
2183 | clean_multipathconf();
|
---|
2184 | if (!run_boot_loader(FALSE)) {
|
---|
2185 | log_msg(1, "Great! Boot loader was installed. No need for msg at end.");
|
---|
2186 | }
|
---|
2187 | clean_blkid();
|
---|
2188 | protect_against_braindead_sysadmins();
|
---|
2189 | retval += unmount_all_devices(mountlist);
|
---|
2190 | mvaddstr_and_log_it(g_currentY, 0, "Using tune2fs/tune4fs to identify your ext2,3,4 partitions");
|
---|
2191 |
|
---|
2192 | mr_asprintf(tmp1, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", "/tmp/mountlist.txt", MONDO_LOGFILE, MONDO_LOGFILE);
|
---|
2193 | res = run_program_and_log_output(tmp1, TRUE);
|
---|
2194 | mr_free(tmp1);
|
---|
2195 | if (res) {
|
---|
2196 | log_to_screen("label-partitions-as-necessary returned an error");
|
---|
2197 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
2198 | } else {
|
---|
2199 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
2200 | }
|
---|
2201 | retval += res;
|
---|
2202 |
|
---|
2203 | after_the_nuke:
|
---|
2204 | mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat "CMDLINE));
|
---|
2205 | if (retval) {
|
---|
2206 | log_to_screen("Errors occurred during the nuke phase.");
|
---|
2207 | } else if (strstr(tmp1, "RESTORE")) {
|
---|
2208 | log_to_screen("PC was restored successfully. Thank you for using Mondo Rescue.");
|
---|
2209 | log_to_screen("Please visit our website at http://www.mondorescue.org for more information.");
|
---|
2210 | } else {
|
---|
2211 | mr_asprintf(tmp,"%s","Mondo has restored your system.\n\nPlease wait for the command prompt. Then remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information.");
|
---|
2212 | popup_and_OK(tmp);
|
---|
2213 | mr_free(tmp);
|
---|
2214 | log_to_screen("Mondo has restored your system. Please wait for the command prompt.");
|
---|
2215 | log_to_screen("Then remove the backup media and reboot.");
|
---|
2216 | log_to_screen("Please visit our website at http://www.mondorescue.org for more information.");
|
---|
2217 | }
|
---|
2218 | mr_free(tmp1);
|
---|
2219 |
|
---|
2220 | g_I_have_just_nuked = TRUE;
|
---|
2221 | return (retval);
|
---|
2222 | }
|
---|
2223 |
|
---|
2224 | /**************************************************************************
|
---|
2225 | *END_NUKE_MODE *
|
---|
2226 | **************************************************************************/
|
---|
2227 |
|
---|
2228 |
|
---|
2229 |
|
---|
2230 | /**
|
---|
2231 | * Allow the user to modify the mountlist before we partition & format their drives.
|
---|
2232 | * @param bkpinfo The backup information structure. @c disaster_recovery is the only field used.
|
---|
2233 | * @param mountlist The mountlist to let the user modify.
|
---|
2234 | * @param raidlist The raidlist that goes with @p mountlist.
|
---|
2235 | * @return 0 for success, nonzero for failure.
|
---|
2236 | * @ingroup restoreGuiGroup
|
---|
2237 | */
|
---|
2238 | int let_user_edit_the_mountlist(struct mountlist_itself *mountlist,
|
---|
2239 | struct raidlist_itself *raidlist)
|
---|
2240 | {
|
---|
2241 | int retval = 0, res = 0;
|
---|
2242 |
|
---|
2243 | log_msg(2, "let_user_edit_the_mountlist() --- starting");
|
---|
2244 |
|
---|
2245 | assert(bkpinfo != NULL);
|
---|
2246 | assert(mountlist != NULL);
|
---|
2247 | assert(raidlist != NULL);
|
---|
2248 | if (!bkpinfo->disaster_recovery) {
|
---|
2249 | strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
2250 | log_msg(2, "I guess you're testing edit_mountlist()");
|
---|
2251 | }
|
---|
2252 | if (!does_file_exist(g_mountlist_fname)) {
|
---|
2253 | log_to_screen(g_mountlist_fname);
|
---|
2254 | log_to_screen("does not exist");
|
---|
2255 | return (1);
|
---|
2256 | }
|
---|
2257 |
|
---|
2258 | retval = load_mountlist(mountlist, g_mountlist_fname);
|
---|
2259 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
2260 | if (retval) {
|
---|
2261 | log_to_screen
|
---|
2262 | ("Warning - load_raidtab_into_raidlist returned an error");
|
---|
2263 | }
|
---|
2264 | res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
|
---|
2265 | if (res) {
|
---|
2266 | return (1);
|
---|
2267 | }
|
---|
2268 |
|
---|
2269 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
2270 | save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
|
---|
2271 |
|
---|
2272 | log_to_screen("I have finished editing the mountlist for you.");
|
---|
2273 |
|
---|
2274 | return (retval);
|
---|
2275 | }
|
---|
2276 |
|
---|
2277 |
|
---|
2278 |
|
---|
2279 |
|
---|
2280 |
|
---|
2281 | /**
|
---|
2282 | * Call interactive_mode(), nuke_mode(), or compare_mode() depending on the user's choice.
|
---|
2283 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
2284 | * @param mountlist The mountlist containing information about the user's partitions.
|
---|
2285 | * @param raidlist The raidlist to go with @p mountlist.
|
---|
2286 | * @return The return code from the mode function called.
|
---|
2287 | * @ingroup restoreGroup
|
---|
2288 | */
|
---|
2289 | int
|
---|
2290 | catchall_mode(struct mountlist_itself *mountlist,
|
---|
2291 | struct raidlist_itself *raidlist)
|
---|
2292 | {
|
---|
2293 | char c;
|
---|
2294 | char *tmp = NULL;
|
---|
2295 | int retval = 0;
|
---|
2296 |
|
---|
2297 | log_it("inside catchall");
|
---|
2298 | assert(bkpinfo != NULL);
|
---|
2299 | assert(mountlist != NULL);
|
---|
2300 | assert(raidlist != NULL);
|
---|
2301 | log_it("pre wrm");
|
---|
2302 | c = which_restore_mode();
|
---|
2303 | log_it("post wrm");
|
---|
2304 | if (c == 'I' || c == 'C') {
|
---|
2305 | interactively_obtain_media_parameters_from_user(FALSE);
|
---|
2306 | } else if (c == 'N') {
|
---|
2307 | // Auto mode nothing special to do
|
---|
2308 | } else {
|
---|
2309 | popup_and_OK("No restoring or comparing will take place today.");
|
---|
2310 | if (is_this_device_mounted("/mnt/cdrom")) {
|
---|
2311 | run_program_and_log_output("umount -d /mnt/cdrom", FALSE);
|
---|
2312 | }
|
---|
2313 | if (g_ISO_restore_mode) {
|
---|
2314 | mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
|
---|
2315 | run_program_and_log_output(tmp, FALSE);
|
---|
2316 | mr_free(tmp);
|
---|
2317 | }
|
---|
2318 | paranoid_MR_finish(0);
|
---|
2319 | }
|
---|
2320 |
|
---|
2321 | log_it("post int");
|
---|
2322 |
|
---|
2323 | if (bkpinfo->backup_media_type == iso) {
|
---|
2324 | if (iso_fiddly_bits((c == 'N') ? TRUE : FALSE)) {
|
---|
2325 | log_msg(2,
|
---|
2326 | "catchall_mode --- iso_fiddly_bits returned w/ error");
|
---|
2327 | return (1);
|
---|
2328 | } else {
|
---|
2329 | log_msg(2, "catchall_mode --- iso_fiddly_bits ok");
|
---|
2330 | }
|
---|
2331 | }
|
---|
2332 |
|
---|
2333 | if (c == 'I') {
|
---|
2334 | log_msg(2, "IM selected");
|
---|
2335 | retval += interactive_mode(mountlist, raidlist);
|
---|
2336 | } else if (c == 'N') {
|
---|
2337 | log_msg(2, "NM selected");
|
---|
2338 | retval += nuke_mode(mountlist, raidlist);
|
---|
2339 | } else if (c == 'C') {
|
---|
2340 | log_msg(2, "CM selected");
|
---|
2341 | retval += compare_mode(mountlist, raidlist);
|
---|
2342 | }
|
---|
2343 | return (retval);
|
---|
2344 | }
|
---|
2345 |
|
---|
2346 | /**************************************************************************
|
---|
2347 | *END_CATCHALL_MODE *
|
---|
2348 | **************************************************************************/
|
---|
2349 |
|
---|
2350 | /**************************************************************************
|
---|
2351 | *END_ EXTRACT_CONFIG_FILE_FROM_RAMDISK *
|
---|
2352 | **************************************************************************/
|
---|
2353 |
|
---|
2354 |
|
---|
2355 | /**
|
---|
2356 | * Locate an executable in the directory structure rooted at @p restg.
|
---|
2357 | * @param out_path Where to put the executable.
|
---|
2358 | * @param fname The basename of the executable.
|
---|
2359 | * @param restg The directory structure to look in.
|
---|
2360 | * @note If it could not be found in @p restg then @p fname is put in @p out_path.
|
---|
2361 | * @ingroup restoreUtilityGroup
|
---|
2362 | */
|
---|
2363 | void
|
---|
2364 | find_pathname_of_executable_preferably_in_RESTORING(char *out_path,
|
---|
2365 | char *fname,
|
---|
2366 | char *restg)
|
---|
2367 | {
|
---|
2368 | assert(out_path != NULL);
|
---|
2369 | assert_string_is_neither_NULL_nor_zerolength(fname);
|
---|
2370 |
|
---|
2371 | sprintf(out_path, "%s/sbin/%s", restg, fname);
|
---|
2372 | if (does_file_exist(out_path)) {
|
---|
2373 | sprintf(out_path, "%s/usr/sbin/%s", restg, fname);
|
---|
2374 | if (does_file_exist(out_path)) {
|
---|
2375 | sprintf(out_path, "%s/bin/%s", restg, fname);
|
---|
2376 | if (does_file_exist(out_path)) {
|
---|
2377 | sprintf(out_path, "%s/usr/bin/%s", restg, fname);
|
---|
2378 | if (does_file_exist(out_path)) {
|
---|
2379 | strcpy(out_path, fname);
|
---|
2380 | }
|
---|
2381 | }
|
---|
2382 | }
|
---|
2383 | }
|
---|
2384 | }
|
---|
2385 |
|
---|
2386 | /**************************************************************************
|
---|
2387 | *END_FIND_PATHNAME_OF_EXECUTABLE_PREFERABLY_IN_RESTORING *
|
---|
2388 | **************************************************************************/
|
---|
2389 |
|
---|
2390 |
|
---|
2391 | /**
|
---|
2392 | * Run an arbitrary restore mode (prompt the user), but from ISO images
|
---|
2393 | * instead of real media.
|
---|
2394 | * @param mountlist The mountlist containing information about the user's partitions.
|
---|
2395 | * @param raidlist The raidlist that goes with @p mountlist.
|
---|
2396 | * @param nuke_me_please If TRUE, we plan to run Nuke Mode.
|
---|
2397 | * @return 0 for success, or the number of errors encountered.
|
---|
2398 | */
|
---|
2399 | int
|
---|
2400 | iso_mode(struct mountlist_itself *mountlist,
|
---|
2401 | struct raidlist_itself *raidlist, bool nuke_me_please)
|
---|
2402 | {
|
---|
2403 | char c;
|
---|
2404 | int retval = 0;
|
---|
2405 |
|
---|
2406 | assert(mountlist != NULL);
|
---|
2407 | assert(raidlist != NULL);
|
---|
2408 | if (iso_fiddly_bits(nuke_me_please)) {
|
---|
2409 | log_msg(1, "iso_mode --- returning w/ error");
|
---|
2410 | return (1);
|
---|
2411 | } else {
|
---|
2412 | c = which_restore_mode();
|
---|
2413 | if (c == 'I' || c == 'N' || c == 'C') {
|
---|
2414 | interactively_obtain_media_parameters_from_user(FALSE);
|
---|
2415 | }
|
---|
2416 | if (c == 'I') {
|
---|
2417 | retval += interactive_mode(mountlist, raidlist);
|
---|
2418 | } else if (c == 'N') {
|
---|
2419 | retval += nuke_mode(mountlist, raidlist);
|
---|
2420 | } else if (c == 'C') {
|
---|
2421 | retval += compare_mode(mountlist, raidlist);
|
---|
2422 | } else {
|
---|
2423 | log_to_screen("OK, I shan't restore/compare any files.");
|
---|
2424 | }
|
---|
2425 | }
|
---|
2426 | if (is_this_device_mounted(MNT_CDROM)) {
|
---|
2427 | paranoid_system("umount -d " MNT_CDROM);
|
---|
2428 | }
|
---|
2429 | // if (! already_mounted)
|
---|
2430 | // {
|
---|
2431 | if (system("umount -d /tmp/isodir 2> /dev/null")) {
|
---|
2432 | log_to_screen("WARNING - unable to unmount device where the ISO files are stored.");
|
---|
2433 | }
|
---|
2434 | // }
|
---|
2435 | return (retval);
|
---|
2436 | }
|
---|
2437 |
|
---|
2438 | /**************************************************************************
|
---|
2439 | *END_ISO_MODE *
|
---|
2440 | **************************************************************************/
|
---|
2441 |
|
---|
2442 |
|
---|
2443 | /* MONDO - saving your systems since Feb 18th, 2000 */
|
---|
2444 |
|
---|
2445 |
|
---|
2446 |
|
---|
2447 | /**
|
---|
2448 | * Restore the user's data (or a subset of it) to the live filesystem.
|
---|
2449 | * This should not be called if we're booted from CD!
|
---|
2450 | * @param bkpinfo The backup information structure. Most fields are used.
|
---|
2451 | * @return 0 for success, or the number of errors encountered.
|
---|
2452 | */
|
---|
2453 | int restore_to_live_filesystem()
|
---|
2454 | {
|
---|
2455 | int retval = 0;
|
---|
2456 |
|
---|
2457 | char *old_restpath = NULL;
|
---|
2458 |
|
---|
2459 | struct mountlist_itself *mountlist = NULL;
|
---|
2460 | struct raidlist_itself *raidlist = NULL;
|
---|
2461 | struct s_node *filelist = NULL;
|
---|
2462 |
|
---|
2463 | log_msg(1, "restore_to_live_filesystem() - starting");
|
---|
2464 | assert(bkpinfo != NULL);
|
---|
2465 | mountlist = malloc(sizeof(struct mountlist_itself));
|
---|
2466 | raidlist = malloc(sizeof(struct raidlist_itself));
|
---|
2467 | if (!mountlist || !raidlist) {
|
---|
2468 | fatal_error("Cannot malloc() mountlist and/or raidlist");
|
---|
2469 | }
|
---|
2470 |
|
---|
2471 | strcpy(bkpinfo->restore_path, "/");
|
---|
2472 | if (!g_restoring_live_from_cd && !g_restoring_live_from_netfs) {
|
---|
2473 | popup_and_OK("Please insert tape/CD/USB Key, then hit 'OK' to continue.");
|
---|
2474 | sleep(1);
|
---|
2475 | }
|
---|
2476 | if (!g_restoring_live_from_netfs) {
|
---|
2477 | interactively_obtain_media_parameters_from_user(FALSE);
|
---|
2478 | }
|
---|
2479 | log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
|
---|
2480 | if (!bkpinfo->media_device[0]) {
|
---|
2481 | log_msg(2, "Warning - failed to find media dev");
|
---|
2482 | }
|
---|
2483 |
|
---|
2484 |
|
---|
2485 | log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
|
---|
2486 |
|
---|
2487 | open_evalcall_form("Thinking...");
|
---|
2488 |
|
---|
2489 | get_cfg_file_from_archive_or_bust();
|
---|
2490 | read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
|
---|
2491 | load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo
|
---|
2492 |
|
---|
2493 | close_evalcall_form();
|
---|
2494 | retval = load_mountlist(mountlist, g_mountlist_fname);
|
---|
2495 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
2496 |
|
---|
2497 | if (!g_restoring_live_from_netfs && (filelist = process_filelist_and_biggielist())) {
|
---|
2498 | save_filelist(filelist, "/tmp/selected-files.txt");
|
---|
2499 | mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
|
---|
2500 | if (popup_and_get_string("Restore path", "Restore files to where? ", bkpinfo->restore_path, MAX_STR_LEN / 4)) {
|
---|
2501 | log_it("Restoring everything");
|
---|
2502 | retval += restore_everything(filelist);
|
---|
2503 | free_filelist(filelist);
|
---|
2504 | strcpy(bkpinfo->restore_path, old_restpath);
|
---|
2505 | } else {
|
---|
2506 | free_filelist(filelist);
|
---|
2507 | }
|
---|
2508 | strcpy(bkpinfo->restore_path, old_restpath);
|
---|
2509 | mr_free(old_restpath);
|
---|
2510 | } else {
|
---|
2511 | if (filelist != NULL) {
|
---|
2512 | retval += restore_everything(NULL);
|
---|
2513 | }
|
---|
2514 | }
|
---|
2515 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
2516 | log_msg(2, "Tape : I don't need to unmount or eject the CD-ROM.");
|
---|
2517 | } else {
|
---|
2518 | run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
|
---|
2519 | if (!bkpinfo->please_dont_eject) {
|
---|
2520 | eject_device(bkpinfo->media_device);
|
---|
2521 | }
|
---|
2522 | }
|
---|
2523 | run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
|
---|
2524 | if (!bkpinfo->please_dont_eject) {
|
---|
2525 | eject_device(bkpinfo->media_device);
|
---|
2526 | }
|
---|
2527 | free(mountlist);
|
---|
2528 | free(raidlist);
|
---|
2529 | return (retval);
|
---|
2530 | }
|
---|
2531 |
|
---|
2532 | /**************************************************************************
|
---|
2533 | *END_RESTORE_TO_LIVE_FILESYSTEM *
|
---|
2534 | **************************************************************************/
|
---|
2535 |
|
---|
2536 | /* @} - end of restoreGroup */
|
---|
2537 |
|
---|
2538 |
|
---|
2539 | /**
|
---|
2540 | * Log a "don't panic" message to the logfile.
|
---|
2541 | */
|
---|
2542 | void welcome_to_mondorestore()
|
---|
2543 | {
|
---|
2544 | log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
|
---|
2545 | log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please ");
|
---|
2546 | log_msg(0, "don't break out in a cold sweat just because you see a few ");
|
---|
2547 | log_msg(0, "error messages in the log. Read them; analyze them; see if ");
|
---|
2548 | log_msg(0, "they are significant; above all, verify your backups! Please");
|
---|
2549 | log_msg(0, "attach a compressed copy of this log to any e-mail you send ");
|
---|
2550 | log_msg(0, "to the Mondo mailing list when you are seeking technical ");
|
---|
2551 | log_msg(0, "support. Without it, we can't help you. - DevTeam");
|
---|
2552 | log_msg(0, "------------------------------------------------------------");
|
---|
2553 | log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages,");
|
---|
2554 | log_msg(0, "some users are inclined to stop reading this log. If Mondo ");
|
---|
2555 | log_msg(0, "stopped for some reason, chances are it's detailed here. ");
|
---|
2556 | log_msg(0, "More than likely there's a message at the very end of this ");
|
---|
2557 | log_msg(0, "log that will tell you what is wrong. Please read it! ");
|
---|
2558 | log_msg(0, "------------------------------------------------------------");
|
---|
2559 | }
|
---|
2560 |
|
---|
2561 |
|
---|
2562 |
|
---|
2563 | /**
|
---|
2564 | * Restore the user's data.
|
---|
2565 | * What did you think it did, anyway? :-)
|
---|
2566 | */
|
---|
2567 | int main(int argc, char *argv[])
|
---|
2568 | {
|
---|
2569 | FILE *fin;
|
---|
2570 | FILE *fout;
|
---|
2571 | int retval = 0;
|
---|
2572 | int res;
|
---|
2573 | char *tmp = NULL;
|
---|
2574 |
|
---|
2575 | struct mountlist_itself *mountlist;
|
---|
2576 | struct raidlist_itself *raidlist;
|
---|
2577 | struct s_node *filelist;
|
---|
2578 | char *tmp1 = NULL;
|
---|
2579 | char *tmp2 = NULL;
|
---|
2580 | bool run_postnuke = FALSE;
|
---|
2581 |
|
---|
2582 | if (getuid() != 0) {
|
---|
2583 | fprintf(stderr, "Please run as root.\r\n");
|
---|
2584 | exit(127);
|
---|
2585 | }
|
---|
2586 | if (!
|
---|
2587 | (bkpinfo = malloc(sizeof(struct s_bkpinfo)))) {
|
---|
2588 | fatal_error("Cannot malloc bkpinfo");
|
---|
2589 | }
|
---|
2590 | reset_bkpinfo();
|
---|
2591 |
|
---|
2592 | g_loglevel = DEFAULT_MR_LOGLEVEL;
|
---|
2593 |
|
---|
2594 | /* Configure global variables */
|
---|
2595 | #ifdef __FreeBSD__
|
---|
2596 | if (strstr
|
---|
2597 | (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
|
---|
2598 | "textonly"))
|
---|
2599 | #else
|
---|
2600 | if (strstr
|
---|
2601 | (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
|
---|
2602 | "textonly"))
|
---|
2603 | #endif
|
---|
2604 | {
|
---|
2605 | g_text_mode = TRUE;
|
---|
2606 | log_msg(1, "TEXTONLY MODE");
|
---|
2607 | } else {
|
---|
2608 | g_text_mode = FALSE;
|
---|
2609 | } // newt :-)
|
---|
2610 | if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
|
---|
2611 | fatal_error("Cannot malloc mountlist");
|
---|
2612 | }
|
---|
2613 | if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
|
---|
2614 | fatal_error("Cannot malloc raidlist");
|
---|
2615 | }
|
---|
2616 |
|
---|
2617 | /* Init GUI */
|
---|
2618 | setup_newt_stuff(); /* call newtInit and setup screen log */
|
---|
2619 |
|
---|
2620 | malloc_libmondo_global_strings();
|
---|
2621 |
|
---|
2622 | strcpy(g_mondo_home,
|
---|
2623 | call_program_and_get_last_line_of_output("which mondorestore"));
|
---|
2624 | g_current_media_number = 1; // precaution
|
---|
2625 |
|
---|
2626 | run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
|
---|
2627 |
|
---|
2628 | setup_MR_global_filenames(); // malloc() and set globals, using bkpinfo->tmpdir etc.
|
---|
2629 | bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
|
---|
2630 | bkpinfo->restore_data = TRUE; // Well, yeah :-)
|
---|
2631 | if (am_I_in_disaster_recovery_mode()) {
|
---|
2632 | run_program_and_log_output("mount / -o remount,rw", 2);
|
---|
2633 | } // for b0rken distros
|
---|
2634 | g_main_pid = getpid();
|
---|
2635 | srandom((int) (time(NULL)));
|
---|
2636 | set_signals(TRUE);
|
---|
2637 | g_kernel_version = get_kernel_version();
|
---|
2638 |
|
---|
2639 | log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
|
---|
2640 | if (strlen(g_mountlist_fname) < 3) {
|
---|
2641 | fatal_error
|
---|
2642 | ("Serious error in malloc()'ing. Could be a bug in your glibc.");
|
---|
2643 | }
|
---|
2644 | mkdir(MNT_CDROM, 0x770);
|
---|
2645 | make_hole_for_dir(MONDO_CACHE);
|
---|
2646 |
|
---|
2647 | /* Backup original mountlist.txt */
|
---|
2648 | mr_asprintf(tmp, "%s.orig", g_mountlist_fname);
|
---|
2649 | if (!does_file_exist(g_mountlist_fname)) {
|
---|
2650 | log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname);
|
---|
2651 | } else if (!does_file_exist(tmp)) {
|
---|
2652 | mr_free(tmp);
|
---|
2653 | mr_asprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, g_mountlist_fname);
|
---|
2654 | run_program_and_log_output(tmp, FALSE);
|
---|
2655 | }
|
---|
2656 | mr_free(tmp);
|
---|
2657 |
|
---|
2658 | /* Init directories */
|
---|
2659 | make_hole_for_dir("/var/log");
|
---|
2660 | make_hole_for_dir("/tmp/tmpfs"); /* just in case... */
|
---|
2661 | run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
|
---|
2662 |
|
---|
2663 | run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
|
---|
2664 |
|
---|
2665 | welcome_to_mondorestore();
|
---|
2666 | if (bkpinfo->disaster_recovery) {
|
---|
2667 | log_msg(1, "I am in disaster recovery mode");
|
---|
2668 | } else {
|
---|
2669 | log_msg(1, "I am in normal, live mode");
|
---|
2670 | }
|
---|
2671 |
|
---|
2672 | log_it("what time is it");
|
---|
2673 |
|
---|
2674 | /* Process command-line parameters */
|
---|
2675 | if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
|
---|
2676 | #ifdef __FreeBSD__
|
---|
2677 | paranoid_system("mv -f /tmp/raidconf.txt /etc/raidtab");
|
---|
2678 | if (!does_file_exist("/etc/raidtab"))
|
---|
2679 | paranoid_system("vinum printconfig > /etc/raidtab");
|
---|
2680 | #endif
|
---|
2681 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
2682 | if (!does_file_exist(g_mountlist_fname)) {
|
---|
2683 | strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
2684 | }
|
---|
2685 | res = let_user_edit_the_mountlist(mountlist, raidlist);
|
---|
2686 | #ifdef __FreeBSD__
|
---|
2687 | paranoid_system("mv -f /etc/raidtab /tmp/raidconf.txt");
|
---|
2688 | #endif
|
---|
2689 | paranoid_MR_finish(res);
|
---|
2690 | }
|
---|
2691 |
|
---|
2692 | if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
|
---|
2693 | fout = fopen("/tmp/out.txt", "w");
|
---|
2694 | fput_string_one_char_at_a_time(stderr, argv[2]);
|
---|
2695 | finish(0);
|
---|
2696 | }
|
---|
2697 |
|
---|
2698 | if (argc == 5 && strcmp(argv[1], "--common") == 0) {
|
---|
2699 | g_loglevel = 6;
|
---|
2700 | filelist = load_filelist(argv[2]);
|
---|
2701 | if (!filelist) {
|
---|
2702 | fatal_error("Failed to load filelist");
|
---|
2703 | }
|
---|
2704 | toggle_node_selection(filelist, FALSE);
|
---|
2705 | toggle_all_root_dirs_on(filelist);
|
---|
2706 | // BERLIOS: /usr/lib ???
|
---|
2707 | toggle_path_selection(filelist, "/usr/share", TRUE);
|
---|
2708 | save_filelist(filelist, "/tmp/out.txt");
|
---|
2709 | mr_asprintf(tmp1, "%s", argv[3]);
|
---|
2710 | mr_asprintf(tmp2, "%s", argv[4]);
|
---|
2711 |
|
---|
2712 | res = save_filelist_entries_in_common(tmp1, filelist, tmp2, FALSE);
|
---|
2713 | mr_free(tmp1);
|
---|
2714 | mr_free(tmp2);
|
---|
2715 |
|
---|
2716 | free_filelist(filelist);
|
---|
2717 | printf("res = %d", res);
|
---|
2718 | finish(0);
|
---|
2719 | }
|
---|
2720 |
|
---|
2721 | if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
|
---|
2722 | popup_changelist_from_file(argv[2]);
|
---|
2723 | paranoid_MR_finish(0);
|
---|
2724 | }
|
---|
2725 |
|
---|
2726 | if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
|
---|
2727 | log_msg(1, "SCORE");
|
---|
2728 | g_loglevel = 10;
|
---|
2729 | if (strstr(argv[2], "save")) {
|
---|
2730 | log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
|
---|
2731 | fin = fopen(argv[3], "r");
|
---|
2732 | fout = fopen(argv[4], "w");
|
---|
2733 | copy_from_src_to_dest(fin, fout, 'w');
|
---|
2734 | fclose(fin);
|
---|
2735 | fin = fopen(argv[3], "r");
|
---|
2736 | copy_from_src_to_dest(fin, fout, 'w');
|
---|
2737 | fclose(fout);
|
---|
2738 | fclose(fin);
|
---|
2739 | } else if (strstr(argv[2], "restore")) {
|
---|
2740 | fout = fopen(argv[3], "w");
|
---|
2741 | fin = fopen(argv[4], "r");
|
---|
2742 | copy_from_src_to_dest(fout, fin, 'r');
|
---|
2743 | fclose(fin);
|
---|
2744 | fin = fopen(argv[4], "r");
|
---|
2745 | copy_from_src_to_dest(fout, fin, 'r');
|
---|
2746 | fclose(fout);
|
---|
2747 | fclose(fin);
|
---|
2748 | } else {
|
---|
2749 | fatal_error("Unknown additional param");
|
---|
2750 | }
|
---|
2751 | finish(0);
|
---|
2752 | }
|
---|
2753 |
|
---|
2754 | if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
|
---|
2755 | wait_until_software_raids_are_prepped(argv[2], 100);
|
---|
2756 | finish(0);
|
---|
2757 | }
|
---|
2758 |
|
---|
2759 | if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
|
---|
2760 | finish(create_raidtab_from_mdstat(MDSTAT_FILE,argv[2]));
|
---|
2761 | }
|
---|
2762 |
|
---|
2763 | if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
|
---|
2764 | retval = run_grub(FALSE, "/dev/hda");
|
---|
2765 | if (retval) {
|
---|
2766 | log_to_screen("Failed to write Master Boot Record");
|
---|
2767 | }
|
---|
2768 | paranoid_MR_finish(0);
|
---|
2769 | }
|
---|
2770 | if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
|
---|
2771 | g_current_media_number = atoi(argv[2]);
|
---|
2772 | pause_and_ask_for_cdr(5, NULL);
|
---|
2773 | paranoid_MR_finish(0);
|
---|
2774 | }
|
---|
2775 | if ((argc == 2 && strcmp(argv[1], "--partition-only") == 0) && (bkpinfo->disaster_recovery)) {
|
---|
2776 | log_msg(0, "Partitioning only.");
|
---|
2777 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
2778 | strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
2779 | load_mountlist(mountlist, g_mountlist_fname);
|
---|
2780 | res = partition_everything(mountlist);
|
---|
2781 | finish(res);
|
---|
2782 | }
|
---|
2783 |
|
---|
2784 | if ((argc == 2 && strcmp(argv[1], "--format-only") == 0) && (bkpinfo->disaster_recovery)) {
|
---|
2785 | log_msg(0, "Formatting only.");
|
---|
2786 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
2787 | strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
2788 | load_mountlist(mountlist, g_mountlist_fname);
|
---|
2789 | res = format_everything(mountlist, FALSE, raidlist);
|
---|
2790 | finish(res);
|
---|
2791 | }
|
---|
2792 |
|
---|
2793 | if ((argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) && (bkpinfo->disaster_recovery)) {
|
---|
2794 | log_msg(0, "Stopping LVM and RAID");
|
---|
2795 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
2796 | strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
2797 | load_mountlist(mountlist, g_mountlist_fname);
|
---|
2798 | res = do_my_funky_lvm_stuff(TRUE, FALSE);
|
---|
2799 | res += stop_all_raid_devices(mountlist);
|
---|
2800 | finish(res);
|
---|
2801 | }
|
---|
2802 |
|
---|
2803 | if ((argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) && (!bkpinfo->disaster_recovery)) {
|
---|
2804 | g_restoring_live_from_cd = TRUE;
|
---|
2805 | }
|
---|
2806 |
|
---|
2807 | // Handle params here first
|
---|
2808 | handle_incoming_parameters(argc,argv);
|
---|
2809 |
|
---|
2810 | if (!bkpinfo->disaster_recovery) { // live!
|
---|
2811 | log_msg(1, "I am in normal, live mode.");
|
---|
2812 | log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
|
---|
2813 | mount_boot_if_necessary(); /* for Gentoo users */
|
---|
2814 | log_msg(2, "Still here.");
|
---|
2815 | if (bkpinfo->backup_media_type == netfs) {
|
---|
2816 | g_restoring_live_from_netfs = TRUE;
|
---|
2817 | }
|
---|
2818 | log_msg(2, "Calling restore_to_live_filesystem()");
|
---|
2819 | retval = restore_to_live_filesystem();
|
---|
2820 |
|
---|
2821 | log_msg(2, "Still here. Yay.");
|
---|
2822 | if ((strlen(bkpinfo->tmpdir) > 0) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
|
---|
2823 | mr_asprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
|
---|
2824 | run_program_and_log_output(tmp, FALSE);
|
---|
2825 | mr_free(tmp);
|
---|
2826 | }
|
---|
2827 | unmount_boot_if_necessary(); /* for Gentoo users */
|
---|
2828 | paranoid_MR_finish(retval);
|
---|
2829 | } else {
|
---|
2830 | /* Disaster recovery mode (must be) */
|
---|
2831 | log_msg(1, "I must be in disaster recovery mode.");
|
---|
2832 | log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
|
---|
2833 |
|
---|
2834 | log_it("About to call load_mountlist and load_raidtab");
|
---|
2835 | strcpy(bkpinfo->restore_path, MNT_RESTORING);
|
---|
2836 | read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
|
---|
2837 | retval = load_mountlist(mountlist, g_mountlist_fname);
|
---|
2838 | retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
2839 | log_it("Returned from calling load_mountlist and load_raidtab successfully");
|
---|
2840 |
|
---|
2841 | // BCO:To be reviewed
|
---|
2842 | if ((bkpinfo->restore_mode == compare) || (bkpinfo->restore_mode == nuke)) {
|
---|
2843 | if ((bkpinfo->backup_media_type == netfs) && bkpinfo->netfs_mount && !is_this_device_mounted(bkpinfo->netfs_mount)) {
|
---|
2844 | log_msg(1, "Mounting remote %s dir", bkpinfo->netfs_proto);
|
---|
2845 | sprintf(bkpinfo->isodir, "/tmp/isodir");
|
---|
2846 | run_program_and_log_output("mkdir -p /tmp/isodir", 5);
|
---|
2847 | if (strstr(bkpinfo->netfs_proto, "sshfs")) {
|
---|
2848 | if (bkpinfo->netfs_user) {
|
---|
2849 | mr_asprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
|
---|
2850 | } else {
|
---|
2851 | mr_asprintf(tmp, "sshfs -o ro %s /tmp/isodir", bkpinfo->netfs_mount);
|
---|
2852 | }
|
---|
2853 | } else {
|
---|
2854 | if (strstr(bkpinfo->netfs_proto, "smbfs")) {
|
---|
2855 | if (bkpinfo->netfs_user) {
|
---|
2856 | mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o user=%s,nolock,ro ", bkpinfo->netfs_mount,bkpinfo->netfs_user);
|
---|
2857 | } else {
|
---|
2858 | mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o nolock,ro ", bkpinfo->netfs_mount);
|
---|
2859 | }
|
---|
2860 | } else {
|
---|
2861 | if (bkpinfo->netfs_user) {
|
---|
2862 | mr_asprintf(tmp, "mount %s@%s -o nolock,ro /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
|
---|
2863 | } else {
|
---|
2864 | mr_asprintf(tmp, "mount %s -o nolock,ro /tmp/isodir", bkpinfo->netfs_mount);
|
---|
2865 | }
|
---|
2866 | }
|
---|
2867 | }
|
---|
2868 | run_program_and_log_output(tmp, 1);
|
---|
2869 | mr_free(tmp);
|
---|
2870 | }
|
---|
2871 | }
|
---|
2872 |
|
---|
2873 | if (retval) {
|
---|
2874 | log_to_screen("Warning - load_raidtab_into_raidlist returned an error");
|
---|
2875 | }
|
---|
2876 |
|
---|
2877 | log_msg(1, "Send in the clowns.");
|
---|
2878 |
|
---|
2879 |
|
---|
2880 | if (bkpinfo->restore_mode == nuke) {
|
---|
2881 | log_it("nuking");
|
---|
2882 | retval += nuke_mode(mountlist, raidlist);
|
---|
2883 | } else if (bkpinfo->restore_mode == interactive) {
|
---|
2884 | log_it("catchall");
|
---|
2885 | retval += catchall_mode(mountlist, raidlist);
|
---|
2886 | } else if (bkpinfo->restore_mode == compare) {
|
---|
2887 | log_it("compare");
|
---|
2888 | retval += compare_mode(mountlist, raidlist);
|
---|
2889 | } else if (bkpinfo->restore_mode == isoonly) {
|
---|
2890 | log_it("iso");
|
---|
2891 | retval = iso_mode(mountlist, raidlist, FALSE);
|
---|
2892 | } else if (bkpinfo->restore_mode == mbr) {
|
---|
2893 | log_it("mbr");
|
---|
2894 | retval = mount_all_devices(mountlist, TRUE);
|
---|
2895 | if (!retval) {
|
---|
2896 | retval += run_boot_loader(FALSE);
|
---|
2897 | retval += unmount_all_devices(mountlist);
|
---|
2898 | }
|
---|
2899 | if (retval) {
|
---|
2900 | log_to_screen("Failed to write Master Boot Record");
|
---|
2901 | }
|
---|
2902 | } else if (bkpinfo->restore_mode == isonuke) {
|
---|
2903 | log_it("isonuke");
|
---|
2904 | retval = iso_mode(mountlist, raidlist, TRUE);
|
---|
2905 | } else {
|
---|
2906 | log_it("catchall (no mode specified in command-line call");
|
---|
2907 | retval += catchall_mode(mountlist, raidlist);
|
---|
2908 | }
|
---|
2909 | }
|
---|
2910 |
|
---|
2911 | /* clean up at the end */
|
---|
2912 | if (retval) {
|
---|
2913 | if (does_file_exist(MONDO_CACHE"/changed.files")) {
|
---|
2914 | log_to_screen
|
---|
2915 | ("See "MONDO_CACHE"/changed.files for list of files that have changed.");
|
---|
2916 | }
|
---|
2917 | mvaddstr_and_log_it(g_currentY++,
|
---|
2918 | 0,
|
---|
2919 | "Run complete. Errors were reported. Please review the logfile.");
|
---|
2920 | } else {
|
---|
2921 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
2922 | mvaddstr_and_log_it(g_currentY++,
|
---|
2923 | 0,
|
---|
2924 | "Run complete. Please remove media and reboot.");
|
---|
2925 | } else {
|
---|
2926 | sync();
|
---|
2927 | if (is_this_device_mounted(MNT_CDROM)) {
|
---|
2928 | run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
|
---|
2929 | }
|
---|
2930 |
|
---|
2931 | if (!bkpinfo->please_dont_eject) {
|
---|
2932 | (void)eject_device("/dev/cdrom");
|
---|
2933 | }
|
---|
2934 | mvaddstr_and_log_it(g_currentY++,
|
---|
2935 | 0,
|
---|
2936 | "Run complete. Please remove media and reboot.");
|
---|
2937 | }
|
---|
2938 | }
|
---|
2939 |
|
---|
2940 | // g_I_have_just_nuked is set true by nuke_mode() just before it returns
|
---|
2941 | if (!system("which post-nuke > /dev/null 2> /dev/null")) {
|
---|
2942 | log_msg(1, "post-nuke found; find out whether we should run it...");
|
---|
2943 | if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
|
---|
2944 | run_postnuke = TRUE;
|
---|
2945 | log_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
|
---|
2946 | } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
|
---|
2947 | run_postnuke = TRUE;
|
---|
2948 | log_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
|
---|
2949 | } else {
|
---|
2950 | run_postnuke = FALSE;
|
---|
2951 | log_msg(1, "No, will not run post-nuke.");
|
---|
2952 | }
|
---|
2953 | } else {
|
---|
2954 | log_msg(1, "No post-nuke found.");
|
---|
2955 | }
|
---|
2956 | if (run_postnuke) {
|
---|
2957 | log_to_screen("Running post-nuke...");
|
---|
2958 | if (mount_all_devices(mountlist, TRUE)) {
|
---|
2959 | log_to_screen
|
---|
2960 | ("Unable to re-mount partitions for post-nuke stuff");
|
---|
2961 | } else {
|
---|
2962 | log_msg(1, "Re-mounted partitions for post-nuke stuff");
|
---|
2963 | mr_asprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval);
|
---|
2964 | log_msg(2, "Calling '%s'", tmp);
|
---|
2965 | if ((res = run_program_and_log_output(tmp, 0))) {
|
---|
2966 | log_OS_error(tmp);
|
---|
2967 | }
|
---|
2968 | mr_free(tmp);
|
---|
2969 | log_msg(1, "post-nuke returned w/ res=%d", res);
|
---|
2970 | }
|
---|
2971 | unmount_all_devices(mountlist);
|
---|
2972 | log_to_screen("I've finished post-nuking.");
|
---|
2973 | }
|
---|
2974 |
|
---|
2975 | /*
|
---|
2976 | log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
|
---|
2977 | log_to_screen("Otherwise, please wait until the RAID disks are done.");
|
---|
2978 | wait_until_software_raids_are_prepped("/proc/mdstat", 100);
|
---|
2979 | log_to_screen("Thank you.");
|
---|
2980 | */
|
---|
2981 | unlink("/tmp/mondo-run-prog.tmp");
|
---|
2982 | set_signals(FALSE);
|
---|
2983 | log_to_screen("Restore log (%s) copied to /var/log on your hard disk", MONDO_LOGFILE);
|
---|
2984 | log_to_screen("Mondo-restore is exiting (retval=%d) ", retval);
|
---|
2985 |
|
---|
2986 | mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
|
---|
2987 | run_program_and_log_output(tmp, 5);
|
---|
2988 | mr_free(tmp);
|
---|
2989 |
|
---|
2990 | paranoid_free(mountlist);
|
---|
2991 | paranoid_free(raidlist);
|
---|
2992 | if (am_I_in_disaster_recovery_mode()) {
|
---|
2993 | run_program_and_log_output("mount / -o remount,rw", 2);
|
---|
2994 | } // for b0rken distros
|
---|
2995 | if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) {
|
---|
2996 | mr_asprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
|
---|
2997 | paranoid_system(tmp);
|
---|
2998 | mr_free(tmp);
|
---|
2999 | }
|
---|
3000 | paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
|
---|
3001 | free_libmondo_global_strings(); // it's fine to have this here :) really :)
|
---|
3002 |
|
---|
3003 | unlink("/tmp/filelist.full");
|
---|
3004 | unlink("/tmp/filelist.full.gz");
|
---|
3005 |
|
---|
3006 | exit(retval);
|
---|
3007 | }
|
---|
3008 |
|
---|
3009 | /**************************************************************************
|
---|
3010 | *END_MAIN *
|
---|
3011 | **************************************************************************/
|
---|
3012 |
|
---|
3013 |
|
---|
3014 |
|
---|
3015 |
|
---|
3016 |
|
---|
3017 | /**************************************************************************
|
---|
3018 | *END_MONDO-RESTORE.C *
|
---|
3019 | **************************************************************************/
|
---|