source: MondoRescue/branches/3.2/mondo/src/mondorestore/mondorestore.c@ 3194

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