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

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

Fond ?

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