source: MondoRescue/branches/2.2.8/mondo/src/mondorestore/mondorestore.c@ 2072

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