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

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

wait_until_software_raids_are_prepped function has now only 1 parameter (the other was useless)

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