source: MondoRescue/branches/2.2.2/mondo/src/mondorestore/mondo-restore.c@ 1236

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

Port from stable important patches for 2.2.2:
mindi-busybox:

  • Improve Gentoo packaging

mindi:

  • Better messages for analyze-my-lvm
  • Add support for newer Qlogic drivers (qla2300 & 2400), mpt, dm and ohci
  • Fix a bug in mindi for the FAILSAFE support
  • PATH fixed for init in restore (/usr/games added for petris)
  • Fiw a bug where restore failing because no archive files are found when -G is used
  • /media is now completely excluded as per StandardsCompliance

mondo:

  • Handle no compression + verify correctly
  • various HOWTO fixes
  • Fix temporarily a bug when a biggiefile > 32MB was compressed below the size

of a slice (16MB)

  • Better module loading in insmod_crucial_modules
  • Improve Gentoo packaging
  • Small typo fix for mondorestore man page
  • Small memory management improvements
  • Store NFS config only once
  • Fix a flaw in libmondo-mountlist.c (there since rev [1] !!)
  • Increased MAX_STR_LEN to 384 to make it divisible without remainder by eight

for 64 bits platforms

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