source: MondoRescue/branches/2.2.2/mondo/src/mondorestore/mondo-restore.c@ 1295

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