source: MondoRescue/branches/2.2.5/mondo/src/mondorestore/mondo-restore.c@ 1533

Last change on this file since 1533 was 1453, checked in by Bruno Cornec, 17 years ago

Fix #114

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