source: MondoRescue/branches/2.2.5/mondo/src/mondorestore/mondo-restore.c@ 1579

Last change on this file since 1579 was 1579, checked in by Bruno Cornec, 17 years ago

Remove the useless modify_rclocal_one_time

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