source: MondoRescue/branches/2.2.10/mondo/src/mondorestore/mondorestore.c@ 2326

Last change on this file since 2326 was 2326, checked in by Bruno Cornec, 15 years ago

r3337@localhost: bruno | 2009-08-11 20:02:18 +0200
bkpinfo->boot_device and bkpinfo->zip_exe are now dynamically allocated

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