source: MondoRescue/trunk/mondo/mondo/mondorestore/mondo-restore.c@ 815

Last change on this file since 815 was 815, checked in by Bruno Cornec, 18 years ago

merge -r807:814 $SVN_M/branches/stable

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