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

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

merge -r978:1042 $SVN_M/branches/stable

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