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

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

gettext reviewed + french messages updated (half done)

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