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

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