source: MondoRescue/branches/3.0/mondo/src/mondorestore/mondorestore.c

Last change on this file was 3185, checked in by Bruno Cornec, 11 years ago

Simplify the interface of mr_getline and mr_asprintf. With 3.1 compatibility now will allow backports from this branch into 3.0

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