source: MondoRescue/branches/stable/mondo/src/mondorestore/mondorestore.c@ 1202

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

Typo again

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