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

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