source: MondoRescue/branches/3.0/mondo/src/mondorestore/mondorestore.c@ 3098

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