source: MondoRescue/branches/2.2.6/mondo/src/mondorestore/mondorestore.c@ 1967

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