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

Last change on this file since 2287 was 2287, checked in by Bruno Cornec, 15 years ago

r3289@localhost: bruno | 2009-07-21 15:12:29 +0200

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