source: MondoRescue/branches/3.3/mondo/src/mondorestore/mondorestore.c@ 3879

Last change on this file since 3879 was 3879, checked in by Bruno Cornec, 3 months ago

Fix all remaining compiler errors

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