source: MondoRescue/branches/3.0/mondo/src/mondorestore/mondorestore.c@ 3145

Last change on this file since 3145 was 3145, checked in by Bruno Cornec, 11 years ago

r5361@localhost: bruno | 2013-06-14 12:18:21 +0200

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