source: MondoRescue/branches/2.2.9/mondo/src/mondorestore/mondorestore.c@ 2209

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