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

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

r5345@localhost: bruno | 2013-06-13 12:46:54 +0200

  • Solving #702 by adding a -F option which is meant to be used especially when mondoarchive is launched from cron, to avoid going into a loop where mondoarchive asks questions to the admin, where they cannot be answerd, which fills the logs and the underlying file system. With -F mondoarchive will exits at the first interaction request instead.
  • Property svn:keywords set to Id
File size: 98.2 KB
Line 
1/***************************************************************************
2$Id: mondorestore.c 3141 2013-06-13 16:05:57Z 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 3141 2013-06-13 16:05:57Z 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 " errctl= 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 (g_getfattr) {
1802 log_msg(1, "Setting fattr list %s", xattr_fname);
1803 if (length_of_file(xattr_fname) > 0) {
1804 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1805 if (res) {
1806 log_to_screen
1807 ("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
1820 ("Errors occurred while setting access control lists");
1821 } else {
1822 log_msg(1, "I set ACL OK");
1823 }
1824 retval += res;
1825 }
1826 }
1827 if (retval) {
1828 mr_asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
1829 paranoid_system(command);
1830 paranoid_free(command);
1831
1832 log_msg(2, "Errors occurred while processing fileset #%d",
1833 current_tarball_number);
1834 } else {
1835 log_msg(2, "Fileset #%d processed OK", current_tarball_number);
1836 }
1837 }
1838 if (does_file_exist("/PAUSE")) {
1839 popup_and_OK
1840 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
1841 }
1842 unlink(filelist_subset_fname);
1843 unlink(xattr_fname);
1844 unlink(acl_fname);
1845 unlink(temp_log);
1846
1847 leave_sub:
1848 paranoid_free(tmp);
1849 paranoid_free(filelist_name);
1850 paranoid_free(filelist_subset_fname);
1851 paranoid_free(executable);
1852 paranoid_free(temp_log);
1853 paranoid_free(xattr_fname);
1854 paranoid_free(acl_fname);
1855 log_msg(5, "Leaving");
1856 return (retval);
1857}
1858
1859/**************************************************************************
1860 *END_RESTORE_A_TARBALL_FROM_CD *
1861 **************************************************************************/
1862
1863
1864/**
1865 * Restore a tarball from the currently opened stream.
1866 * @param bkpinfo The backup information structure. Fields used:
1867 * - @c bkpinfo->backup_media_type
1868 * - @c bkpinfo->media_device
1869 * - @c bkpinfo->zip_exe
1870 * @param tarball_fname The filename of the afioball to restore.
1871 * @param current_tarball_number The number (starting from 0) of the fileset
1872 * we're restoring now.
1873 * @param filelist The node structure containing the list of files to be
1874 * restored. If no file in the afioball is in this list, afio will still be
1875 * called, but nothing will be written.
1876 * @param size The size (in @b bytes) of the afioball.
1877 * @return 0 for success, nonzero for failure.
1878 */
1879int
1880restore_a_tarball_from_stream(char *tarball_fname,
1881 long current_tarball_number,
1882 struct s_node *filelist,
1883 long long size, char *xattr_fname,
1884 char *acl_fname)
1885{
1886 int retval = 0;
1887 int res = 0;
1888
1889 /** malloc add ***/
1890 char *tmp;
1891 char *mds = NULL;
1892 char *command;
1893 char *afio_fname;
1894 char *filelist_fname;
1895 char *filelist_subset_fname;
1896 char *executable;
1897 long matches = 0;
1898 bool restore_this_fileset = FALSE;
1899 bool use_star;
1900
1901 assert(bkpinfo != NULL);
1902 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1903 malloc_string(filelist_subset_fname);
1904 malloc_string(filelist_fname);
1905 malloc_string(afio_fname);
1906 malloc_string(executable);
1907 malloc_string(command);
1908 malloc_string(tmp);
1909 filelist_subset_fname[0] = '\0';
1910 /* to do it with a file... */
1911 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1912 mds = media_descriptor_string(bkpinfo->backup_media_type);
1913 sprintf(tmp,
1914 "Restoring from fileset #%ld (%ld KB) on %s #%d",
1915 current_tarball_number, (long) size >> 10, mds, g_current_media_number);
1916 mr_free(mds);
1917
1918 log_msg(2, tmp);
1919 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
1920
1921 /****************************************************************************
1922 * Use RAMDISK's /tmp; saves time; oh wait, it's too small *
1923 * Well, pipe from tape to afio, then; oh wait, can't do that either: bug *
1924 * in afio or someting; oh darn.. OK, use tmpfs :-) *
1925 ****************************************************************************/
1926 filelist_fname[0] = filelist_subset_fname[0] = '\0';
1927 sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
1928 current_tarball_number);
1929 sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
1930 current_tarball_number);
1931 sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
1932 bkpinfo->tmpdir, current_tarball_number);
1933// sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
1934 res = read_file_from_stream_to_file(afio_fname, size);
1935 if (strstr(tarball_fname, ".star")) {
1936 bkpinfo->use_star = TRUE;
1937 }
1938 if (res) {
1939 log_msg(1, "Warning - error reading afioball from tape");
1940 }
1941 if (bkpinfo->compression_level == 0) {
1942 executable[0] = '\0';
1943 } else {
1944 if (bkpinfo->use_star) {
1945 strcpy(executable, " -bz");
1946 } else {
1947 sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
1948 }
1949 }
1950
1951 if (!filelist) // if unconditional restore then restore entire fileset
1952 {
1953 restore_this_fileset = TRUE;
1954 } else // If restoring selectively then get TOC from tarball
1955 {
1956 if (strstr(tarball_fname, ".star.")) {
1957 use_star = TRUE;
1958 sprintf(command, "star -sparse -t file=%s %s", afio_fname, executable);
1959 } else {
1960 use_star = FALSE;
1961 sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
1962 executable, afio_fname);
1963 }
1964 sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
1965 MONDO_LOGFILE);
1966 log_msg(1, "command = %s", command);
1967 if (system(command)) {
1968 log_msg(4, "Warning - error occurred while retrieving TOC");
1969 }
1970 if ((matches =
1971 save_filelist_entries_in_common(filelist_fname, filelist,
1972 filelist_subset_fname,
1973 use_star))
1974 <= 0 || length_of_file(filelist_subset_fname) < 2) {
1975 if (length_of_file(filelist_subset_fname) < 2) {
1976 log_msg(1, "No matches found in fileset %ld",
1977 current_tarball_number);
1978 }
1979 sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
1980 log_msg(2, tmp);
1981 restore_this_fileset = FALSE;
1982 } else {
1983 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
1984 matches, current_tarball_number,
1985 filelist_subset_fname);
1986 restore_this_fileset = TRUE;
1987 }
1988 }
1989
1990// Concoct the call to star/afio to restore files
1991 if (strstr(tarball_fname, ".star.")) // star
1992 {
1993 sprintf(command, "star -sparse -x file=%s %s", afio_fname, executable);
1994 if (filelist) {
1995 sprintf(command + strlen(command), " list=%s",
1996 filelist_subset_fname);
1997 }
1998 } else // afio
1999 {
2000 sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
2001 executable);
2002 if (filelist) {
2003 sprintf(command + strlen(command), " -w %s",
2004 filelist_subset_fname);
2005 }
2006 sprintf(command + strlen(command), " %s", afio_fname);
2007 }
2008 sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
2009
2010// Call if IF there are files to restore (selectively/unconditionally)
2011 if (restore_this_fileset) {
2012 log_msg(1, "Calling command='%s'", command);
2013 paranoid_system(command);
2014
2015 if (g_getfattr) {
2016 log_it("Restoring xattr stuff");
2017 res = set_fattr_list(filelist_subset_fname, xattr_fname);
2018 if (res) {
2019 log_msg(1, "Errors occurred while setting xattr");
2020 } else {
2021 log_msg(1, "I set xattr OK");
2022 }
2023 retval += res;
2024 }
2025
2026 if (g_getfacl) {
2027 log_it("Restoring acl stuff");
2028 res = set_acl_list(filelist_subset_fname, acl_fname);
2029 if (res) {
2030 log_msg(1, "Errors occurred while setting ACL");
2031 } else {
2032 log_msg(1, "I set ACL OK");
2033 }
2034 retval += res;
2035 }
2036
2037 } else {
2038 log_msg(1, "NOT CALLING '%s'", command);
2039 }
2040
2041 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
2042 log_to_screen("Paused after set %ld", current_tarball_number);
2043 popup_and_OK("Pausing. Press ENTER to continue.");
2044 }
2045
2046 unlink(filelist_subset_fname);
2047 unlink(filelist_fname);
2048 unlink(afio_fname);
2049
2050 paranoid_free(filelist_subset_fname);
2051 paranoid_free(filelist_fname);
2052 paranoid_free(afio_fname);
2053 paranoid_free(command);
2054 paranoid_free(tmp);
2055 return (retval);
2056}
2057
2058/**************************************************************************
2059 *END_RESTORE_A_TARBALL_FROM_STREAM *
2060 **************************************************************************/
2061
2062
2063
2064
2065/**
2066 * Restore all biggiefiles from all media in this CD backup.
2067 * The CD with the last afioball should be currently mounted.
2068 * @param bkpinfo The backup information structure. @c backup_media_type is the
2069 * only field used in this function.
2070 * @param filelist The node structure containing the list of files to be
2071 * restored. If a prospective biggiefile is not in this list, it will be ignored.
2072 * @return 0 for success, nonzero for failure.
2073 */
2074int
2075restore_all_biggiefiles_from_CD(struct s_node *filelist)
2076{
2077 int retval = 0;
2078 int res = 0;
2079 long noof_biggiefiles, bigfileno = 0, total_slices;
2080 /** malloc **/
2081 char *tmp;
2082 char *mds = NULL;
2083 bool just_changed_cds = FALSE;
2084 char *xattr_fname;
2085 char *acl_fname;
2086 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes
2087 char *pathname_of_last_biggie_restored;
2088 FILE *fbw = NULL;
2089
2090 malloc_string(xattr_fname);
2091 malloc_string(acl_fname);
2092 malloc_string(tmp);
2093 malloc_string(biggies_whose_EXATs_we_should_set);
2094 malloc_string(pathname_of_last_biggie_restored);
2095 assert(bkpinfo != NULL);
2096
2097 sprintf(biggies_whose_EXATs_we_should_set,
2098 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2099 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2100 log_msg(1, "Warning - cannot openout %s",
2101 biggies_whose_EXATs_we_should_set);
2102 }
2103
2104 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2105 total_slices = atol(tmp);
2106 sprintf(tmp, "Reassembling large files ");
2107 mvaddstr_and_log_it(g_currentY, 0, tmp);
2108 if (length_of_file(BIGGIELIST) < 6) {
2109 log_msg(1, "OK, no biggielist; not restoring biggiefiles");
2110 return (0);
2111 }
2112 noof_biggiefiles = count_lines_in_file(BIGGIELIST);
2113 if (noof_biggiefiles <= 0) {
2114 log_msg(2,
2115 "OK, no biggiefiles in biggielist; not restoring biggiefiles");
2116 return (0);
2117 }
2118 sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2119 noof_biggiefiles);
2120 log_msg(2, tmp);
2121
2122 open_progress_form("Reassembling large files",
2123 "I am now reassembling all the large files.",
2124 "Please wait. This may take some time.",
2125 "", total_slices);
2126 for (bigfileno = 0 ; bigfileno < noof_biggiefiles ;) {
2127 log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
2128 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
2129 log_msg(3,
2130 "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
2131 mds = media_descriptor_string(bkpinfo->backup_media_type);
2132 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
2133 bigfileno + 1, mds,
2134 g_current_media_number);
2135 log_msg(3, "Slicename would have been %s",
2136 slice_fname(bigfileno, 0, ARCHIVES_PATH, ""));
2137 // I'm not positive 'just_changed_cds' is even necessary...
2138 if (just_changed_cds) {
2139 just_changed_cds = FALSE;
2140 log_msg(3,
2141 "I'll continue to scan this CD for bigfiles to be restored.");
2142 } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
2143 insist_on_this_cd_number(++g_current_media_number);
2144 sprintf(tmp, "Restoring from %s #%d", mds,
2145 g_current_media_number);
2146 log_to_screen(tmp);
2147 just_changed_cds = TRUE;
2148 } else {
2149 /* That big file doesn't exist, but the followings may */
2150 /* So we need to continue looping */
2151 log_msg(2, "There was no bigfile #%ld. That's OK.",
2152 bigfileno + 1);
2153 log_msg(2, "I'm going to stop restoring bigfiles now.");
2154 retval++;
2155 bigfileno++;
2156 }
2157 mr_free(mds);
2158 } else {
2159 just_changed_cds = FALSE;
2160 sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
2161 update_progress_form(tmp);
2162 res =
2163 restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored);
2164 log_it("%s",pathname_of_last_biggie_restored);
2165 if (fbw && pathname_of_last_biggie_restored[0]) {
2166 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2167 }
2168 retval += res;
2169 bigfileno++;
2170
2171 }
2172 }
2173
2174 if (fbw) {
2175 fclose(fbw);
2176 if (g_getfattr) {
2177 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2178 if (length_of_file(xattr_fname) > 0) {
2179 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2180 }
2181 }
2182 if (g_getfacl) {
2183 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2184 if (length_of_file(acl_fname) > 0) {
2185 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2186 }
2187 }
2188 }
2189 if (does_file_exist("/PAUSE")) {
2190 popup_and_OK
2191 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2192 }
2193 close_progress_form();
2194 if (retval) {
2195 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2196 } else {
2197 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2198 }
2199 paranoid_free(xattr_fname);
2200 paranoid_free(acl_fname);
2201 paranoid_free(tmp);
2202 paranoid_free(biggies_whose_EXATs_we_should_set);
2203 paranoid_free(pathname_of_last_biggie_restored);
2204 return (retval);
2205}
2206
2207/**************************************************************************
2208 *END_RESTORE_ALL_BIGGIFILES_FROM_CD *
2209 **************************************************************************/
2210
2211
2212
2213/**
2214 * Restore all afioballs from all CDs in the backup.
2215 * The first CD should be inserted (if not, it will be asked for).
2216 * @param bkpinfo The backup information structure. @c backup_media_type is the
2217 * only field used in @e this function.
2218 * @param filelist The node structure containing the list of files to be
2219 * restored. If no file in some particular afioball is in this list, afio will
2220 * still be called for that fileset, but nothing will be written.
2221 * @return 0 for success, or the number of filesets that failed.
2222 */
2223int
2224restore_all_tarballs_from_CD(struct s_node *filelist)
2225{
2226 int retval = 0;
2227 int res;
2228 int attempts;
2229 long current_tarball_number = 0;
2230 long max_val;
2231 /**malloc ***/
2232 char *tmp = NULL;
2233 char *mds = NULL;
2234 char *tmp1 = NULL;
2235 char *tarball_fname;
2236 char *progress_str;
2237 char *comment;
2238
2239 malloc_string(tmp);
2240 malloc_string(tarball_fname);
2241 malloc_string(progress_str);
2242 malloc_string(comment);
2243
2244 assert(bkpinfo != NULL);
2245
2246 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2247 log_msg(2,
2248 "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER");
2249 if (g_current_media_number != 1) {
2250 log_msg(3, "OK, that's jacked up.");
2251 g_current_media_number = 1;
2252 }
2253 insist_on_this_cd_number(g_current_media_number);
2254 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2255 max_val = atol(tmp) + 1;
2256 paranoid_free(tmp);
2257
2258 mds = media_descriptor_string(bkpinfo->backup_media_type);
2259 sprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);
2260
2261 log_to_screen(progress_str);
2262 open_progress_form("Restoring from archives",
2263 "Restoring data from the archives.",
2264 "Please wait. This may take some time.",
2265 progress_str, max_val);
2266 for (;;) {
2267 insist_on_this_cd_number(g_current_media_number);
2268 update_progress_form(progress_str);
2269 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
2270 current_tarball_number);
2271 if (!does_file_exist(tarball_fname)) {
2272 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz",
2273 current_tarball_number);
2274 }
2275 if (!does_file_exist(tarball_fname)) {
2276 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
2277 current_tarball_number);
2278 }
2279 if (!does_file_exist(tarball_fname)) {
2280 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
2281 current_tarball_number);
2282 }
2283 if (!does_file_exist(tarball_fname)) {
2284 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
2285 current_tarball_number);
2286 }
2287 if (!does_file_exist(tarball_fname)) {
2288 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
2289 current_tarball_number);
2290 }
2291 if (!does_file_exist(tarball_fname)) {
2292 if (current_tarball_number == 0) {
2293 log_to_screen
2294 ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
2295 return (0);
2296 }
2297 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2298 || system("find " MNT_CDROM
2299 "/archives/slice* > /dev/null 2> /dev/null") ==
2300 0) {
2301 break;
2302 }
2303 g_current_media_number++;
2304 sprintf(progress_str, "Restoring from %s #%d",
2305 media_descriptor_string(bkpinfo->backup_media_type),
2306 g_current_media_number);
2307 log_to_screen(progress_str);
2308 } else {
2309 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
2310 current_tarball_number, mds, g_current_media_number);
2311// log_msg(3, "progress_str = %s", progress_str);
2312 for (res = 999, attempts = 0; attempts < 3 && res != 0;
2313 attempts++) {
2314 res =
2315 restore_a_tarball_from_CD(tarball_fname,
2316 current_tarball_number,
2317 filelist);
2318 }
2319 mr_asprintf(&tmp1, "%s #%d, fileset #%ld - restore ",
2320 mds, g_current_media_number, current_tarball_number);
2321 if (res) {
2322 mr_strcat(tmp1, "reported errors");
2323 } else if (attempts > 1) {
2324 mr_strcat(tmp1, "succeeded");
2325 } else {
2326 mr_strcat(tmp1, "succeeded");
2327 }
2328 if (attempts > 1) {
2329 mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
2330 }
2331 strcpy(comment, tmp1);
2332 paranoid_free(tmp1);
2333 if (attempts > 1) {
2334 log_to_screen(comment);
2335 }
2336
2337 retval += res;
2338 current_tarball_number++;
2339 g_current_progress++;
2340 }
2341 /* Now we need to umount the current media to have the next mounted by insist_on_this_cd_number */
2342 /* run_program_and_log_output("umount " MNT_CDROM, FALSE); */
2343 }
2344 mr_free(mds);
2345
2346 close_progress_form();
2347 if (retval) {
2348 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2349 } else {
2350 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2351 }
2352 paranoid_free(tarball_fname);
2353 paranoid_free(progress_str);
2354 paranoid_free(comment);
2355
2356 return (retval);
2357}
2358
2359/**************************************************************************
2360 *END_RESTORE_ALL_TARBALLS_FROM_CD *
2361 **************************************************************************/
2362
2363
2364
2365/**
2366 * Restore all biggiefiles from the currently opened stream.
2367 * @param bkpinfo The backup information structure. Passed to other functions.
2368 * @param filelist The node structure containing the list of files to be
2369 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2370 * @return 0 for success, or the number of biggiefiles that failed.
2371 */
2372int
2373restore_all_biggiefiles_from_stream(struct s_node *filelist)
2374{
2375 long noof_biggiefiles;
2376 long current_bigfile_number = 0;
2377 long total_slices;
2378
2379 int retval = 0;
2380 int res = 0;
2381 int ctrl_chr;
2382
2383 /** malloc add ****/
2384 char *tmp;
2385 char *biggie_fname;
2386 char *biggie_cksum;
2387 char *xattr_fname;
2388 char *acl_fname;
2389 char *p;
2390 char *pathname_of_last_biggie_restored;
2391 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes
2392 long long biggie_size;
2393 FILE *fbw = NULL;
2394
2395 malloc_string(tmp);
2396 malloc_string(biggie_fname);
2397 malloc_string(biggie_cksum);
2398 malloc_string(xattr_fname);
2399 malloc_string(acl_fname);
2400 malloc_string(biggies_whose_EXATs_we_should_set);
2401 malloc_string(pathname_of_last_biggie_restored);
2402 assert(bkpinfo != NULL);
2403
2404 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2405
2406 total_slices = atol(tmp);
2407 sprintf(tmp, "Reassembling large files ");
2408 if (g_getfattr) {
2409 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2410 }
2411 if (g_getfacl) {
2412 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2413 }
2414 mvaddstr_and_log_it(g_currentY, 0, tmp);
2415 sprintf(biggies_whose_EXATs_we_should_set,
2416 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2417 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2418 log_msg(1, "Warning - cannot openout %s",
2419 biggies_whose_EXATs_we_should_set);
2420 }
2421// get xattr and acl files if they're there
2422 res =
2423 read_header_block_from_stream(&biggie_size, biggie_fname,
2424 &ctrl_chr);
2425 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2426 res = read_EXAT_files_from_tape(&biggie_size, biggie_fname,
2427 &ctrl_chr, xattr_fname, acl_fname);
2428 }
2429
2430 noof_biggiefiles = atol(biggie_fname);
2431 sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2432 noof_biggiefiles);
2433 log_msg(2, tmp);
2434 open_progress_form("Reassembling large files",
2435 "I am now reassembling all the large files.",
2436 "Please wait. This may take some time.",
2437 "", total_slices);
2438
2439 for (res =
2440 read_header_block_from_stream(&biggie_size, biggie_fname,
2441 &ctrl_chr);
2442 ctrl_chr != BLK_STOP_BIGGIEFILES;
2443 res =
2444 read_header_block_from_stream(&biggie_size, biggie_fname,
2445 &ctrl_chr)) {
2446 if (ctrl_chr != BLK_START_A_NORMBIGGIE
2447 && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2448 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2449 }
2450 p = strrchr(biggie_fname, '/');
2451 if (!p) {
2452 p = biggie_fname;
2453 } else {
2454 p++;
2455 }
2456 sprintf(tmp, "Restoring big file %ld (%lld K)",
2457 current_bigfile_number + 1, biggie_size / 1024);
2458 update_progress_form(tmp);
2459 res = restore_a_biggiefile_from_stream(biggie_fname,
2460 current_bigfile_number,
2461 biggie_cksum,
2462 biggie_size,
2463 filelist, ctrl_chr,
2464 pathname_of_last_biggie_restored);
2465 log_msg(1, "I believe I have restored %s",
2466 pathname_of_last_biggie_restored);
2467 if (fbw && pathname_of_last_biggie_restored[0]) {
2468 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2469 }
2470 retval += res;
2471 current_bigfile_number++;
2472
2473 }
2474 if (current_bigfile_number != noof_biggiefiles
2475 && noof_biggiefiles != 0) {
2476 sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
2477 current_bigfile_number, noof_biggiefiles);
2478 } else {
2479 sprintf(tmp,
2480 "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
2481 noof_biggiefiles, current_bigfile_number);
2482 }
2483 log_msg(1, tmp);
2484
2485 if (fbw) {
2486 fclose(fbw);
2487 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
2488 log_it("Setting biggie-EXATs");
2489 if (g_getfattr) {
2490 if (length_of_file(xattr_fname) > 0) {
2491 log_msg(1, "set_fattr_List(%s,%s)",
2492 biggies_whose_EXATs_we_should_set, xattr_fname);
2493 set_fattr_list(biggies_whose_EXATs_we_should_set,
2494 xattr_fname);
2495 }
2496 }
2497 if (g_getfacl) {
2498 if (length_of_file(acl_fname) > 0) {
2499 log_msg(1, "set_acl_list(%s,%s)",
2500 biggies_whose_EXATs_we_should_set, acl_fname);
2501 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2502 }
2503 }
2504 } else {
2505 log_it("No biggiefiles selected. So, no biggie-EXATs to set.");
2506 }
2507 }
2508 if (does_file_exist("/PAUSE")) {
2509 popup_and_OK
2510 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2511 }
2512
2513 close_progress_form();
2514 if (retval) {
2515 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2516 } else {
2517 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2518 }
2519 paranoid_free(biggies_whose_EXATs_we_should_set);
2520 paranoid_free(pathname_of_last_biggie_restored);
2521 paranoid_free(biggie_fname);
2522 paranoid_free(biggie_cksum);
2523 paranoid_free(xattr_fname);
2524 paranoid_free(acl_fname);
2525 paranoid_free(tmp);
2526 return (retval);
2527}
2528
2529/**************************************************************************
2530 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM *
2531 **************************************************************************/
2532
2533
2534
2535
2536
2537
2538/**
2539 * Restore all afioballs from the currently opened tape stream.
2540 * @param bkpinfo The backup information structure. Fields used:
2541 * - @c bkpinfo->backup_media_type
2542 * - @c bkpinfo->restore_path
2543 * @param filelist The node structure containing the list of files to be
2544 * restored. If no file in an afioball is in this list, afio will still be
2545 * called for that fileset, but nothing will be written.
2546 * @return 0 for success, or the number of filesets that failed.
2547 */
2548int
2549restore_all_tarballs_from_stream(struct s_node *filelist)
2550{
2551 int retval = 0;
2552 int res;
2553 long current_afioball_number = 0;
2554 int ctrl_chr;
2555 long max_val /*, total_noof_files */ ;
2556
2557 /** malloc **/
2558 char *tmp;
2559 char *mds = NULL;
2560 char *progress_str;
2561 char *tmp_fname;
2562 char *xattr_fname;
2563 char *acl_fname;
2564
2565 long long tmp_size;
2566
2567 malloc_string(tmp);
2568 malloc_string(progress_str);
2569 malloc_string(tmp_fname);
2570 assert(bkpinfo != NULL);
2571 malloc_string(xattr_fname);
2572 malloc_string(acl_fname);
2573 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2574 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2575 max_val = atol(tmp) + 1;
2576
2577 if (chdir(bkpinfo->restore_path)) { /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
2578 //FIXME
2579 }
2580
2581 run_program_and_log_output("pwd", 5);
2582
2583 sprintf(progress_str, "Restoring from media #%d",
2584 g_current_media_number);
2585 log_to_screen(progress_str);
2586 open_progress_form("Restoring from archives",
2587 "Restoring data from the archives.",
2588 "Please wait. This may take some time.",
2589 progress_str, max_val);
2590
2591 log_msg(3, "hey");
2592
2593 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2594 if (res) {
2595 log_msg(2, "Warning - error reading afioball from tape");
2596 }
2597 retval += res;
2598 if (ctrl_chr != BLK_START_AFIOBALLS) {
2599 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
2600 }
2601 log_msg(2, "ho");
2602 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2603 while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2604 update_progress_form(progress_str);
2605 if (g_getfattr) {
2606 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
2607 current_afioball_number);
2608 unlink(xattr_fname);
2609 }
2610 if (g_getfacl) {
2611 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
2612 current_afioball_number);
2613 unlink(acl_fname);
2614 }
2615 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2616 log_it("Reading EXAT files from tape");
2617 res = read_EXAT_files_from_tape(&tmp_size, tmp_fname,
2618 &ctrl_chr, xattr_fname,
2619 acl_fname);
2620 }
2621 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2622 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2623 }
2624 sprintf(tmp,
2625 "Restoring from fileset #%ld (name=%s, size=%ld K)",
2626 current_afioball_number, tmp_fname, (long) tmp_size >> 10);
2627 res =
2628 restore_a_tarball_from_stream(tmp_fname,
2629 current_afioball_number,
2630 filelist, tmp_size, xattr_fname,
2631 acl_fname);
2632 retval += res;
2633 if (res) {
2634 sprintf(tmp, "Fileset %ld - errors occurred",
2635 current_afioball_number);
2636 log_to_screen(tmp);
2637 }
2638 res =
2639 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2640 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2641 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2642 }
2643
2644 current_afioball_number++;
2645 g_current_progress++;
2646 mds = media_descriptor_string(bkpinfo->backup_media_type),
2647 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
2648 current_afioball_number, mds,
2649 g_current_media_number);
2650 mr_free(mds);
2651 res =
2652 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2653 if (g_getfattr) {
2654 unlink(xattr_fname);
2655 }
2656 if (g_getfacl) {
2657 unlink(acl_fname);
2658 }
2659 } // next
2660 log_msg(1, "All done with afioballs");
2661 close_progress_form();
2662 if (retval) {
2663 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2664 } else {
2665 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2666 }
2667 paranoid_free(tmp);
2668 paranoid_free(progress_str);
2669 paranoid_free(tmp_fname);
2670 paranoid_free(xattr_fname);
2671 paranoid_free(acl_fname);
2672 return (retval);
2673}
2674
2675/**************************************************************************
2676 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM *
2677 **************************************************************************/
2678
2679/* @} - end of LLrestoreGroup */
2680
2681
2682/**
2683 * Restore all files in @p filelist.
2684 * @param bkpinfo The backup information structure. Most fields are used.
2685 * @param filelist The node structure containing the list of files to be
2686 * restored.
2687 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2688 * @ingroup restoreGroup
2689 */
2690int restore_everything(struct s_node *filelist)
2691{
2692 int resA;
2693 int resB;
2694
2695 /** mallco ***/
2696 char *cwd;
2697 char *newpath;
2698 char *tmp;
2699 assert(bkpinfo != NULL);
2700
2701 malloc_string(cwd);
2702 malloc_string(newpath);
2703 malloc_string(tmp);
2704 log_msg(2, "restore_everything() --- starting");
2705 g_current_media_number = 1;
2706 if (getcwd(cwd, MAX_STR_LEN - 1)) {
2707 // FIXME
2708 }
2709 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
2710 run_program_and_log_output(tmp, FALSE);
2711 log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
2712 if (chdir(bkpinfo->restore_path)) {
2713 //FIXME
2714 }
2715 if (getcwd(newpath, MAX_STR_LEN - 1)) {
2716 // FIXME
2717 }
2718 log_msg(1, "path is now %s", newpath);
2719 log_msg(1, "restoring everything");
2720 if (!find_home_of_exe("petris") && !g_text_mode) {
2721 newtDrawRootText(0, g_noof_rows - 2,
2722 "Press ALT-<left cursor> twice to play Petris :-) ");
2723 newtRefresh();
2724 }
2725 mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
2726 mount_media();
2727 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2728 mvaddstr_and_log_it(g_currentY++, 0,
2729 "Restoring OS and data from streaming media");
2730 if (bkpinfo->backup_media_type == cdstream) {
2731 openin_cdstream();
2732 } else {
2733 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
2734 openin_tape();
2735 }
2736 resA = restore_all_tarballs_from_stream(filelist);
2737 resB = restore_all_biggiefiles_from_stream(filelist);
2738 if (bkpinfo->backup_media_type == cdstream) {
2739 closein_cdstream();
2740 } else {
2741 closein_tape();
2742 }
2743 } else {
2744 mvaddstr_and_log_it(g_currentY++, 0,
2745 "Restoring OS and data from CD/USB ");
2746 resA = restore_all_tarballs_from_CD(filelist);
2747 resB = restore_all_biggiefiles_from_CD(filelist);
2748 }
2749 if (chdir(cwd)) {
2750 //FIXME
2751 }
2752 if (resA + resB) {
2753 log_to_screen("Errors occurred while data was being restored.");
2754 }
2755 if (length_of_file("/etc/raidtab") > 0) {
2756 log_msg(2, "Copying local raidtab to restored filesystem");
2757 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
2758 "/etc/raidtab", FALSE);
2759 }
2760 kill_petris();
2761 log_msg(2, "restore_everything() --- leaving");
2762 paranoid_free(cwd);
2763 paranoid_free(newpath);
2764 paranoid_free(tmp);
2765 return (resA + resB);
2766}
2767
2768/**************************************************************************
2769 *END_RESTORE_EVERYTHING *
2770 **************************************************************************/
2771
2772
2773extern void wait_until_software_raids_are_prepped(char *, int);
2774
2775
2776char which_restore_mode(void);
2777
2778
2779/**
2780 * Log a "don't panic" message to the logfile.
2781 */
2782void welcome_to_mondorestore()
2783{
2784 log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
2785 log_msg(0,
2786 "DON'T PANIC! Mondorestore logs almost everything, so please ");
2787 log_msg(0,
2788 "don't break out in a cold sweat just because you see a few ");
2789 log_msg(0,
2790 "error messages in the log. Read them; analyze them; see if ");
2791 log_msg(0,
2792 "they are significant; above all, verify your backups! Please");
2793 log_msg(0,
2794 "attach a compressed copy of this log to any e-mail you send ");
2795 log_msg(0,
2796 "to the Mondo mailing list when you are seeking technical ");
2797 log_msg(0,
2798 "support. Without it, we can't help you. - DevTeam");
2799 log_msg(0,
2800 "------------------------------------------------------------");
2801 log_msg(0,
2802 "BTW, despite (or perhaps because of) the wealth of messages,");
2803 log_msg(0,
2804 "some users are inclined to stop reading this log. If Mondo ");
2805 log_msg(0,
2806 "stopped for some reason, chances are it's detailed here. ");
2807 log_msg(0,
2808 "More than likely there's a message at the very end of this ");
2809 log_msg(0,
2810 "log that will tell you what is wrong. Please read it! ");
2811 log_msg(0,
2812 "------------------------------------------------------------");
2813}
2814
2815
2816
2817/**
2818 * Restore the user's data.
2819 * What did you think it did, anyway? :-)
2820 */
2821int main(int argc, char *argv[])
2822{
2823 FILE *fin;
2824 FILE *fout;
2825 int retval = 0;
2826 int res;
2827// int c;
2828 char *tmp;
2829
2830 struct mountlist_itself *mountlist;
2831 struct raidlist_itself *raidlist;
2832 struct s_node *filelist;
2833 char *a, *b;
2834 bool run_postnuke = FALSE;
2835
2836 if (getuid() != 0) {
2837 fprintf(stderr, "Please run as root.\r\n");
2838 exit(127);
2839 }
2840 if (!
2841 (bkpinfo = malloc(sizeof(struct s_bkpinfo)))) {
2842 fatal_error("Cannot malloc bkpinfo");
2843 }
2844 reset_bkpinfo();
2845
2846 g_loglevel = DEFAULT_MR_LOGLEVEL;
2847 malloc_string(tmp);
2848
2849/* Configure global variables */
2850#ifdef __FreeBSD__
2851 if (strstr
2852 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
2853 "textonly"))
2854#else
2855 if (strstr
2856 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
2857 "textonly"))
2858#endif
2859 {
2860 g_text_mode = TRUE;
2861 log_msg(1, "TEXTONLY MODE");
2862 } else {
2863 g_text_mode = FALSE;
2864 } // newt :-)
2865 if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
2866 fatal_error("Cannot malloc mountlist");
2867 }
2868 if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
2869 fatal_error("Cannot malloc raidlist");
2870 }
2871
2872 malloc_libmondo_global_strings();
2873
2874 strcpy(g_mondo_home,
2875 call_program_and_get_last_line_of_output("which mondorestore"));
2876 /*
2877 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
2878 make_hole_for_dir(g_tmpfs_mountpt);
2879 */
2880 g_current_media_number = 1; // precaution
2881
2882 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
2883
2884 malloc_string(a);
2885 malloc_string(b);
2886 setup_MR_global_filenames(); // malloc() and set globals, using bkpinfo->tmpdir etc.
2887 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
2888 bkpinfo->restore_data = TRUE; // Well, yeah :-)
2889 if (am_I_in_disaster_recovery_mode()) {
2890 run_program_and_log_output("mount / -o remount,rw", 2);
2891 } // for b0rken distros
2892 g_main_pid = getpid();
2893 srandom((int) (time(NULL)));
2894 set_signals(TRUE);
2895 g_kernel_version = get_kernel_version();
2896
2897 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
2898 if (strlen(g_mountlist_fname) < 3) {
2899 fatal_error
2900 ("Serious error in malloc()'ing. Could be a bug in your glibc.");
2901 }
2902 mkdir(MNT_CDROM, 0x770);
2903 make_hole_for_dir(MONDO_CACHE);
2904
2905 /* Backup original mountlist.txt */
2906 sprintf(tmp, "%s.orig", g_mountlist_fname);
2907 if (!does_file_exist(g_mountlist_fname)) {
2908 log_msg(2,
2909 "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
2910 __LINE__, g_mountlist_fname);
2911 } else if (!does_file_exist(tmp)) {
2912 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
2913 g_mountlist_fname);
2914 run_program_and_log_output(tmp, FALSE);
2915 }
2916
2917 /* Init directories */
2918 make_hole_for_dir("/var/log");
2919 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */
2920 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
2921 /*
2922 run_program_and_log_output("ln -sf /var/log/mondo-archive.log /tmp/mondorestore.log",
2923 FALSE);
2924 */
2925
2926 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
2927
2928 /* Init GUI */
2929 setup_newt_stuff(); /* call newtInit and setup screen log */
2930 welcome_to_mondorestore();
2931 if (bkpinfo->disaster_recovery) {
2932 log_msg(1, "I am in disaster recovery mode");
2933 } else {
2934 log_msg(1, "I am in normal, live mode");
2935 }
2936
2937 log_it("what time is it");
2938
2939 /* Process command-line parameters */
2940 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
2941#ifdef __FreeBSD__
2942 paranoid_system("mv -f /tmp/raidconf.txt /etc/raidtab");
2943 if (!does_file_exist("/etc/raidtab"))
2944 paranoid_system("vinum printconfig > /etc/raidtab");
2945#endif
2946 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2947 if (!does_file_exist(g_mountlist_fname)) {
2948 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2949 }
2950 res = let_user_edit_the_mountlist(mountlist, raidlist);
2951#ifdef __FreeBSD__
2952 paranoid_system("mv -f /etc/raidtab /tmp/raidconf.txt");
2953#endif
2954 paranoid_MR_finish(res);
2955 }
2956
2957 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
2958 fout = fopen("/tmp/out.txt", "w");
2959 fput_string_one_char_at_a_time(stderr, argv[2]);
2960 finish(0);
2961 }
2962
2963 if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
2964 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
2965 paranoid_system("mount " MNT_CDROM);
2966 }
2967 bkpinfo->compression_level = 1;
2968 g_current_media_number = 2;
2969 strcpy(bkpinfo->restore_path, "/tmp/TESTING");
2970 bkpinfo->backup_media_type = dvd;
2971 open_progress_form("Reassembling /dev/hda1",
2972 "Shark is a bit of a silly person.",
2973 "Please wait. This may take some time.",
2974 "", 1999);
2975 paranoid_system("rm -Rf /tmp/*pih*");
2976
2977 restore_a_biggiefile_from_CD(42, NULL, tmp);
2978 }
2979
2980 if (argc == 5 && strcmp(argv[1], "--common") == 0) {
2981 g_loglevel = 6;
2982 filelist = load_filelist(argv[2]);
2983 if (!filelist) {
2984 fatal_error("Failed to load filelist");
2985 }
2986 toggle_node_selection(filelist, FALSE);
2987 toggle_all_root_dirs_on(filelist);
2988 // BERLIOS: /usr/lib ???
2989 toggle_path_selection(filelist, "/usr/share", TRUE);
2990// show_filelist(filelist);
2991 save_filelist(filelist, "/tmp/out.txt");
2992// finish(0);
2993// toggle_path_selection (filelist, "/root/stuff", TRUE);
2994 strcpy(a, argv[3]);
2995 strcpy(b, argv[4]);
2996
2997 res = save_filelist_entries_in_common(a, filelist, b, FALSE);
2998 free_filelist(filelist);
2999 printf("res = %d", res);
3000 finish(0);
3001 }
3002
3003 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
3004 popup_changelist_from_file(argv[2]);
3005 paranoid_MR_finish(0);
3006 }
3007
3008 if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
3009 log_msg(1, "SCORE");
3010 g_loglevel = 10;
3011 if (strstr(argv[2], "save")) {
3012 log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
3013 fin = fopen(argv[3], "r");
3014 fout = fopen(argv[4], "w");
3015 copy_from_src_to_dest(fin, fout, 'w');
3016 fclose(fin);
3017 fin = fopen(argv[3], "r");
3018 copy_from_src_to_dest(fin, fout, 'w');
3019 fclose(fout);
3020 fclose(fin);
3021 } else if (strstr(argv[2], "restore")) {
3022 fout = fopen(argv[3], "w");
3023 fin = fopen(argv[4], "r");
3024 copy_from_src_to_dest(fout, fin, 'r');
3025 fclose(fin);
3026 fin = fopen(argv[4], "r");
3027 copy_from_src_to_dest(fout, fin, 'r');
3028 fclose(fout);
3029 fclose(fin);
3030 } else {
3031 fatal_error("Unknown additional param");
3032 }
3033 finish(0);
3034 }
3035
3036 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
3037 wait_until_software_raids_are_prepped(argv[2], 100);
3038 finish(0);
3039 }
3040
3041 if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
3042 finish(create_raidtab_from_mdstat(MDSTAT_FILE,argv[2]));
3043 }
3044
3045 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
3046 retval = run_grub(FALSE, "/dev/hda");
3047 if (retval) {
3048 log_to_screen("Failed to write Master Boot Record");
3049 }
3050 paranoid_MR_finish(0);
3051 }
3052 if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
3053 g_current_media_number = atoi(argv[2]);
3054 pause_and_ask_for_cdr(5, NULL);
3055 paranoid_MR_finish(0);
3056 }
3057 if ((argc == 2 && strcmp(argv[1], "--partition-only") == 0) && (bkpinfo->disaster_recovery)) {
3058 log_msg(0, "Partitioning only.");
3059 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3060 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3061 load_mountlist(mountlist, g_mountlist_fname);
3062 res = partition_everything(mountlist);
3063 finish(res);
3064 }
3065
3066 if ((argc == 2 && strcmp(argv[1], "--format-only") == 0) && (bkpinfo->disaster_recovery)) {
3067 log_msg(0, "Formatting only.");
3068 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3069 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3070 load_mountlist(mountlist, g_mountlist_fname);
3071 res = format_everything(mountlist, FALSE, raidlist);
3072 finish(res);
3073 }
3074
3075 if ((argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) && (bkpinfo->disaster_recovery)) {
3076 log_msg(0, "Stopping LVM and RAID");
3077 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3078 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3079 load_mountlist(mountlist, g_mountlist_fname);
3080 res = do_my_funky_lvm_stuff(TRUE, FALSE);
3081 res += stop_all_raid_devices(mountlist);
3082 finish(res);
3083 }
3084
3085 if ((argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) && (!bkpinfo->disaster_recovery)) {
3086 g_restoring_live_from_cd = TRUE;
3087 }
3088
3089 // Handle params here first
3090 handle_incoming_parameters(argc,argv);
3091
3092 if (!bkpinfo->disaster_recovery) { // live!
3093 log_msg(1, "I am in normal, live mode.");
3094 log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
3095 mount_boot_if_necessary(); /* for Gentoo users */
3096 log_msg(2, "Still here.");
3097 if (bkpinfo->backup_media_type == netfs) {
3098 g_restoring_live_from_netfs = TRUE;
3099 }
3100 log_msg(2, "Calling restore_to_live_filesystem()");
3101 retval = restore_to_live_filesystem();
3102
3103 log_msg(2, "Still here. Yay.");
3104 if ((strlen(bkpinfo->tmpdir) > 0) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
3105 sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
3106 run_program_and_log_output(tmp, FALSE);
3107 }
3108 unmount_boot_if_necessary(); /* for Gentoo users */
3109 paranoid_MR_finish(retval);
3110 } else {
3111 /* Disaster recovery mode (must be) */
3112 log_msg(1, "I must be in disaster recovery mode.");
3113 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
3114
3115 log_it("About to call load_mountlist and load_raidtab");
3116 strcpy(bkpinfo->restore_path, MNT_RESTORING);
3117 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
3118 retval = load_mountlist(mountlist, g_mountlist_fname);
3119 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3120 log_it("Returned from calling load_mountlist and load_raidtab successfully");
3121
3122 // BCO:To be reviewed
3123 if ((bkpinfo->restore_mode == compare) || (bkpinfo->restore_mode == nuke)) {
3124 if (bkpinfo->backup_media_type == netfs
3125 && !is_this_device_mounted(bkpinfo->netfs_mount)) {
3126 log_msg(1, "Mounting remote %s dir", bkpinfo->netfs_proto);
3127 sprintf(bkpinfo->isodir, "/tmp/isodir");
3128 run_program_and_log_output("mkdir -p /tmp/isodir", 5);
3129 if (strstr(bkpinfo->netfs_proto, "sshfs")) {
3130 if (bkpinfo->netfs_user) {
3131 sprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir",
3132 bkpinfo->netfs_user,bkpinfo->netfs_mount);
3133 } else {
3134 sprintf(tmp, "sshfs -o ro %s /tmp/isodir",
3135 bkpinfo->netfs_mount);
3136 }
3137 } else {
3138 if (strstr(bkpinfo->netfs_proto, "smbfs")) {
3139 if (bkpinfo->netfs_user) {
3140 sprintf(tmp, "mount -t cifs %s /tmp/isodir -o user=%s,nolock,ro ",
3141 bkpinfo->netfs_mount,bkpinfo->netfs_user);
3142 } else {
3143 sprintf(tmp, "mount -t cifs %s /tmp/isodir -o nolock,ro ",
3144 bkpinfo->netfs_mount);
3145 }
3146 } else {
3147 if (bkpinfo->netfs_user) {
3148 sprintf(tmp, "mount %s@%s -o nolock,ro /tmp/isodir",
3149 bkpinfo->netfs_user,bkpinfo->netfs_mount);
3150 } else {
3151 sprintf(tmp, "mount %s -o nolock,ro /tmp/isodir",
3152 bkpinfo->netfs_mount);
3153 }
3154 }
3155 }
3156 run_program_and_log_output(tmp, 1);
3157 }
3158 }
3159
3160 if (retval) {
3161 log_to_screen
3162 ("Warning - load_raidtab_into_raidlist returned an error");
3163 }
3164
3165 log_msg(1, "Send in the clowns.");
3166
3167
3168 if (bkpinfo->restore_mode == nuke) {
3169 log_it("nuking");
3170 retval += nuke_mode(mountlist, raidlist);
3171 } else if (bkpinfo->restore_mode == interactive) {
3172 log_it("catchall");
3173 retval += catchall_mode(mountlist, raidlist);
3174 } else if (bkpinfo->restore_mode == compare) {
3175 log_it("compare");
3176 retval += compare_mode(mountlist, raidlist);
3177 } else if (bkpinfo->restore_mode == isoonly) {
3178 log_it("iso");
3179 retval = iso_mode(mountlist, raidlist, FALSE);
3180 } else if (bkpinfo->restore_mode == mbr) {
3181 log_it("mbr");
3182 retval = mount_all_devices(mountlist, TRUE);
3183 if (!retval) {
3184 retval += run_boot_loader(FALSE);
3185 retval += unmount_all_devices(mountlist);
3186 }
3187 if (retval) {
3188 log_to_screen("Failed to write Master Boot Record");
3189 }
3190 } else if (bkpinfo->restore_mode == isonuke) {
3191 log_it("isonuke");
3192 retval = iso_mode(mountlist, raidlist, TRUE);
3193 } else {
3194 log_it("catchall (no mode specified in command-line call");
3195 retval += catchall_mode(mountlist, raidlist);
3196 }
3197 }
3198
3199 /* clean up at the end */
3200 if (retval) {
3201 if (does_file_exist(MONDO_CACHE"/changed.files")) {
3202 log_to_screen
3203 ("See "MONDO_CACHE"/changed.files for list of files that have changed.");
3204 }
3205 mvaddstr_and_log_it(g_currentY++,
3206 0,
3207 "Run complete. Errors were reported. Please review the logfile.");
3208 } else {
3209 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3210 mvaddstr_and_log_it(g_currentY++,
3211 0,
3212 "Run complete. Please remove media and reboot.");
3213 } else {
3214 run_program_and_log_output("sync", FALSE);
3215 if (is_this_device_mounted(MNT_CDROM)) {
3216 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
3217 }
3218
3219 if (!bkpinfo->please_dont_eject) {
3220 (void)eject_device("/dev/cdrom");
3221 }
3222 mvaddstr_and_log_it(g_currentY++,
3223 0,
3224 "Run complete. Please remove media and reboot.");
3225 }
3226 }
3227
3228// g_I_have_just_nuked is set true by nuke_mode() just before it returns
3229 if (!system("which post-nuke > /dev/null 2> /dev/null")) {
3230 log_msg(1, "post-nuke found; find out whether we should run it...");
3231 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
3232 run_postnuke = TRUE;
3233 log_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
3234 } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
3235 run_postnuke = TRUE;
3236 log_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
3237 } else {
3238 run_postnuke = FALSE;
3239 log_msg(1, "No, will not run post-nuke.");
3240 }
3241 } else {
3242 log_msg(1, "No post-nuke found.");
3243 }
3244 if (run_postnuke) {
3245 log_to_screen("Running post-nuke...");
3246 if (mount_all_devices(mountlist, TRUE)) {
3247 log_to_screen
3248 ("Unable to re-mount partitions for post-nuke stuff");
3249 } else {
3250 log_msg(1, "Re-mounted partitions for post-nuke stuff");
3251 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
3252 retval);
3253 log_msg(2, "Calling '%s'", tmp);
3254 if ((res = run_program_and_log_output(tmp, 0))) {
3255 log_OS_error(tmp);
3256 }
3257 log_msg(1, "post-nuke returned w/ res=%d", res);
3258 }
3259 unmount_all_devices(mountlist);
3260 log_to_screen("I've finished post-nuking.");
3261 }
3262
3263/*
3264 log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
3265 log_to_screen("Otherwise, please wait until the RAID disks are done.");
3266 wait_until_software_raids_are_prepped("/proc/mdstat", 100);
3267 log_to_screen("Thank you.");
3268*/
3269 unlink("/tmp/mondo-run-prog.tmp");
3270 set_signals(FALSE);
3271 log_to_screen("Restore log (%s) copied to /var/log on your hard disk", MONDO_LOGFILE);
3272 sprintf(tmp,
3273 "Mondo-restore is exiting (retval=%d) ",
3274 retval);
3275 log_to_screen(tmp);
3276 sprintf(tmp, "umount -d %s", bkpinfo->isodir);
3277 run_program_and_log_output(tmp, 5);
3278 paranoid_free(mountlist);
3279 paranoid_free(raidlist);
3280 if (am_I_in_disaster_recovery_mode()) {
3281 run_program_and_log_output("mount / -o remount,rw", 2);
3282 } // for b0rken distros
3283 if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) {
3284 sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
3285 paranoid_system(tmp);
3286 }
3287 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
3288 free_libmondo_global_strings(); // it's fine to have this here :) really :)
3289 paranoid_free(a);
3290 paranoid_free(b);
3291 paranoid_free(tmp);
3292
3293 unlink("/tmp/filelist.full");
3294 unlink("/tmp/filelist.full.gz");
3295
3296 exit(retval);
3297}
3298
3299/**************************************************************************
3300 *END_MAIN *
3301 **************************************************************************/
3302
3303
3304
3305
3306
3307/**************************************************************************
3308 *END_MONDO-RESTORE.C *
3309 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.