source: MondoRescue/branches/2.2.10/mondo/src/mondorestore/mondorestore.c@ 2296

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