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

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

r3327@localhost: bruno | 2009-08-04 00:17:46 +0200
popup_and_get_string and build_partition_name now return an allocated string

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