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

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