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

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

Fix #194

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