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

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