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

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

r3335@localhost: bruno | 2009-08-08 23:04:12 +0200

  • Change mr_asprintf to avoid the need of pointer and be consistent with the other mr_mem functions
  • Property svn:keywords set to Id
File size: 94.4 KB
Line 
1/***************************************************************************
2$Id: mondorestore.c 2324 2009-08-18 13:13: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 2324 2009-08-18 13:13: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 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
972 if (!bkpinfo->media_device[0]) {
973 log_msg(2, "Warning - failed to find media dev");
974 }
975
976
977 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
978
979 open_evalcall_form("Thinking...");
980
981 get_cfg_file_from_archive_or_bust();
982 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
983 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo
984
985 close_evalcall_form();
986 retval = load_mountlist(mountlist, g_mountlist_fname);
987 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
988
989 if (!g_restoring_live_from_nfs && (filelist = process_filelist_and_biggielist())) {
990 save_filelist(filelist, "/tmp/selected-files.txt");
991 strcpy(old_restpath, bkpinfo->restore_path);
992 p = popup_and_get_string("Restore path", "Restore files to where? )", bkpinfo->restore_path);
993 if (p != NULL) {
994 strcpy(bkpinfo->restore_path, p);
995 mr_free(p);
996
997 log_it("Restoring everything");
998 retval += restore_everything(filelist);
999 free_filelist(filelist);
1000 strcpy(bkpinfo->restore_path, old_restpath);
1001 } else {
1002 free_filelist(filelist);
1003 }
1004 strcpy(bkpinfo->restore_path, old_restpath);
1005 } else {
1006 if (filelist != NULL) {
1007 retval += restore_everything(NULL);
1008 }
1009 }
1010 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1011 log_msg(2,
1012 "Tape : I don't need to unmount or eject the CD-ROM.");
1013 } else {
1014 run_program_and_log_output("umount " MNT_CDROM, FALSE);
1015 if (!bkpinfo->please_dont_eject) {
1016 eject_device(bkpinfo->media_device);
1017 }
1018 }
1019 run_program_and_log_output("umount " MNT_CDROM, FALSE);
1020 if (!bkpinfo->please_dont_eject) {
1021 eject_device(bkpinfo->media_device);
1022 }
1023 paranoid_free(old_restpath);
1024 free(mountlist);
1025 free(raidlist);
1026 return (retval);
1027}
1028
1029/**************************************************************************
1030 *END_RESTORE_TO_LIVE_FILESYSTEM *
1031 **************************************************************************/
1032
1033/* @} - end of restoreGroup */
1034
1035
1036#include <utime.h>
1037/**
1038 * @addtogroup LLrestoreGroup
1039 * @{
1040 */
1041/**
1042 * Restore biggiefile @p bigfileno from the currently mounted CD.
1043 * @param bkpinfo The backup information structure. Fields used:
1044 * - @c bkpinfo->backup_media_type
1045 * - @c bkpinfo->restore_path
1046 * @param bigfileno The biggiefile number (starting from 0) to restore.
1047 * @param filelist The node structure containing the list of files to restore.
1048 * If the biggiefile is not in this list, it will be skipped (return value will
1049 * still indicate success).
1050 * @return 0 for success (or skip), nonzero for failure.
1051 */
1052int
1053restore_a_biggiefile_from_CD(long bigfileno,
1054 struct s_node *filelist,
1055 char *pathname_of_last_file_restored)
1056{
1057 FILE *fin;
1058 FILE *fout;
1059 FILE *fbzip2;
1060
1061 /** malloc ***/
1062 char *checksum;
1063 char *outfile_fname = NULL;
1064 char *tmp = NULL;
1065 char *bzip2_command = NULL;
1066 char *ntfsprog_command, *suffix;
1067 char *sz_devfile = NULL;
1068 char *bigblk;
1069 char *p;
1070 char *mds = NULL;
1071 int retval = 0;
1072 int finished = FALSE;
1073 long sliceno;
1074 long siz;
1075 char ntfsprog_fifo[MAX_STR_LEN];
1076 char *file_to_openout = NULL;
1077 struct s_filename_and_lstat_info biggiestruct;
1078 struct utimbuf the_utime_buf, *ubuf;
1079 bool use_ntfsprog_hack = FALSE;
1080 pid_t pid;
1081 int res = 0;
1082 int old_loglevel;
1083 struct s_node *node;
1084
1085 old_loglevel = g_loglevel;
1086 ubuf = &the_utime_buf;
1087 assert(bkpinfo != NULL);
1088
1089 malloc_string(checksum);
1090 malloc_string(ntfsprog_command);
1091 malloc_string(suffix);
1092
1093 pathname_of_last_file_restored[0] = '\0';
1094 if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
1095 fatal_error("Cannot malloc bigblk");
1096 }
1097
1098 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
1099 log_to_screen("Cannot even open bigfile's info file");
1100 return (1);
1101 }
1102
1103 memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
1104 if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
1105 sizeof(biggiestruct)) {
1106 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
1107 bigfileno + 1);
1108 }
1109 paranoid_fclose(fin);
1110
1111 strcpy(checksum, biggiestruct.checksum);
1112
1113 if (!checksum[0]) {
1114 log_msg(3, "Warning - bigfile %ld does not have a checksum", bigfileno + 1);
1115 p = checksum;
1116 }
1117
1118 if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :)
1119 {
1120 mr_asprintf(outfile_fname, "%s", biggiestruct.filename);
1121 } else {
1122 mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename);
1123 }
1124
1125 /* skip file if we have a selective restore subset & it doesn't match */
1126 if (filelist != NULL) {
1127 node = find_string_at_node(filelist, biggiestruct.filename);
1128 if (!node) {
1129 log_msg(0, "Skipping %s (name isn't in filelist)",
1130 biggiestruct.filename);
1131 pathname_of_last_file_restored[0] = '\0';
1132 return (0);
1133 } else if (!(node->selected)) {
1134 log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1135 biggiestruct.filename);
1136 pathname_of_last_file_restored[0] = '\0';
1137 return (0);
1138 }
1139 }
1140 /* otherwise, continue */
1141
1142 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
1143 if (biggiestruct.use_ntfsprog) {
1144 if (strncmp(biggiestruct.filename, "/dev/", 5)) {
1145 log_msg(1,
1146 "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
1147 log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
1148 biggiestruct.use_ntfsprog = FALSE;
1149 }
1150 }
1151
1152 if (biggiestruct.use_ntfsprog) // if it's an NTFS device
1153// if (!strncmp ( biggiestruct.filename, "/dev/", 5))
1154 {
1155 g_loglevel = 4;
1156 use_ntfsprog_hack = TRUE;
1157 log_msg(2, "Calling ntfsclone in background because %s is an NTFS /dev entry", outfile_fname);
1158 mr_asprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), (int) (random() % 32768));
1159 mkfifo(sz_devfile, 0x770);
1160 strcpy(ntfsprog_fifo, sz_devfile);
1161 mr_free(sz_devfile);
1162 file_to_openout = ntfsprog_fifo;
1163 switch (pid = fork()) {
1164 case -1:
1165 fatal_error("Fork failure");
1166 case 0:
1167 log_msg(3,
1168 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
1169 biggiestruct.filename, ntfsprog_fifo);
1170 res =
1171 feed_outfrom_ntfsprog(biggiestruct.filename,
1172 ntfsprog_fifo);
1173// log_msg(3, "CHILD - fip - exiting");
1174 exit(res);
1175 break;
1176 default:
1177 log_msg(3,
1178 "feed_into_ntfsprog() called in background --- pid=%ld",
1179 (long int) (pid));
1180 }
1181 } else {
1182 use_ntfsprog_hack = FALSE;
1183 ntfsprog_fifo[0] = '\0';
1184 file_to_openout = outfile_fname;
1185 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
1186 {
1187 make_hole_for_file(outfile_fname);
1188 }
1189 }
1190
1191 log_msg(2, "Reassembling big file %ld (%s)", bigfileno + 1, outfile_fname);
1192
1193 /*
1194 last slice is zero-length and uncompressed; when we find it, we stop.
1195 We DON'T wait until there are no more slices; if we did that,
1196 We might stop at end of CD, not at last slice (which is 0-len and uncompd)
1197 */
1198
1199 strncpy(pathname_of_last_file_restored, biggiestruct.filename,
1200 MAX_STR_LEN - 1);
1201 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1202
1203 log_msg(3, "file_to_openout = %s", file_to_openout);
1204 if (!(fout = fopen(file_to_openout, "w"))) {
1205 log_to_screen("Cannot openout outfile_fname - hard disk full?");
1206 return (1);
1207 }
1208 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
1209
1210 for (sliceno = 1, finished = FALSE; !finished;) {
1211 if (!does_file_exist
1212 (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
1213 &&
1214 !does_file_exist(slice_fname
1215 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
1216 &&
1217 !does_file_exist(slice_fname
1218 (bigfileno, sliceno, ARCHIVES_PATH, "gz"))
1219 &&
1220 !does_file_exist(slice_fname
1221 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1222 log_msg(3,
1223 "Cannot find a data slice or terminator slice on CD %d",
1224 g_current_media_number);
1225 g_current_media_number++;
1226 mds = media_descriptor_string(bkpinfo->backup_media_type);
1227 log_msg(2, "Asking for %s #%d so that I may read slice #%ld\n", mds, g_current_media_number, sliceno);
1228 mr_free(mds);
1229
1230 log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
1231
1232 insist_on_this_cd_number(g_current_media_number);
1233 log_to_screen("Continuing to restore.");
1234 } else {
1235 mr_asprintf(tmp, "%s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
1236 if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
1237 log_msg(2,
1238 "End of bigfile # %ld (slice %ld is the terminator)",
1239 bigfileno + 1, sliceno);
1240 finished = TRUE;
1241 mr_free(tmp);
1242 continue;
1243 } else {
1244 if (does_file_exist
1245 (slice_fname
1246 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
1247 mr_asprintf(bzip2_command, "lzop");
1248 strcpy(suffix, "lzo");
1249 } else
1250 if (does_file_exist
1251 (slice_fname
1252 (bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
1253 mr_asprintf(bzip2_command, "gzip");
1254 strcpy(suffix, "gz");
1255 } else
1256 if (does_file_exist
1257 (slice_fname
1258 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1259 mr_asprintf(bzip2_command, "bzip2");
1260 strcpy(suffix, "bz2");
1261 } else
1262 if (does_file_exist
1263 (slice_fname
1264 (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
1265 mr_asprintf(bzip2_command, "");
1266 strcpy(suffix, "");
1267 } else {
1268 log_to_screen("OK, that's pretty fsck0red...");
1269 mr_free(tmp);
1270 return (1);
1271 }
1272 }
1273 mr_free(tmp);
1274 if (bzip2_command != NULL) {
1275 mr_strcat(bzip2_command, " -dc %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
1276 } else {
1277 mr_asprintf(bzip2_command, "cat %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
1278 }
1279 mds = media_descriptor_string(bkpinfo->backup_media_type);
1280 mr_asprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", mds, g_current_media_number, bigfileno + 1, sliceno);
1281 mr_free(mds);
1282 log_msg(2, tmp);
1283
1284 if (!g_text_mode) {
1285 newtDrawRootText(0, g_noof_rows - 2, tmp);
1286 newtRefresh();
1287 strip_spaces(tmp);
1288 update_progress_form(tmp);
1289 }
1290 mr_free(tmp);
1291
1292 if (!(fbzip2 = popen(bzip2_command, "r"))) {
1293 fatal_error("Can't run popen command");
1294 }
1295 mr_free(bzip2_command);
1296
1297 while (!feof(fbzip2)) {
1298 siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
1299 if (siz > 0) {
1300 siz = fwrite(bigblk, 1, siz, fout);
1301 }
1302 }
1303 paranoid_pclose(fbzip2);
1304
1305
1306 sliceno++;
1307 g_current_progress++;
1308 }
1309 }
1310 paranoid_fclose(fout);
1311 g_loglevel = old_loglevel;
1312
1313 if (use_ntfsprog_hack) {
1314 log_msg(3, "Waiting for ntfsclone to finish");
1315 mr_asprintf(tmp, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
1316 while (system(tmp) == 0) {
1317 sleep(1);
1318 }
1319 mr_free(tmp);
1320 log_it("OK, ntfsclone has really finished");
1321 }
1322
1323 if (strcmp(outfile_fname, "/dev/null")) {
1324 chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid);
1325 chmod(outfile_fname, biggiestruct.properties.st_mode);
1326 ubuf->actime = biggiestruct.properties.st_atime;
1327 ubuf->modtime = biggiestruct.properties.st_mtime;
1328 utime(outfile_fname, ubuf);
1329 }
1330 mr_free(outfile_fname);
1331 paranoid_free(bigblk);
1332 paranoid_free(checksum);
1333 paranoid_free(ntfsprog_command);
1334 paranoid_free(suffix);
1335
1336 return (retval);
1337}
1338
1339/**************************************************************************
1340 *END_ RESTORE_A_BIGGIEFILE_FROM_CD *
1341 **************************************************************************/
1342
1343
1344
1345/**
1346 * Restore a biggiefile from the currently opened stream.
1347 * @param bkpinfo The backup information structure. Fields used:
1348 * - @c bkpinfo->restore_path
1349 * - @c bkpinfo->zip_exe
1350 * @param orig_bf_fname The original filename of the biggiefile.
1351 * @param biggiefile_number The number of the biggiefile (starting from 0).
1352 * @param orig_checksum Unused.
1353 * @param biggiefile_size Unused.
1354 * @param filelist The node structure containing the list of files to be restored.
1355 * If @p orig_bf_fname is not in the list, it will be ignored.
1356 * @return 0 for success (or skip), nonzero for failure.
1357 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL).
1358 */
1359int restore_a_biggiefile_from_stream(char *orig_bf_fname, long biggiefile_number, char *orig_checksum, //UNUSED
1360 long long biggiefile_size, //UNUSED
1361 struct s_node *filelist,
1362 int use_ntfsprog,
1363 char *pathname_of_last_file_restored)
1364{
1365 FILE *pout;
1366 FILE *fin;
1367
1368 /** mallocs ********/
1369 char *tmp = NULL;
1370 char *tmp1 = NULL;
1371 char *command = NULL;
1372 char *outfile_fname = NULL;
1373 char *ntfsprog_command;
1374 char *sz_devfile = NULL;
1375 char *ntfsprog_fifo;
1376 char *file_to_openout = NULL;
1377
1378 struct s_node *node;
1379
1380 int old_loglevel;
1381 long current_slice_number = 0;
1382 int retval = 0;
1383 int res = 0;
1384 int ctrl_chr = '\0';
1385 long long slice_siz;
1386 bool dummy_restore = FALSE;
1387 bool use_ntfsprog_hack = FALSE;
1388 pid_t pid;
1389 struct s_filename_and_lstat_info biggiestruct;
1390 struct utimbuf the_utime_buf, *ubuf;
1391 ubuf = &the_utime_buf;
1392
1393 malloc_string(tmp);
1394 malloc_string(ntfsprog_fifo);
1395 malloc_string(ntfsprog_command);
1396 old_loglevel = g_loglevel;
1397 assert(bkpinfo != NULL);
1398 assert(orig_bf_fname != NULL);
1399 assert(orig_checksum != NULL);
1400
1401 pathname_of_last_file_restored[0] = '\0';
1402 if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
1403 use_ntfsprog = 1;
1404 log_msg(1, "%s --- pih=YES", orig_bf_fname);
1405 } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
1406 use_ntfsprog = 0;
1407 log_msg(1, "%s --- pih=NO", orig_bf_fname);
1408 } else {
1409 use_ntfsprog = 0;
1410 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
1411 }
1412
1413 strncpy(pathname_of_last_file_restored, orig_bf_fname,
1414 MAX_STR_LEN - 1);
1415 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1416
1417 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
1418
1419 if (filelist != NULL) {
1420 node = find_string_at_node(filelist, orig_bf_fname);
1421 if (!node) {
1422 dummy_restore = TRUE;
1423 log_msg(1,
1424 "Skipping big file %ld (%s) - not in biggielist subset",
1425 biggiefile_number + 1, orig_bf_fname);
1426 pathname_of_last_file_restored[0] = '\0';
1427 } else if (!(node->selected)) {
1428 dummy_restore = TRUE;
1429 log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1430 orig_bf_fname);
1431 pathname_of_last_file_restored[0] = '\0';
1432 }
1433 }
1434
1435 if (use_ntfsprog) {
1436 if (strncmp(orig_bf_fname, "/dev/", 5)) {
1437 log_msg(1,
1438 "I was in error when I set use_ntfsprog to TRUE.");
1439 log_msg(1, "%s isn't even in /dev", orig_bf_fname);
1440 use_ntfsprog = FALSE;
1441 }
1442 }
1443
1444 if (use_ntfsprog) {
1445 g_loglevel = 4;
1446 mr_asprintf(outfile_fname, "%s", orig_bf_fname);
1447 use_ntfsprog_hack = TRUE;
1448 log_msg(2, "Calling ntfsclone in background because %s is a /dev entry", outfile_fname);
1449 mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
1450 mkfifo(sz_devfile, 0x770);
1451 strcpy(ntfsprog_fifo, sz_devfile);
1452 mr_free(sz_devfile);
1453
1454 file_to_openout = ntfsprog_fifo;
1455 switch (pid = fork()) {
1456 case -1:
1457 fatal_error("Fork failure");
1458 case 0:
1459 log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", outfile_fname, ntfsprog_fifo);
1460 res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
1461 exit(res);
1462 break;
1463 default:
1464 log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
1465 }
1466 } else {
1467 if (!strncmp(orig_bf_fname, "/dev/", 5)) {
1468 // non-NTFS partition
1469 mr_asprintf(outfile_fname, "%s", orig_bf_fname);
1470 } else {
1471 // biggiefile
1472 mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname);
1473 }
1474 use_ntfsprog_hack = FALSE;
1475 ntfsprog_fifo[0] = '\0';
1476 file_to_openout = outfile_fname;
1477 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
1478 {
1479 make_hole_for_file(outfile_fname);
1480 }
1481 log_msg(2, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname);
1482 }
1483
1484 if (dummy_restore) {
1485 mr_free(outfile_fname);
1486 mr_asprintf(outfile_fname, "/dev/null");
1487 }
1488
1489 if (!bkpinfo->zip_exe[0]) {
1490 mr_asprintf(command, "cat > \"%s\"", file_to_openout);
1491 } else {
1492 mr_asprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE);
1493 if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
1494 /* Ignore SIGPIPE for gzip as it causes errors on big files
1495 * Cf: http://trac.mondorescue.org/ticket/244 */
1496 signal(SIGPIPE,SIG_IGN);
1497 }
1498 }
1499 log_msg(3, "Pipe command = '%s'", command);
1500
1501 /* restore biggiefile, one slice at a time */
1502 if (!(pout = popen(command, "w"))) {
1503 fatal_error("Cannot pipe out");
1504 }
1505 mr_free(command);
1506
1507 for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1508 ctrl_chr != BLK_STOP_A_BIGGIE;
1509 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
1510 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
1511 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
1512 }
1513 log_msg(2, "Working on file #%ld, slice #%ld ", biggiefile_number + 1, current_slice_number);
1514 if (!g_text_mode) {
1515 newtDrawRootText(0, g_noof_rows - 2, tmp);
1516 newtRefresh();
1517 }
1518 strip_spaces(tmp);
1519 update_progress_form(tmp);
1520 if (current_slice_number == 0) {
1521 res =
1522 read_file_from_stream_to_file("/tmp/biggie-blah.txt",
1523 slice_siz);
1524 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
1525 log_OS_error("blah blah");
1526 } else {
1527 if (fread
1528 ((void *) &biggiestruct, 1, sizeof(biggiestruct),
1529 fin) < sizeof(biggiestruct)) {
1530 log_msg(2,
1531 "Warning - unable to get biggiestruct of bigfile #%d",
1532 biggiefile_number + 1);
1533 }
1534 paranoid_fclose(fin);
1535 }
1536 } else {
1537 res =
1538 read_file_from_stream_to_stream(pout, slice_siz);
1539 }
1540 retval += res;
1541 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1542 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
1543 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
1544 }
1545 current_slice_number++;
1546 g_current_progress++;
1547 }
1548 paranoid_pclose(pout);
1549
1550 if (bkpinfo->zip_exe[0]) {
1551 if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
1552 /* Re-enable SIGPIPE for gzip */
1553 signal(SIGPIPE, terminate_daemon);
1554 }
1555 }
1556
1557 log_msg(1, "pathname_of_last_file_restored is now %s",
1558 pathname_of_last_file_restored);
1559
1560 if (use_ntfsprog_hack) {
1561 log_msg(3, "Waiting for ntfsclone to finish");
1562 mr_asprintf(tmp1, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
1563 while (system(tmp1) == 0) {
1564 sleep(1);
1565 }
1566 mr_free(tmp1);
1567 log_msg(3, "OK, ntfsclone has really finished");
1568 }
1569
1570 log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
1571 log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
1572 if (strcmp(outfile_fname, "/dev/null")) {
1573 chmod(outfile_fname, biggiestruct.properties.st_mode);
1574 chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid);
1575 ubuf->actime = biggiestruct.properties.st_atime;
1576 ubuf->modtime = biggiestruct.properties.st_mtime;
1577 utime(outfile_fname, ubuf);
1578 }
1579 mr_free(outfile_fname);
1580
1581 paranoid_free(tmp);
1582 paranoid_free(ntfsprog_command);
1583 paranoid_free(ntfsprog_fifo);
1584 g_loglevel = old_loglevel;
1585 return (retval);
1586}
1587
1588/**************************************************************************
1589 *END_RESTORE_A_BIGGIEFILE_FROM_STREAM *
1590 **************************************************************************/
1591
1592
1593
1594/**
1595 * Restore @p tarball_fname from CD.
1596 * @param tarball_fname The filename of the tarball to restore (in /mnt/cdrom).
1597 * This will be used unmodified.
1598 * @param current_tarball_number The number (starting from 0) of the fileset
1599 * we're restoring now.
1600 * @param filelist The node structure containing the list of files to be
1601 * restored. If no file in the afioball is in this list, afio will still be
1602 * called, but nothing will be written.
1603 * @return 0 for success, nonzero for failure.
1604 */
1605int
1606restore_a_tarball_from_CD(char *tarball_fname,
1607 long current_tarball_number,
1608 struct s_node *filelist)
1609{
1610 int retval = 0;
1611 int res;
1612 char *p;
1613
1614 /** malloc **/
1615 char *command = NULL;
1616 char *tmp = NULL;
1617 char *filelist_name = NULL;
1618 char *filelist_subset_fname = NULL;
1619 char *executable = NULL;
1620 char *temp_log = NULL;
1621 long matches = 0;
1622 bool use_star;
1623 char *xattr_fname = NULL;
1624 char *acl_fname = NULL;
1625
1626 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1627
1628 log_msg(5, "Entering");
1629 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1630 mr_asprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
1631 run_program_and_log_output(command, 9);
1632 paranoid_free(command);
1633
1634 mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", current_tarball_number);
1635 if (length_of_file(filelist_name) <= 2) {
1636 log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name);
1637 log_msg(2, "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
1638 log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");
1639 retval = 0;
1640 mr_free(filelist_name);
1641 log_msg(5, "Leaving");
1642 return(0);
1643 }
1644 if (count_lines_in_file(filelist_name) <= 0 || length_of_file(tarball_fname) <= 0) {
1645 log_msg(3, "length_of_file(%s) = %llu", tarball_fname, length_of_file(tarball_fname));
1646 log_msg(3, "count_lines_in_file(%s) = %llu", tarball_fname, count_lines_in_file(tarball_fname));
1647 log_to_screen("Unable to restore fileset #%ld (CD I/O error)", current_tarball_number);
1648 mr_free(filelist_name);
1649 log_msg(5, "Leaving");
1650 return(1);
1651 }
1652
1653 if (filelist) {
1654 mr_asprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);
1655 if ((matches =
1656 save_filelist_entries_in_common(filelist_name, filelist,
1657 filelist_subset_fname,
1658 use_star)) <= 0) {
1659 log_msg(1, "Skipping fileset %ld", current_tarball_number);
1660 } else {
1661 log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);
1662 }
1663 log_to_screen("Tarball #%ld --- %ld matches", current_tarball_number, matches);
1664 }
1665 mr_free(filelist_name);
1666
1667 if (filelist == NULL || matches > 0) {
1668 if (g_getfattr) {
1669 mr_asprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
1670 }
1671 if (g_getfacl) {
1672 mr_asprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
1673 }
1674 if (strstr(tarball_fname, ".bz2")) {
1675 mr_asprintf(executable, "bzip2");
1676 } else if (strstr(tarball_fname, ".gz")) {
1677 mr_asprintf(executable, "gzip");
1678 } else if (strstr(tarball_fname, ".lzo")) {
1679 mr_asprintf(executable, "lzop");
1680 }
1681 if (executable) {
1682 mr_asprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
1683 res = run_program_and_log_output(tmp, FALSE);
1684 mr_free(tmp);
1685
1686 if (res) {
1687 log_to_screen("(compare_a_tarball) Compression program %s not found - oh no!", executable);
1688 paranoid_MR_finish(1);
1689 }
1690 tmp = executable;
1691 mr_asprintf(executable, "-P %s -Z", tmp);
1692 mr_free(tmp);
1693 }
1694#ifdef __FreeBSD__
1695#define BUFSIZE 512
1696#else
1697#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
1698#endif
1699
1700 if (use_star) {
1701 mr_asprintf(command, "star -x -force-remove -U " STAR_ACL_SZ " errctl= file=%s", tarball_fname);
1702 if (strstr(tarball_fname, ".bz2")) {
1703 mr_strcat(command, " -bz");
1704 }
1705 } else {
1706 if (! executable) {
1707 log_msg(2, "Mo executable, this shouldn't happen !");
1708 } else {
1709 if (filelist_subset_fname != NULL) {
1710 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);
1711 } else {
1712 mr_asprintf(command, "afio -i -b %ld -c %ld -M 8m %s %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, tarball_fname);
1713 }
1714 }
1715 }
1716 mr_free(executable);
1717
1718#undef BUFSIZE
1719 mr_asprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), (int) (random() % 32768));
1720
1721 mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
1722 log_msg(1, "command = '%s'", command);
1723 unlink(temp_log);
1724 res = system(command);
1725 if (res) {
1726 p = strstr(command, "-acl ");
1727 if (p) {
1728 p[0] = p[1] = p[2] = p[3] = ' ';
1729 log_msg(1, "new command = '%s'", command);
1730 res = system(command);
1731 }
1732 }
1733 paranoid_free(command);
1734
1735 if (res && length_of_file(temp_log) < 5) {
1736 res = 0;
1737 }
1738
1739 if (g_getfattr) {
1740 log_msg(1, "Setting fattr list %s", xattr_fname);
1741 if (length_of_file(xattr_fname) > 0) {
1742 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1743 if (res) {
1744 log_to_screen("Errors occurred while setting extended attributes");
1745 } else {
1746 log_msg(1, "I set xattr OK");
1747 }
1748 retval += res;
1749 }
1750 }
1751 if (g_getfacl) {
1752 log_msg(1, "Setting acl list %s", acl_fname);
1753 if (length_of_file(acl_fname) > 0) {
1754 res = set_acl_list(filelist_subset_fname, acl_fname);
1755 if (res) {
1756 log_to_screen
1757 ("Errors occurred while setting access control lists");
1758 } else {
1759 log_msg(1, "I set ACL OK");
1760 }
1761 retval += res;
1762 }
1763 }
1764 if (retval) {
1765 mr_asprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
1766 system(command);
1767 paranoid_free(command);
1768
1769 log_msg(2, "Errors occurred while processing fileset #%d",
1770 current_tarball_number);
1771 } else {
1772 log_msg(2, "Fileset #%d processed OK", current_tarball_number);
1773 }
1774 unlink(temp_log);
1775 mr_free(temp_log);
1776 }
1777 if (does_file_exist("/PAUSE")) {
1778 popup_and_OK
1779 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
1780 }
1781 unlink(filelist_subset_fname);
1782 mr_free(filelist_subset_fname);
1783 if (g_getfattr) {
1784 unlink(xattr_fname);
1785 mr_free(xattr_fname);
1786 }
1787 if (g_getfacl) {
1788 unlink(acl_fname);
1789 mr_free(acl_fname);
1790 }
1791
1792 log_msg(5, "Leaving");
1793 return (retval);
1794}
1795
1796/**************************************************************************
1797 *END_RESTORE_A_TARBALL_FROM_CD *
1798 **************************************************************************/
1799
1800
1801/**
1802 * Restore a tarball from the currently opened stream.
1803 * @param bkpinfo The backup information structure. Fields used:
1804 * - @c bkpinfo->backup_media_type
1805 * - @c bkpinfo->media_device
1806 * - @c bkpinfo->zip_exe
1807 * @param tarball_fname The filename of the afioball to restore.
1808 * @param current_tarball_number The number (starting from 0) of the fileset
1809 * we're restoring now.
1810 * @param filelist The node structure containing the list of files to be
1811 * restored. If no file in the afioball is in this list, afio will still be
1812 * called, but nothing will be written.
1813 * @param size The size (in @b bytes) of the afioball.
1814 * @return 0 for success, nonzero for failure.
1815 */
1816int
1817restore_a_tarball_from_stream(char *tarball_fname,
1818 long current_tarball_number,
1819 struct s_node *filelist,
1820 long long size, char *xattr_fname,
1821 char *acl_fname)
1822{
1823 int retval = 0;
1824 int res = 0;
1825
1826 /** malloc add ***/
1827 char *mds = NULL;
1828 char *command = NULL;
1829 char *afio_fname = NULL;
1830 char *filelist_fname = NULL;
1831 char *filelist_subset_fname = NULL;
1832 char *executable = NULL;
1833 long matches = 0;
1834 bool restore_this_fileset = FALSE;
1835 bool use_star;
1836
1837 assert(bkpinfo != NULL);
1838 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1839
1840 /* to do it with a file... */
1841 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1842 mds = media_descriptor_string(bkpinfo->backup_media_type);
1843 log_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d",
1844 current_tarball_number, (long) size >> 10, mds, g_current_media_number);
1845 mr_free(mds);
1846
1847 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
1848
1849 /****************************************************************************
1850 * Use RAMDISK's /tmp; saves time; oh wait, it's too small *
1851 * Well, pipe from tape to afio, then; oh wait, can't do that either: bug *
1852 * in afio or someting; oh darn.. OK, use tmpfs :-) *
1853 ****************************************************************************/
1854 mr_asprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number);
1855 mr_asprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number);
1856 mr_asprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number);
1857
1858 res = read_file_from_stream_to_file(afio_fname, size);
1859 if (strstr(tarball_fname, ".star")) {
1860 bkpinfo->use_star = TRUE;
1861 }
1862 if (res) {
1863 log_msg(1, "Warning - error reading afioball from tape");
1864 }
1865 if (bkpinfo->compression_level == 0) {
1866 mr_asprintf(executable, "%s", "");
1867 } else {
1868 if (bkpinfo->use_star) {
1869 mr_asprintf(executable, "%s", " -bz");
1870 } else {
1871 mr_asprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
1872 }
1873 }
1874
1875 if (!filelist) // if unconditional restore then restore entire fileset
1876 {
1877 restore_this_fileset = TRUE;
1878 } else // If restoring selectively then get TOC from tarball
1879 {
1880 if (strstr(tarball_fname, ".star.")) {
1881 use_star = TRUE;
1882 mr_asprintf(command, "star -t file=%s %s", afio_fname, executable);
1883 } else {
1884 use_star = FALSE;
1885 mr_asprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, executable, afio_fname);
1886 }
1887 mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
1888 log_msg(1, "command = %s", command);
1889 if (system(command)) {
1890 log_msg(4, "Warning - error occurred while retrieving TOC");
1891 }
1892 mr_free(command);
1893
1894 if ((matches =
1895 save_filelist_entries_in_common(filelist_fname, filelist,
1896 filelist_subset_fname,
1897 use_star))
1898 <= 0 || length_of_file(filelist_subset_fname) < 2) {
1899 if (length_of_file(filelist_subset_fname) < 2) {
1900 log_msg(1, "No matches found in fileset %ld",
1901 current_tarball_number);
1902 }
1903 log_msg(2, "Skipping fileset %ld", current_tarball_number);
1904 restore_this_fileset = FALSE;
1905 } else {
1906 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
1907 matches, current_tarball_number,
1908 filelist_subset_fname);
1909 restore_this_fileset = TRUE;
1910 }
1911 }
1912
1913// Concoct the call to star/afio to restore files
1914 if (strstr(tarball_fname, ".star.")) {
1915 // star
1916 mr_asprintf(command, "star -x file=%s %s", afio_fname, executable);
1917 if (filelist) {
1918 mr_strcat(command, " list=%s", filelist_subset_fname);
1919 }
1920 } else {
1921 // afio
1922 mr_asprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable);
1923 if (filelist) {
1924 mr_strcat(command, " -w %s", filelist_subset_fname);
1925 }
1926 mr_strcat(command, " %s", afio_fname);
1927 }
1928 mr_strcat(command, " 2>> %s", MONDO_LOGFILE);
1929 mr_free(executable);
1930
1931// Call if IF there are files to restore (selectively/unconditionally)
1932 if (restore_this_fileset) {
1933 log_msg(1, "Calling command='%s'", command);
1934 paranoid_system(command);
1935
1936 if (g_getfattr) {
1937 log_it("Restoring xattr stuff");
1938 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1939 if (res) {
1940 log_msg(1, "Errors occurred while setting xattr");
1941 } else {
1942 log_msg(1, "I set xattr OK");
1943 }
1944 retval += res;
1945 }
1946
1947 if (g_getfacl) {
1948 log_it("Restoring acl stuff");
1949 res = set_acl_list(filelist_subset_fname, acl_fname);
1950 if (res) {
1951 log_msg(1, "Errors occurred while setting ACL");
1952 } else {
1953 log_msg(1, "I set ACL OK");
1954 }
1955 retval += res;
1956 }
1957
1958 } else {
1959 log_msg(1, "NOT CALLING '%s'", command);
1960 }
1961 mr_free(command);
1962
1963 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
1964 log_to_screen("Paused after set %ld", current_tarball_number);
1965 popup_and_OK("Pausing. Press ENTER to continue.");
1966 }
1967
1968 unlink(filelist_subset_fname);
1969 mr_free(filelist_subset_fname);
1970 unlink(filelist_fname);
1971 mr_free(filelist_fname);
1972 unlink(afio_fname);
1973 mr_free(afio_fname);
1974
1975 return (retval);
1976}
1977
1978/**************************************************************************
1979 *END_RESTORE_A_TARBALL_FROM_STREAM *
1980 **************************************************************************/
1981
1982
1983
1984
1985/**
1986 * Restore all biggiefiles from all media in this CD backup.
1987 * The CD with the last afioball should be currently mounted.
1988 * @param bkpinfo The backup information structure. @c backup_media_type is the
1989 * only field used in this function.
1990 * @param filelist The node structure containing the list of files to be
1991 * restored. If a prospective biggiefile is not in this list, it will be ignored.
1992 * @return 0 for success, nonzero for failure.
1993 */
1994int
1995restore_all_biggiefiles_from_CD(struct s_node *filelist)
1996{
1997 int retval = 0;
1998 int res = 0;
1999 long noof_biggiefiles, bigfileno = 0, total_slices;
2000 /** malloc **/
2001 char *tmp;
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(tmp);
2012 malloc_string(pathname_of_last_biggie_restored);
2013 assert(bkpinfo != NULL);
2014
2015 mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2016 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2017 log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
2018 }
2019
2020 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2021 total_slices = atol(tmp);
2022 mr_asprintf(tmp1, "Reassembling large files ");
2023 mvaddstr_and_log_it(g_currentY, 0, tmp1);
2024 mr_free(tmp1);
2025
2026 if (length_of_file(BIGGIELIST) < 6) {
2027 log_msg(1, "OK, no biggielist; not restoring biggiefiles");
2028 return (0);
2029 }
2030 noof_biggiefiles = count_lines_in_file(BIGGIELIST);
2031 if (noof_biggiefiles <= 0) {
2032 log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles");
2033 return (0);
2034 }
2035 log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
2036
2037 open_progress_form("Reassembling large files",
2038 "I am now reassembling all the large files.",
2039 "Please wait. This may take some time.",
2040 "", total_slices);
2041 for (bigfileno = 0 ; bigfileno < noof_biggiefiles ;) {
2042 log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
2043 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
2044 log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
2045 mds = media_descriptor_string(bkpinfo->backup_media_type);
2046 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno + 1, mds, g_current_media_number);
2047 log_msg(3, "Slicename would have been %s",
2048 slice_fname(bigfileno, 0, ARCHIVES_PATH, ""));
2049 // I'm not positive 'just_changed_cds' is even necessary...
2050 if (just_changed_cds) {
2051 just_changed_cds = FALSE;
2052 log_msg(3, "I'll continue to scan this CD for bigfiles to be restored.");
2053 } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
2054 insist_on_this_cd_number(++g_current_media_number);
2055 log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
2056 just_changed_cds = TRUE;
2057 } else {
2058 /* That big file doesn't exist, but the followings may */
2059 /* So we need to continue looping */
2060 log_msg(2, "There was no bigfile #%ld. That's OK.", bigfileno + 1);
2061 log_msg(2, "I'm going to stop restoring bigfiles now.");
2062 retval++;
2063 bigfileno++;
2064 }
2065 mr_free(mds);
2066 } else {
2067 just_changed_cds = FALSE;
2068 mr_asprintf(tmp1, "Restoring big file %ld", bigfileno + 1);
2069 update_progress_form(tmp1);
2070 mr_free(tmp1);
2071 res = restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored);
2072 log_it("%s",pathname_of_last_biggie_restored);
2073 if (fbw && pathname_of_last_biggie_restored[0]) {
2074 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2075 }
2076 retval += res;
2077 bigfileno++;
2078
2079 }
2080 }
2081
2082 if (fbw) {
2083 fclose(fbw);
2084 if (g_getfattr) {
2085 mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2086 if (length_of_file(xattr_fname) > 0) {
2087 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2088 }
2089 mr_free(xattr_fname);
2090 }
2091 if (g_getfacl) {
2092 mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2093 if (length_of_file(acl_fname) > 0) {
2094 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2095 }
2096 mr_free(acl_fname);
2097 }
2098 }
2099 mr_free(biggies_whose_EXATs_we_should_set);
2100
2101 if (does_file_exist("/PAUSE")) {
2102 popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2103 }
2104 close_progress_form();
2105 if (retval) {
2106 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2107 } else {
2108 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2109 }
2110 paranoid_free(tmp);
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 *tmp = NULL;
2141 char *mds = NULL;
2142 char *tmp1 = NULL;
2143 char *tarball_fname = NULL;
2144 char *progress_str = NULL;
2145 char *comment;
2146
2147 malloc_string(tmp);
2148 malloc_string(comment);
2149
2150 assert(bkpinfo != NULL);
2151
2152 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2153 log_msg(2, "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
2154 if (g_current_media_number != 1) {
2155 log_msg(3, "OK, that's jacked up.");
2156 g_current_media_number = 1;
2157 }
2158 insist_on_this_cd_number(g_current_media_number);
2159 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2160 max_val = atol(tmp) + 1;
2161 paranoid_free(tmp);
2162
2163 mds = media_descriptor_string(bkpinfo->backup_media_type);
2164 mr_asprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);
2165
2166 log_to_screen(progress_str);
2167 open_progress_form("Restoring from archives",
2168 "Restoring data from the archives.",
2169 "Please wait. This may take some time.",
2170 progress_str, max_val);
2171 for (;;) {
2172 insist_on_this_cd_number(g_current_media_number);
2173 update_progress_form(progress_str);
2174 mr_free(progress_str);
2175
2176 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", current_tarball_number);
2177 if (!does_file_exist(tarball_fname)) {
2178 mr_free(tarball_fname);
2179 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz", current_tarball_number);
2180 }
2181 if (!does_file_exist(tarball_fname)) {
2182 mr_free(tarball_fname);
2183 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", current_tarball_number);
2184 }
2185 if (!does_file_exist(tarball_fname)) {
2186 mr_free(tarball_fname);
2187 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.", current_tarball_number);
2188 }
2189 if (!does_file_exist(tarball_fname)) {
2190 mr_free(tarball_fname);
2191 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", current_tarball_number);
2192 }
2193 if (!does_file_exist(tarball_fname)) {
2194 mr_free(tarball_fname);
2195 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", current_tarball_number);
2196 }
2197 if (!does_file_exist(tarball_fname)) {
2198 if (current_tarball_number == 0) {
2199 log_to_screen
2200 ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
2201 mr_free(tarball_fname);
2202 return (0);
2203 }
2204 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2205 || system("find " MNT_CDROM
2206 "/archives/slice* > /dev/null 2> /dev/null") ==
2207 0) {
2208 break;
2209 }
2210 g_current_media_number++;
2211 mr_asprintf(progress_str, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
2212 log_to_screen(progress_str);
2213 } else {
2214 mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_tarball_number, mds, g_current_media_number);
2215 for (res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) {
2216 res = restore_a_tarball_from_CD(tarball_fname, current_tarball_number, filelist);
2217 }
2218 mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ", mds, g_current_media_number, current_tarball_number);
2219 if (res) {
2220 mr_strcat(tmp1, "reported errors");
2221 } else if (attempts > 1) {
2222 mr_strcat(tmp1, "succeeded");
2223 } else {
2224 mr_strcat(tmp1, "succeeded");
2225 }
2226 if (attempts > 1) {
2227 mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
2228 }
2229 strcpy(comment, tmp1);
2230 mr_free(tmp1);
2231 if (attempts > 1) {
2232 log_to_screen(comment);
2233 }
2234
2235 retval += res;
2236 current_tarball_number++;
2237 g_current_progress++;
2238 }
2239 mr_free(tarball_fname);
2240 }
2241 mr_free(mds);
2242 mr_free(progress_str);
2243
2244 close_progress_form();
2245 if (retval) {
2246 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2247 } else {
2248 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2249 }
2250 paranoid_free(comment);
2251
2252 return (retval);
2253}
2254
2255/**************************************************************************
2256 *END_RESTORE_ALL_TARBALLS_FROM_CD *
2257 **************************************************************************/
2258
2259
2260
2261/**
2262 * Restore all biggiefiles from the currently opened stream.
2263 * @param bkpinfo The backup information structure. Passed to other functions.
2264 * @param filelist The node structure containing the list of files to be
2265 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2266 * @return 0 for success, or the number of biggiefiles that failed.
2267 */
2268int
2269restore_all_biggiefiles_from_stream(struct s_node *filelist)
2270{
2271 long noof_biggiefiles;
2272 long current_bigfile_number = 0;
2273 long total_slices;
2274
2275 int retval = 0;
2276 int res = 0;
2277 int ctrl_chr;
2278
2279 /** malloc add ****/
2280 char *tmp;
2281 char *tmp1;
2282 char *biggie_fname;
2283 char *biggie_cksum;
2284 char *xattr_fname = NULL;
2285 char *acl_fname = NULL;
2286 char *p;
2287 char *pathname_of_last_biggie_restored;
2288 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
2289 long long biggie_size;
2290 FILE *fbw = NULL;
2291
2292 malloc_string(tmp);
2293 malloc_string(biggie_fname);
2294 malloc_string(biggie_cksum);
2295 malloc_string(pathname_of_last_biggie_restored);
2296 assert(bkpinfo != NULL);
2297
2298 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2299
2300 total_slices = atol(tmp);
2301 if (g_getfattr) {
2302 mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2303 }
2304 if (g_getfacl) {
2305 mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2306 }
2307 mr_asprintf(tmp1, "Reassembling large files ");
2308 mvaddstr_and_log_it(g_currentY, 0, tmp1);
2309 mr_free(tmp1);
2310
2311 mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2312 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2313 log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
2314 }
2315
2316 // get xattr and acl files if they're there
2317 res = read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr);
2318 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2319 res =
2320 read_EXAT_files_from_tape(&biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname);
2321 }
2322
2323 noof_biggiefiles = atol(biggie_fname);
2324 log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
2325 open_progress_form("Reassembling large files",
2326 "I am now reassembling all the large files.",
2327 "Please wait. This may take some time.",
2328 "", total_slices);
2329
2330 for (res =
2331 read_header_block_from_stream(&biggie_size, biggie_fname,
2332 &ctrl_chr);
2333 ctrl_chr != BLK_STOP_BIGGIEFILES;
2334 res =
2335 read_header_block_from_stream(&biggie_size, biggie_fname,
2336 &ctrl_chr)) {
2337 if (ctrl_chr != BLK_START_A_NORMBIGGIE
2338 && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2339 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2340 }
2341 p = strrchr(biggie_fname, '/');
2342 if (!p) {
2343 p = biggie_fname;
2344 } else {
2345 p++;
2346 }
2347 mr_asprintf(tmp1, "Restoring big file %ld (%lld K)", current_bigfile_number + 1, biggie_size / 1024);
2348 update_progress_form(tmp1);
2349 mr_free(tmp1);
2350 res = restore_a_biggiefile_from_stream(biggie_fname,
2351 current_bigfile_number,
2352 biggie_cksum,
2353 biggie_size,
2354 filelist, ctrl_chr,
2355 pathname_of_last_biggie_restored);
2356 log_msg(1, "I believe I have restored %s",
2357 pathname_of_last_biggie_restored);
2358 if (fbw && pathname_of_last_biggie_restored[0]) {
2359 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2360 }
2361 retval += res;
2362 current_bigfile_number++;
2363
2364 }
2365 if (current_bigfile_number != noof_biggiefiles
2366 && noof_biggiefiles != 0) {
2367 log_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", current_bigfile_number, noof_biggiefiles);
2368 } else {
2369 log_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", noof_biggiefiles, current_bigfile_number);
2370 }
2371
2372 if (fbw) {
2373 fclose(fbw);
2374 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
2375 log_it("Setting biggie-EXATs");
2376 if (g_getfattr) {
2377 if (length_of_file(xattr_fname) > 0) {
2378 log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname);
2379 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2380 }
2381 }
2382 if (g_getfacl) {
2383 if (length_of_file(acl_fname) > 0) {
2384 log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname);
2385 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2386 }
2387 }
2388 } else {
2389 log_it("No biggiefiles selected. So, no biggie-EXATs to set.");
2390 }
2391 }
2392 mr_free(xattr_fname);
2393 mr_free(acl_fname);
2394 mr_free(biggies_whose_EXATs_we_should_set);
2395
2396 if (does_file_exist("/PAUSE")) {
2397 popup_and_OK
2398 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2399 }
2400
2401 close_progress_form();
2402 if (retval) {
2403 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2404 } else {
2405 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2406 }
2407 paranoid_free(pathname_of_last_biggie_restored);
2408 paranoid_free(biggie_fname);
2409 paranoid_free(biggie_cksum);
2410 paranoid_free(tmp);
2411 return (retval);
2412}
2413
2414/**************************************************************************
2415 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM *
2416 **************************************************************************/
2417
2418
2419
2420
2421
2422
2423/**
2424 * Restore all afioballs from the currently opened tape stream.
2425 * @param bkpinfo The backup information structure. Fields used:
2426 * - @c bkpinfo->backup_media_type
2427 * - @c bkpinfo->restore_path
2428 * @param filelist The node structure containing the list of files to be
2429 * restored. If no file in an afioball is in this list, afio will still be
2430 * called for that fileset, but nothing will be written.
2431 * @return 0 for success, or the number of filesets that failed.
2432 */
2433int
2434restore_all_tarballs_from_stream(struct s_node *filelist)
2435{
2436 int retval = 0;
2437 int res;
2438 long current_afioball_number = 0;
2439 int ctrl_chr;
2440 long max_val /*, total_noof_files */ ;
2441
2442 /** malloc **/
2443 char *tmp = NULL;
2444 char *mds = NULL;
2445 char *progress_str = NULL;
2446 char *tmp_fname;
2447 char *xattr_fname = NULL;
2448 char *acl_fname = NULL;
2449
2450 long long tmp_size;
2451
2452 malloc_string(tmp_fname);
2453 assert(bkpinfo != NULL);
2454 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2455 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2456 max_val = atol(tmp) + 1;
2457
2458 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
2459
2460 run_program_and_log_output("pwd", 5);
2461
2462 mr_asprintf(progress_str, "Restoring from media #%d", g_current_media_number);
2463 log_to_screen(progress_str);
2464 open_progress_form("Restoring from archives",
2465 "Restoring data from the archives.",
2466 "Please wait. This may take some time.",
2467 progress_str, max_val);
2468
2469 log_msg(3, "hey");
2470
2471 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2472 if (res) {
2473 log_msg(2, "Warning - error reading afioball from tape");
2474 }
2475 retval += res;
2476 if (ctrl_chr != BLK_START_AFIOBALLS) {
2477 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
2478 }
2479 log_msg(2, "ho");
2480 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2481 while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2482 update_progress_form(progress_str);
2483 if (g_getfattr) {
2484 mr_asprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
2485 unlink(xattr_fname);
2486 }
2487 if (g_getfacl) {
2488 mr_asprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
2489 unlink(acl_fname);
2490 }
2491 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2492 log_it("Reading EXAT files from tape");
2493 res = read_EXAT_files_from_tape(&tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname);
2494 }
2495 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2496 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2497 }
2498 log_msg(4, "Restoring from fileset #%ld (name=%s, size=%ld K)", current_afioball_number, tmp_fname, (long) tmp_size >> 10);
2499 res = restore_a_tarball_from_stream(tmp_fname, current_afioball_number, filelist, tmp_size, xattr_fname, acl_fname);
2500 retval += res;
2501 if (res) {
2502 log_to_screen("Fileset %ld - errors occurred", current_afioball_number);
2503 }
2504 res =
2505 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2506 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2507 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2508 }
2509
2510 current_afioball_number++;
2511 g_current_progress++;
2512 mds = media_descriptor_string(bkpinfo->backup_media_type),
2513
2514 mr_free(progress_str);
2515 mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_afioball_number, mds, g_current_media_number);
2516 mr_free(mds);
2517 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2518 if (g_getfattr) {
2519 unlink(xattr_fname);
2520 }
2521 if (g_getfacl) {
2522 unlink(acl_fname);
2523 }
2524 } // next
2525 mr_free(progress_str);
2526 if (g_getfattr) {
2527 mr_free(xattr_fname);
2528 }
2529 if (g_getfacl) {
2530 mr_free(acl_fname);
2531 }
2532
2533 log_msg(1, "All done with afioballs");
2534 close_progress_form();
2535 if (retval) {
2536 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2537 } else {
2538 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2539 }
2540 paranoid_free(tmp_fname);
2541 return (retval);
2542}
2543
2544/**************************************************************************
2545 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM *
2546 **************************************************************************/
2547
2548/* @} - end of LLrestoreGroup */
2549
2550
2551/**
2552 * Restore all files in @p filelist.
2553 * @param bkpinfo The backup information structure. Most fields are used.
2554 * @param filelist The node structure containing the list of files to be
2555 * restored.
2556 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2557 * @ingroup restoreGroup
2558 */
2559int restore_everything(struct s_node *filelist)
2560{
2561 int resA;
2562 int resB;
2563
2564 /** mallco ***/
2565 char *cwd;
2566 char *newpath;
2567 char *tmp = NULL;
2568 assert(bkpinfo != NULL);
2569
2570 malloc_string(cwd);
2571 malloc_string(newpath);
2572 log_msg(2, "restore_everything() --- starting");
2573 g_current_media_number = 1;
2574 getcwd(cwd, MAX_STR_LEN - 1);
2575 mr_asprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
2576 run_program_and_log_output(tmp, FALSE);
2577 mr_free(tmp);
2578
2579 log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
2580 chdir(bkpinfo->restore_path);
2581 getcwd(newpath, MAX_STR_LEN - 1);
2582 log_msg(1, "path is now %s", newpath);
2583 log_msg(1, "restoring everything");
2584 if (!find_home_of_exe("petris") && !g_text_mode) {
2585 newtDrawRootText(0, g_noof_rows - 2,
2586 "Press ALT-<left cursor> twice to play Petris :-) ");
2587 newtRefresh();
2588 }
2589 mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
2590 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2591 mount_media();
2592 mvaddstr_and_log_it(g_currentY++, 0,
2593 "Restoring OS and data from streaming media");
2594 if (bkpinfo->backup_media_type == cdstream) {
2595 openin_cdstream();
2596 } else {
2597 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
2598 openin_tape();
2599 }
2600 resA = restore_all_tarballs_from_stream(filelist);
2601 resB = restore_all_biggiefiles_from_stream(filelist);
2602 if (bkpinfo->backup_media_type == cdstream) {
2603 closein_cdstream();
2604 } else {
2605 closein_tape();
2606 }
2607 } else {
2608 mvaddstr_and_log_it(g_currentY++, 0,
2609 "Restoring OS and data from CD/USB ");
2610 mount_media();
2611 resA = restore_all_tarballs_from_CD(filelist);
2612 resB = restore_all_biggiefiles_from_CD(filelist);
2613 }
2614 chdir(cwd);
2615 if (resA + resB) {
2616 log_to_screen("Errors occurred while data was being restored.");
2617 }
2618 if (length_of_file("/etc/raidtab") > 0) {
2619 log_msg(2, "Copying local raidtab to restored filesystem");
2620 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
2621 "/etc/raidtab", FALSE);
2622 }
2623 kill_petris();
2624 log_msg(2, "restore_everything() --- leaving");
2625 paranoid_free(cwd);
2626 paranoid_free(newpath);
2627 return (resA + resB);
2628}
2629
2630/**************************************************************************
2631 *END_RESTORE_EVERYTHING *
2632 **************************************************************************/
2633
2634
2635extern void wait_until_software_raids_are_prepped(char *, int);
2636
2637
2638char which_restore_mode(void);
2639
2640
2641/**
2642 * Log a "don't panic" message to the logfile.
2643 */
2644void welcome_to_mondorestore()
2645{
2646 log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
2647 log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please ");
2648 log_msg(0, "don't break out in a cold sweat just because you see a few ");
2649 log_msg(0, "error messages in the log. Read them; analyze them; see if ");
2650 log_msg(0, "they are significant; above all, verify your backups! Please");
2651 log_msg(0, "attach a compressed copy of this log to any e-mail you send ");
2652 log_msg(0, "to the Mondo mailing list when you are seeking technical ");
2653 log_msg(0, "support. Without it, we can't help you. - DevTeam");
2654 log_msg(0, "------------------------------------------------------------");
2655 log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages,");
2656 log_msg(0, "some users are inclined to stop reading this log. If Mondo ");
2657 log_msg(0, "stopped for some reason, chances are it's detailed here. ");
2658 log_msg(0, "More than likely there's a message at the very end of this ");
2659 log_msg(0, "log that will tell you what is wrong. Please read it! ");
2660 log_msg(0, "------------------------------------------------------------");
2661}
2662
2663
2664
2665/**
2666 * Restore the user's data.
2667 * What did you think it did, anyway? :-)
2668 */
2669int main(int argc, char *argv[])
2670{
2671 FILE *fin;
2672 FILE *fout;
2673 int retval = 0;
2674 int res;
2675 char *tmp = NULL;
2676
2677 struct mountlist_itself *mountlist;
2678 struct raidlist_itself *raidlist;
2679 struct s_node *filelist;
2680 char *a, *b;
2681 bool run_postnuke = FALSE;
2682
2683 if (getuid() != 0) {
2684 fprintf(stderr, "Please run as root.\r\n");
2685 exit(127);
2686 }
2687 bkpinfo = (struct s_bkpinfo *)mr_malloc(sizeof(struct s_bkpinfo));
2688 init_bkpinfo();
2689
2690 g_loglevel = DEFAULT_MR_LOGLEVEL;
2691
2692 /* Configure global variables */
2693 malloc_libmondo_global_strings();
2694#ifdef __FreeBSD__
2695 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "textonly"))
2696#else
2697 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "textonly"))
2698#endif
2699 {
2700 g_text_mode = TRUE;
2701 log_msg(1, "TEXTONLY MODE");
2702 } else {
2703 g_text_mode = FALSE;
2704 } // newt :-)
2705
2706 /* Init GUI */
2707 setup_newt_stuff(); /* call newtInit and setup screen log */
2708
2709 strcpy(g_mondo_home, call_program_and_get_last_line_of_output("which mondorestore"));
2710 g_current_media_number = 1; // precaution
2711
2712 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
2713
2714 malloc_string(a);
2715 malloc_string(b);
2716 setup_MR_global_filenames(); // malloc() and set globals, using bkpinfo->tmpdir etc.
2717 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
2718 bkpinfo->restore_data = TRUE; // Well, yeah :-)
2719 if (am_I_in_disaster_recovery_mode()) {
2720 run_program_and_log_output("mount / -o remount,rw", 2);
2721 } // for b0rken distros
2722 g_main_pid = getpid();
2723 srandom((int) (time(NULL)));
2724 set_signals(TRUE);
2725 g_kernel_version = get_kernel_version();
2726
2727 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
2728 if (strlen(g_mountlist_fname) < 3) {
2729 fatal_error("Serious error in malloc()'ing. Could be a bug in your glibc.");
2730 }
2731 mkdir(MNT_CDROM, 0x770);
2732 make_hole_for_dir(MONDO_CACHE);
2733
2734 /* Backup original mountlist.txt */
2735 mr_asprintf(tmp, "%s.orig", g_mountlist_fname);
2736 if (!does_file_exist(g_mountlist_fname)) {
2737 log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname);
2738 } else if (!does_file_exist(tmp)) {
2739 mr_free(tmp);
2740 mr_asprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, g_mountlist_fname);
2741 run_program_and_log_output(tmp, FALSE);
2742 }
2743 mr_free(tmp);
2744
2745 /* Init directories */
2746 make_hole_for_dir("/var/log");
2747 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */
2748 run_program_and_log_output("umount " MNT_CDROM, FALSE);
2749
2750 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
2751
2752 welcome_to_mondorestore();
2753 if (bkpinfo->disaster_recovery) {
2754 log_msg(1, "I am in disaster recovery mode");
2755 } else {
2756 log_msg(1, "I am in normal, live mode");
2757 }
2758
2759 log_it("what time is it");
2760
2761 mountlist = (struct mountlist_itself *)mr_malloc(sizeof(struct mountlist_itself));
2762 raidlist = (struct raidlist_itself *)mr_malloc(sizeof(struct raidlist_itself));
2763
2764 /* Process command-line parameters */
2765 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
2766#ifdef __FreeBSD__
2767 system("mv -f /tmp/raidconf.txt /etc/raidtab");
2768 if (!does_file_exist("/etc/raidtab"))
2769 system("vinum printconfig > /etc/raidtab");
2770#endif
2771 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2772 if (!does_file_exist(g_mountlist_fname)) {
2773 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2774 }
2775 res = let_user_edit_the_mountlist(mountlist, raidlist);
2776#ifdef __FreeBSD__
2777 system("mv -f /etc/raidtab /tmp/raidconf.txt");
2778#endif
2779 paranoid_MR_finish(res);
2780 }
2781
2782 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
2783 fout = fopen("/tmp/out.txt", "w");
2784 fput_string_one_char_at_a_time(stderr, argv[2]);
2785 finish(0);
2786 }
2787
2788 if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
2789 make_grub_install_scriptlet(argv[2]);
2790 finish(0);
2791 }
2792
2793 if (argc == 5 && strcmp(argv[1], "--common") == 0) {
2794 g_loglevel = 6;
2795 filelist = load_filelist(argv[2]);
2796 if (!filelist) {
2797 fatal_error("Failed to load filelist");
2798 }
2799 toggle_node_selection(filelist, FALSE);
2800 toggle_all_root_dirs_on(filelist);
2801 // BERLIOS: /usr/lib ???
2802 toggle_path_selection(filelist, "/usr/share", TRUE);
2803 save_filelist(filelist, "/tmp/out.txt");
2804 strcpy(a, argv[3]);
2805 strcpy(b, argv[4]);
2806
2807 res = save_filelist_entries_in_common(a, filelist, b, FALSE);
2808 free_filelist(filelist);
2809 printf("res = %d", res);
2810 finish(0);
2811 }
2812
2813 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
2814 popup_changelist_from_file(argv[2]);
2815 paranoid_MR_finish(0);
2816 }
2817
2818 if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
2819 log_msg(1, "SCORE");
2820 g_loglevel = 10;
2821 if (strstr(argv[2], "save")) {
2822 log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
2823 fin = fopen(argv[3], "r");
2824 fout = fopen(argv[4], "w");
2825 copy_from_src_to_dest(fin, fout, 'w');
2826 fclose(fin);
2827 fin = fopen(argv[3], "r");
2828 copy_from_src_to_dest(fin, fout, 'w');
2829 fclose(fout);
2830 fclose(fin);
2831 } else if (strstr(argv[2], "restore")) {
2832 fout = fopen(argv[3], "w");
2833 fin = fopen(argv[4], "r");
2834 copy_from_src_to_dest(fout, fin, 'r');
2835 fclose(fin);
2836 fin = fopen(argv[4], "r");
2837 copy_from_src_to_dest(fout, fin, 'r');
2838 fclose(fout);
2839 fclose(fin);
2840 } else {
2841 fatal_error("Unknown additional param");
2842 }
2843 finish(0);
2844 }
2845
2846 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
2847 wait_until_software_raids_are_prepped(argv[2], 100);
2848 finish(0);
2849 }
2850
2851 if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
2852 finish(create_raidtab_from_mdstat(argv[2]));
2853 }
2854
2855 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
2856 retval = run_grub(FALSE, "/dev/hda");
2857 if (retval) {
2858 log_to_screen("Failed to write Master Boot Record");
2859 }
2860 paranoid_MR_finish(0);
2861 }
2862 if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
2863 g_current_media_number = atoi(argv[2]);
2864 pause_and_ask_for_cdr(5, NULL);
2865 paranoid_MR_finish(0);
2866 }
2867 if ((argc == 2 && strcmp(argv[1], "--partition-only") == 0) && (bkpinfo->disaster_recovery)) {
2868 log_msg(0, "Partitioning only.");
2869 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2870 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2871 load_mountlist(mountlist, g_mountlist_fname);
2872 res = partition_everything(mountlist);
2873 finish(res);
2874 }
2875
2876 if ((argc == 2 && strcmp(argv[1], "--format-only") == 0) && (bkpinfo->disaster_recovery)) {
2877 log_msg(0, "Formatting only.");
2878 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2879 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2880 load_mountlist(mountlist, g_mountlist_fname);
2881 res = format_everything(mountlist, FALSE, raidlist);
2882 finish(res);
2883 }
2884
2885 if ((argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) && (bkpinfo->disaster_recovery)) {
2886 log_msg(0, "Stopping LVM and RAID");
2887 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2888 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2889 load_mountlist(mountlist, g_mountlist_fname);
2890 res = do_my_funky_lvm_stuff(TRUE, FALSE);
2891 res += stop_all_raid_devices(mountlist);
2892 finish(res);
2893 }
2894
2895 if ((argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) && (!bkpinfo->disaster_recovery)) {
2896 g_restoring_live_from_cd = TRUE;
2897 }
2898
2899 // Handle params here first
2900 handle_incoming_parameters(argc,argv);
2901
2902 if (!bkpinfo->disaster_recovery) { // live!
2903 log_msg(1, "I am in normal, live mode.");
2904 log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
2905 mount_boot_if_necessary(); /* for Gentoo users */
2906 log_msg(2, "Still here.");
2907 if (bkpinfo->backup_media_type == nfs) {
2908 g_restoring_live_from_nfs = TRUE;
2909 }
2910 log_msg(2, "Calling restore_to_live_filesystem()");
2911 retval = restore_to_live_filesystem();
2912
2913 log_msg(2, "Still here. Yay.");
2914 if ((strlen(bkpinfo->tmpdir) > 0) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
2915 mr_asprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
2916 run_program_and_log_output(tmp, FALSE);
2917 mr_free(tmp);
2918 }
2919 unmount_boot_if_necessary(); /* for Gentoo users */
2920 paranoid_MR_finish(retval);
2921 } else {
2922 /* Disaster recovery mode (must be) */
2923 log_msg(1, "I must be in disaster recovery mode.");
2924 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
2925
2926 log_it("About to call load_mountlist and load_raidtab");
2927 strcpy(bkpinfo->restore_path, MNT_RESTORING);
2928 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
2929 retval = load_mountlist(mountlist, g_mountlist_fname);
2930 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2931 log_it("Returned from calling load_mountlist and load_raidtab successfully");
2932
2933 // BCO:To be reviewed
2934 if ((bkpinfo->restore_mode == compare) || (bkpinfo->restore_mode == nuke)) {
2935 if (bkpinfo->backup_media_type == nfs
2936 && !is_this_device_mounted(bkpinfo->nfs_mount)) {
2937 log_msg(1, "Mounting nfs dir");
2938 mr_free(bkpinfo->isodir);
2939 mr_asprintf(bkpinfo->isodir, "/tmp/isodir");
2940 run_program_and_log_output("mkdir -p /tmp/isodir", 5);
2941 mr_asprintf(tmp, "mount %s -t nfs -o nolock,ro /tmp/isodir", bkpinfo->nfs_mount);
2942 run_program_and_log_output(tmp, 1);
2943 mr_free(tmp);
2944 }
2945 }
2946
2947 if (retval) {
2948 log_to_screen("Warning - load_raidtab_into_raidlist returned an error");
2949 }
2950
2951 log_msg(1, "Send in the clowns.");
2952
2953
2954 if (bkpinfo->restore_mode == nuke) {
2955 log_it("nuking");
2956 retval += nuke_mode(mountlist, raidlist);
2957 } else if (bkpinfo->restore_mode == interactive) {
2958 log_it("catchall");
2959 retval += catchall_mode(mountlist, raidlist);
2960 } else if (bkpinfo->restore_mode == compare) {
2961 log_it("compare");
2962 retval += compare_mode(mountlist, raidlist);
2963 } else if (bkpinfo->restore_mode == isoonly) {
2964 log_it("iso");
2965 retval = iso_mode(mountlist, raidlist, FALSE);
2966 } else if (bkpinfo->restore_mode == mbr) {
2967 log_it("mbr");
2968 retval = mount_all_devices(mountlist, TRUE);
2969 if (!retval) {
2970 retval += run_boot_loader(FALSE);
2971 retval += unmount_all_devices(mountlist);
2972 }
2973 if (retval) {
2974 log_to_screen("Failed to write Master Boot Record");
2975 }
2976 } else if (bkpinfo->restore_mode == isonuke) {
2977 log_it("isonuke");
2978 retval = iso_mode(mountlist, raidlist, TRUE);
2979 } else {
2980 log_it("catchall (no mode specified in command-line call");
2981 retval += catchall_mode(mountlist, raidlist);
2982 }
2983 }
2984
2985 /* clean up at the end */
2986 if (retval) {
2987 if (does_file_exist(MONDO_CACHE"/changed.files")) {
2988 log_to_screen
2989 ("See "MONDO_CACHE"/changed.files for list of files that have changed.");
2990 }
2991 mvaddstr_and_log_it(g_currentY++,
2992 0,
2993 "Run complete. Errors were reported. Please review the logfile.");
2994 } else {
2995 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2996 mvaddstr_and_log_it(g_currentY++,
2997 0,
2998 "Run complete. Please remove media and reboot.");
2999 } else {
3000 run_program_and_log_output("sync", FALSE);
3001 if (is_this_device_mounted(MNT_CDROM)) {
3002 run_program_and_log_output("umount " MNT_CDROM, FALSE);
3003 }
3004
3005 if (!bkpinfo->please_dont_eject) {
3006 (void)eject_device("/dev/cdrom");
3007 }
3008 mvaddstr_and_log_it(g_currentY++,
3009 0,
3010 "Run complete. Please remove media and reboot.");
3011 }
3012 }
3013
3014// g_I_have_just_nuked is set true by nuke_mode() just before it returns
3015 if (!system("which post-nuke > /dev/null 2> /dev/null")) {
3016 log_msg(1, "post-nuke found; find out whether we should run it...");
3017 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
3018 run_postnuke = TRUE;
3019 log_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
3020 } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
3021 run_postnuke = TRUE;
3022 log_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
3023 } else {
3024 run_postnuke = FALSE;
3025 log_msg(1, "No, will not run post-nuke.");
3026 }
3027 } else {
3028 log_msg(1, "No post-nuke found.");
3029 }
3030 if (run_postnuke) {
3031 log_to_screen("Running post-nuke...");
3032 if (mount_all_devices(mountlist, TRUE)) {
3033 log_to_screen
3034 ("Unable to re-mount partitions for post-nuke stuff");
3035 } else {
3036 log_msg(1, "Re-mounted partitions for post-nuke stuff");
3037 mr_asprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval);
3038 log_msg(2, "Calling '%s'", tmp);
3039 if ((res = run_program_and_log_output(tmp, 0))) {
3040 log_OS_error(tmp);
3041 }
3042 mr_free(tmp);
3043 log_msg(1, "post-nuke returned w/ res=%d", res);
3044 }
3045 unmount_all_devices(mountlist);
3046 log_to_screen("I've finished post-nuking.");
3047 }
3048
3049/*
3050 log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
3051 log_to_screen("Otherwise, please wait until the RAID disks are done.");
3052 wait_until_software_raids_are_prepped("/proc/mdstat", 100);
3053 log_to_screen("Thank you.");
3054*/
3055 unlink("/tmp/mondo-run-prog.tmp");
3056 set_signals(FALSE);
3057 log_to_screen("Restore log (%s) copied to /var/log on your hard disk", MONDO_LOGFILE);
3058 log_to_screen("Mondo-restore is exiting (retval=%d) ", retval);
3059
3060 mr_asprintf(tmp, "umount %s", bkpinfo->isodir);
3061 run_program_and_log_output(tmp, 5);
3062 mr_free(tmp);
3063
3064 paranoid_free(mountlist);
3065 paranoid_free(raidlist);
3066 if (am_I_in_disaster_recovery_mode()) {
3067 run_program_and_log_output("mount / -o remount,rw", 2);
3068 } // for b0rken distros
3069 if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) {
3070 mr_asprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
3071 system(tmp);
3072 mr_free(tmp);
3073 }
3074 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
3075 free_libmondo_global_strings(); // it's fine to have this here :) really :)
3076 paranoid_free(a);
3077 paranoid_free(b);
3078
3079 unlink("/tmp/filelist.full");
3080 unlink("/tmp/filelist.full.gz");
3081
3082 exit(retval);
3083}
3084
3085/**************************************************************************
3086 *END_MAIN *
3087 **************************************************************************/
3088
3089
3090
3091
3092
3093/**************************************************************************
3094 *END_MONDO-RESTORE.C *
3095 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.