source: MondoRescue/branches/stable/mondo/src/mondorestore/mondo-restore.c@ 1077

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

Fix a bug reported by Andy Wright (introduced when supporting gzip) where no bzip2 format file would be found.

  • Property svn:keywords set to Id
File size: 101.2 KB
RevLine 
[1]1/***************************************************************************
[1077]2$Id: mondo-restore.c 1077 2007-01-27 07:20:48Z bruno $
3restores mondoarchive data
[1]4***************************************************************************/
5
6/**
7 * @file
8 * The main file for mondorestore.
9 */
10
11/**************************************************************************
12 * #include statements *
13 **************************************************************************/
14#include <pthread.h>
[1067]15#include "my-stuff.h"
[1]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
[128]32//static char cvsid[] = "$Id: mondo-restore.c 1077 2007-01-27 07:20:48Z bruno $";
[1]33
34/**************************************************************************
35 * Globals *
36 **************************************************************************/
[128]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
[1]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 */
[128]58bool g_sigpipe_caught = FALSE;
[1]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 */
[128]64bool g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */
[1]65
66/**
67 * If TRUE, then we have had a successful "nuke" restore.
68 */
[128]69bool g_I_have_just_nuked = FALSE;
[1]70
71/**
72 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
73 */
[128]74char *g_isodir_device;
[1]75
76/**
77 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
78 */
[128]79char *g_isodir_format;
[1]80
81/**
82 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
83 */
[128]84char *g_biggielist_txt;
[1]85
86/**
87 * The location of 'filelist.full', containing all files (<em>including biggiefiles</em>) on
88 * the current archive set.
89 */
[128]90char *g_filelist_full;
[1]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 */
[128]96char *g_filelist_imagedevs;
[1]97
98/**
99 * The location of a file containing a list of imagedevs to actually restore.
100 * @see g_filelist_imagedevs
101 */
[128]102char *g_imagedevs_restthese;
[1]103
104/**
105 * The location of 'mondo-restore.cfg', containing the metadata
106 * information for this backup.
107 */
[128]108char *g_mondo_cfg_file;
[1]109
110/**
111 * The location of 'mountlist.txt', containing the information on the
112 * user's partitions and hard drives.
113 */
[128]114char *g_mountlist_fname;
[1]115
116/**
117 * Mondo's home directory during backup. Unused in mondo-restore; included
118 * to avoid link errors.
119 */
[128]120char *g_mondo_home;
[1]121
[928]122/* Busybox ps has no option and PID in first pos */
[792]123char *ps_options = "";
[928]124char *ps_proc_id = "$1";
[792]125
[952]126extern char *g_getfacl;
127extern char *g_getfattr;
[946]128
[1]129/* @} - end of "Restore-Time Globals" in globalGroup */
130
131
132
[128]133extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
134 char direction);
[1]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 */
[541]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."
[1]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 */
[128]158int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo,
159 struct mountlist_itself *mountlist,
160 struct raidlist_itself *raidlist)
[1]161{
[128]162 int retval = 0, res = 0;
[1]163
[128]164 log_msg(2, "let_user_edit_the_mountlist() --- starting");
[1]165
[128]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()");
[1]172 }
[128]173 if (!does_file_exist(g_mountlist_fname)) {
174 log_to_screen(g_mountlist_fname);
[541]175 log_to_screen("does not exist");
[128]176 return (1);
177 }
[1]178
[128]179 retval = load_mountlist(mountlist, g_mountlist_fname);
180 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
181 if (retval) {
182 log_to_screen
[541]183 ("Warning - load_raidtab_into_raidlist returned an error");
[128]184 }
185 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
186 if (res) {
187 return (1);
188 }
[1]189
[128]190 save_mountlist_to_disk(mountlist, g_mountlist_fname);
191 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
[1]192
[541]193 log_to_screen("I have finished editing the mountlist for you.");
[1]194
[128]195 return (retval);
196}
[1]197
198
[128]199
200
201
[1]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 */
[128]208bool
209partition_table_contains_Compaq_diagnostic_partition(struct
210 mountlist_itself *
211 mountlist)
[1]212{
[128]213 int i;
[1]214
[128]215 assert(mountlist != NULL);
[1]216
[128]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 }
[1]224 }
[128]225 return (FALSE);
[1]226}
[128]227
[1]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 */
[128]238void offer_to_abort_because_Compaq_Proliants_suck(void)
[1]239{
[128]240 popup_and_OK(COMPAQ_PROLIANTS_SUCK);
241 if (ask_me_yes_or_no
[541]242 ("Would you like to reboot and use your Compaq CD to prep your hard drive?"))
[128]243 {
244 fatal_error
[541]245 ("Aborting. Please reboot and prep your hard drive with your Compaq CD.");
[128]246 }
[1]247}
[128]248
[1]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 */
[128]263int
264catchall_mode(struct s_bkpinfo *bkpinfo,
265 struct mountlist_itself *mountlist,
266 struct raidlist_itself *raidlist)
[1]267{
[128]268 char c, *tmp;
269 int retval = 0;
[1]270
[128]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 {
[541]282 popup_and_OK("No restoring or comparing will take place today.");
[128]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);
[1]291 }
292
[128]293 iamhere("post int");
[1]294
[128]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 }
[1]304
[128]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);
[1]317}
[128]318
[1]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
[128]337find_pathname_of_executable_preferably_in_RESTORING(char *out_path,
338 char *fname,
339 char *restg)
[1]340{
[128]341 assert(out_path != NULL);
342 assert_string_is_neither_NULL_nor_zerolength(fname);
[1]343
[128]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 }
[1]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 */
[128]379int
380interactive_mode(struct s_bkpinfo *bkpinfo,
381 struct mountlist_itself *mountlist,
382 struct raidlist_itself *raidlist)
[1]383{
[128]384 int retval = 0;
385 int res;
386 int ptn_errs = 0;
387 int fmt_errs = 0;
[1]388
[128]389 bool done;
390 bool restore_all;
[1]391
392 /** needs malloc **********/
[128]393 char *tmp;
394 char *fstab_fname;
395 char *old_restpath;
[1]396
[128]397 struct s_node *filelist;
[1]398
[128]399 /* try to partition and format */
[1]400
[128]401 log_msg(2, "interactive_mode --- starting (great, assertions OK)");
[1]402
[128]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);
[1]409
[128]410 log_msg(2, "interactive_mode --- assertions OK");
[1]411
[128]412 if (g_text_mode) {
413 if (!ask_me_yes_or_no
[541]414 ("Interactive Mode + textonly = experimental! Proceed anyway?"))
[128]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");
[1]424#ifdef __FreeBSD__
[128]425 if (strstr
426 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
427 "noresize"))
[1]428#else
[128]429 if (strstr
430 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
431 "noresize"))
[1]432#endif
[128]433 {
434 log_msg(1, "Not resizing mountlist.");
435 } else {
436 resize_mountlist_proportionately_to_suit_new_drives(mountlist);
[1]437 }
[128]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);
[1]447 }
[128]448 iamhere("Finished editing mountlist");
449 if (res) {
450 paranoid_MR_finish(1);
[1]451 }
[128]452 log_msg(2, "Proceeding...");
453 save_mountlist_to_disk(mountlist, g_mountlist_fname);
454 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
[541]455 mvaddstr_and_log_it(1, 30, "Restoring Interactively");
[128]456 if (bkpinfo->differential) {
[541]457 log_to_screen("Because this is a differential backup, disk");
[128]458 log_to_screen
[541]459 (" partitioning and formatting will not take place.");
[128]460 done = TRUE;
461 } else {
462 if (ask_me_yes_or_no
[541]463 ("Do you want to erase and partition your hard drives?")) {
[128]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
[541]474 ("Warning. Errors occurred during disk partitioning.");
[128]475 }
[1]476
[558]477 fmt_errs = format_everything(mountlist, FALSE, raidlist);
[128]478 if (!fmt_errs) {
479 log_to_screen
[541]480 ("Errors during disk partitioning were handled OK.");
[128]481 log_to_screen
[541]482 ("Partitions were formatted OK despite those errors.");
[128]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,
[541]492 "User opted not to partition the devices");
[128]493 if (ask_me_yes_or_no
[541]494 ("Do you want to format your hard drives?")) {
[558]495 fmt_errs = format_everything(mountlist, TRUE, raidlist);
[128]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,
[541]507 "Errors occurred. Please repartition and format drives manually.");
[128]508 done = FALSE;
509 }
510 if (ptn_errs & !fmt_errs) {
511 mvaddstr_and_log_it(g_currentY++,
512 0,
[541]513 "Errors occurred during partitioning. Formatting, however, went OK.");
[128]514 done = TRUE;
515 }
516 if (!done) {
[541]517 if (!ask_me_yes_or_no("Re-edit the mountlist?")) {
[128]518 retval++;
519 goto end_of_func;
520 }
521 }
[1]522 }
523 }
524
[128]525 /* mount */
526 if (mount_all_devices(mountlist, TRUE)) {
527 unmount_all_devices(mountlist);
528 retval++;
529 goto end_of_func;
[1]530 }
[128]531 /* restore */
532 if ((restore_all =
[541]533 ask_me_yes_or_no("Do you want me to restore all of your data?")))
[1]534 {
[128]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
[541]540 ("Do you want me to restore _some_ of your data?"))) {
[128]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
[541]553 ("Restore path", "Restore files to where?", tmp,
[128]554 MAX_STR_LEN / 4)) {
555 if (!strcmp(tmp, "/")) {
[541]556 if (!ask_me_yes_or_no("Are you sure?")) {
[128]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
[541]570 ("Restore another subset of your backup?")) {
[128]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,
[541]581 "User opted not to restore any data. ");
[1]582 }
[128]583 if (retval) {
584 mvaddstr_and_log_it(g_currentY++,
585 0,
[541]586 "Errors occurred during the restore phase. ");
[1]587 }
588
[541]589 if (ask_me_yes_or_no("Initialize the boot loader?")) {
[128]590 run_boot_loader(TRUE);
591 } else {
592 mvaddstr_and_log_it(g_currentY++,
593 0,
[541]594 "User opted not to initialize the boot loader.");
[128]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
[541]603 ("Label your ext2 and ext3 partitions if necessary?")) {
[128]604 mvaddstr_and_log_it(g_currentY, 0,
[541]605 "Using e2label to label your ext2,3 partitions");
[128]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
[541]618 ("label-partitions-as-necessary returned an error");
619 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
[128]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,
[541]630 "Warning - errors occurred during the restore phase.");
[128]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);
[1]638}
[128]639
[1]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 */
[128]655int
656iso_mode(struct s_bkpinfo *bkpinfo,
657 struct mountlist_itself *mountlist,
658 struct raidlist_itself *raidlist, bool nuke_me_please)
[1]659{
[128]660 char c;
661 int retval = 0;
[1]662
[128]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 {
[541]682 log_to_screen("OK, I shan't restore/compare any files.");
[128]683 }
684 }
685 if (is_this_device_mounted(MNT_CDROM)) {
686 paranoid_system("umount " MNT_CDROM);
687 }
[1]688// if (! already_mounted)
689// {
[128]690 if (system("umount /tmp/isodir 2> /dev/null")) {
691 log_to_screen
[541]692 ("WARNING - unable to unmount device where the ISO files are stored.");
[128]693 }
[1]694// }
[128]695 return (retval);
[1]696}
[128]697
[1]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 */
[128]717int
718nuke_mode(struct s_bkpinfo *bkpinfo,
719 struct mountlist_itself *mountlist,
720 struct raidlist_itself *raidlist)
[1]721{
[128]722 int retval = 0;
723 int res = 0;
724 bool boot_loader_installed = FALSE;
[1]725 /** malloc **/
[128]726 char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN],
727 tmpC[MAX_STR_LEN];
[1]728
[128]729 assert(bkpinfo != NULL);
730 assert(mountlist != NULL);
731 assert(raidlist != NULL);
[1]732
[128]733 log_msg(2, "nuke_mode --- starting");
[1]734
[128]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
[1]737#ifdef __FreeBSD__
[128]738 if (strstr
739 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
740 "noresize"))
[1]741#else
[128]742 if (strstr
743 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
744 "noresize"))
[1]745#endif
746 {
[128]747 log_msg(2, "Not resizing mountlist.");
748 } else {
749 resize_mountlist_proportionately_to_suit_new_drives(mountlist);
[1]750 }
[128]751 if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
752 sprintf(tmp,
[541]753 "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?",
[128]754 tmpA, tmpB, tmpC);
755 if (ask_me_yes_or_no(tmp)) {
756 retval = interactive_mode(bkpinfo, mountlist, raidlist);
[818]757 goto after_the_nuke;
[128]758 } else {
759 fatal_error("Nuke Mode aborted. ");
760 }
[1]761 }
[128]762 save_mountlist_to_disk(mountlist, g_mountlist_fname);
[541]763 mvaddstr_and_log_it(1, 30, "Restoring Automatically");
[128]764 if (bkpinfo->differential) {
[541]765 log_to_screen("Because this is a differential backup, disk");
766 log_to_screen("partitioning and formatting will not take place.");
[128]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");
[1]775#ifdef __FreeBSD__
[128]776 if (strstr
777 (call_program_and_get_last_line_of_output
778 ("cat /tmp/cmdline"), "nopart"))
[1]779#else
[128]780 if (strstr
781 (call_program_and_get_last_line_of_output
782 ("cat /proc/cmdline"), "nopart"))
[1]783#endif
[128]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
[541]792 ("Warning. Errors occurred during partitioning.");
[128]793 res = 0;
794 }
795 }
796 retval += res;
797 if (!res) {
[541]798 log_to_screen("Preparing to format your disk(s)");
[128]799 sleep(1);
800 system("sync");
[541]801 log_to_screen("Please wait. This may take a few minutes.");
[558]802 res += format_everything(mountlist, FALSE, raidlist);
[128]803 }
804 paranoid_fclose(g_fprep);
805 }
[1]806 }
[128]807 retval += res;
808 if (res) {
809 mvaddstr_and_log_it(g_currentY++,
810 0,
[541]811 "Failed to partition and/or format your hard drives.");
[128]812
[541]813 if (ask_me_yes_or_no("Try in interactive mode instead?")) {
[128]814 retval = interactive_mode(bkpinfo, mountlist, raidlist);
815 goto after_the_nuke;
816 } else
817 if (!ask_me_yes_or_no
[541]818 ("Would you like to try to proceed anyway?")) {
[128]819 return (retval);
820 }
[1]821 }
[128]822 retval = mount_all_devices(mountlist, TRUE);
823 if (retval) {
824 unmount_all_devices(mountlist);
825 log_to_screen
[541]826 ("Unable to mount all partitions. Sorry, I cannot proceed.");
[128]827 return (retval);
[1]828 }
[128]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();
[1]837// run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
[128]838 // modify_rclocal_one_time( MNT_RESTORING "/etc" );
839 retval += unmount_all_devices(mountlist);
840 mvaddstr_and_log_it(g_currentY,
841 0,
[541]842 "Using e2label to label your ext2,3 partitions");
[1]843
[128]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) {
[541]848 log_to_screen("label-partitions-as-necessary returned an error");
849 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
[128]850 } else {
[541]851 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]852 }
853 retval += res;
[1]854
[128]855 after_the_nuke:
856 if (retval) {
[541]857 log_to_screen("Errors occurred during the nuke phase.");
[128]858 } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) // Bruno's thing
859 {
860 log_to_screen
[541]861 ("PC was restored successfully. Thank you for using Mondo Rescue.");
[128]862 log_to_screen
[541]863 ("Please visit our website at http://www.mondorescue.org for more information.");
[128]864 } else {
[818]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.");
[425]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
[818]870 ("Mondo has restored your system. Please wait for the command prompt.");
[425]871 log_to_screen
[818]872 ("Then remove the backup media and reboot.");
873 log_to_screen
[541]874 ("Please visit our website at http://www.mondorescue.org for more information.");
[128]875 }
876 g_I_have_just_nuked = TRUE;
[1]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*/
[128]884 return (retval);
[1]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 */
[128]899int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo)
[1]900{
[128]901 int retval = 0;
[1]902
903 /** malloc **/
[128]904 char *old_restpath;
[1]905
[128]906 struct mountlist_itself *mountlist;
[1]907// static
[128]908 struct raidlist_itself *raidlist;
909 struct s_node *filelist;
[1]910
[128]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 }
[1]919
[128]920 strcpy(bkpinfo->restore_path, "/");
921 if (!g_restoring_live_from_cd) {
922 popup_and_OK
[541]923 ("Please insert tape/CD/boot floppy, then hit 'OK' to continue.");
[128]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 }
[1]931
932
[128]933 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
[1]934
[541]935 open_evalcall_form("Thinking...");
[1]936
[128]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);
[541]948 if (popup_and_get_string("Restore path",
949 "Restore files to where? )",
[128]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);
[1]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,
[128]999 long bigfileno,
1000 struct s_node *filelist,
1001 char *pathname_of_last_file_restored)
[1]1002{
[128]1003 FILE *fin;
1004 FILE *fout;
1005 FILE *fbzip2;
1006
[1]1007 /** malloc ***/
[128]1008 char *checksum, *outfile_fname, *tmp, *bzip2_command,
[296]1009 *ntfsprog_command, *suffix, *sz_devfile;
[128]1010 char *bigblk;
1011 char *p;
1012 int retval = 0;
1013 int finished = FALSE;
1014 long sliceno;
1015 long siz;
[296]1016 char ntfsprog_fifo[MAX_STR_LEN];
[128]1017 char *file_to_openout = NULL;
1018 struct s_filename_and_lstat_info biggiestruct;
1019 struct utimbuf the_utime_buf, *ubuf;
[296]1020 bool use_ntfsprog_hack = FALSE;
[128]1021 pid_t pid;
1022 int res = 0;
1023 int old_loglevel;
1024 char sz_msg[MAX_STR_LEN];
1025 struct s_node *node;
[1]1026
[128]1027 old_loglevel = g_loglevel;
1028 ubuf = &the_utime_buf;
1029 assert(bkpinfo != NULL);
[1]1030
[128]1031 malloc_string(checksum);
1032 malloc_string(outfile_fname);
1033 malloc_string(tmp);
1034 malloc_string(bzip2_command);
[296]1035 malloc_string(ntfsprog_command);
[128]1036 malloc_string(suffix);
1037 malloc_string(sz_devfile);
[1]1038
[128]1039 pathname_of_last_file_restored[0] = '\0';
1040 if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
1041 fatal_error("Cannot malloc bigblk");
1042 }
[1]1043
[128]1044 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
[541]1045 log_to_screen("Cannot even open bigfile's info file");
[128]1046 return (1);
1047 }
[1]1048
[128]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);
[1]1056
[128]1057 strcpy(checksum, biggiestruct.checksum);
[1]1058
[128]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 }
[1]1065
[128]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 }
[1]1073
[128]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 }
[1]1088 }
[128]1089 /* otherwise, continue */
[1]1090
[128]1091 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
[296]1092 if (biggiestruct.use_ntfsprog) {
[128]1093 if (strncmp(biggiestruct.filename, "/dev/", 5)) {
1094 log_msg(1,
[296]1095 "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
[128]1096 log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
[296]1097 biggiestruct.use_ntfsprog = FALSE;
[128]1098 }
1099 }
1100
[296]1101 if (biggiestruct.use_ntfsprog) // if it's an NTFS device
[1]1102// if (!strncmp ( biggiestruct.filename, "/dev/", 5))
[128]1103 {
1104 g_loglevel = 4;
[296]1105 use_ntfsprog_hack = TRUE;
[128]1106 log_msg(2,
[296]1107 "Calling ntfsclone in background because %s is an NTFS /dev entry",
[128]1108 outfile_fname);
1109 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
1110 (int) (random() % 32768));
1111 mkfifo(sz_devfile, 0x770);
[296]1112 strcpy(ntfsprog_fifo, sz_devfile);
1113 file_to_openout = ntfsprog_fifo;
[128]1114 switch (pid = fork()) {
1115 case -1:
1116 fatal_error("Fork failure");
1117 case 0:
1118 log_msg(3,
[296]1119 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
1120 biggiestruct.filename, ntfsprog_fifo);
[128]1121 res =
[296]1122 feed_outfrom_ntfsprog(biggiestruct.filename,
1123 ntfsprog_fifo);
[128]1124// log_msg(3, "CHILD - fip - exiting");
1125 exit(res);
1126 break;
1127 default:
1128 log_msg(3,
[296]1129 "feed_into_ntfsprog() called in background --- pid=%ld",
[128]1130 (long int) (pid));
1131 }
1132 } else {
[296]1133 use_ntfsprog_hack = FALSE;
1134 ntfsprog_fifo[0] = '\0';
[128]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 }
[1]1141
[128]1142 sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
1143 outfile_fname);
1144 log_msg(2, tmp);
[1]1145
[128]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 */
[1]1151
[128]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';
[1]1155
[128]1156 log_msg(3, "file_to_openout = %s", file_to_openout);
1157 if (!(fout = fopen(file_to_openout, "w"))) {
[541]1158 log_to_screen("Cannot openout outfile_fname - hard disk full?");
[128]1159 return (1);
[1]1160 }
[296]1161 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
[1]1162
[128]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
[1053]1171 (bigfileno, sliceno, ARCHIVES_PATH, "gz"))
1172 &&
1173 !does_file_exist(slice_fname
[128]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);
[541]1184 sprintf(tmp, "Restoring from %s #%d",
[128]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);
[541]1189 log_to_screen("Continuing to restore.");
[128]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
[998]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
[128]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 {
[541]1224 log_to_screen("OK, that's pretty fsck0red...");
[128]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);
[1]1242
[128]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);
[1]1263
[128]1264
1265 sliceno++;
1266 g_current_progress++;
1267 }
1268 }
[1]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*/
[128]1276 paranoid_fclose(fout);
1277 g_loglevel = old_loglevel;
[1]1278
[296]1279 if (use_ntfsprog_hack) {
1280 log_msg(3, "Waiting for ntfsclone to finish");
[128]1281 sprintf(tmp,
[433]1282 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
[128]1283 while (system(tmp) == 0) {
1284 sleep(1);
1285 }
[296]1286 log_it("OK, ntfsclone has really finished");
[128]1287 }
[1]1288
[128]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);
[296]1302 paranoid_free(ntfsprog_command);
[128]1303 paranoid_free(suffix);
1304 paranoid_free(sz_devfile);
[1]1305
[128]1306 return (retval);
[1]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 */
[128]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,
[296]1332 int use_ntfsprog,
[128]1333 char *pathname_of_last_file_restored)
[1]1334{
[128]1335 FILE *pout;
1336 FILE *fin;
[1]1337
1338 /** mallocs ********/
[128]1339 char *tmp;
1340 char *command;
1341 char *outfile_fname;
[296]1342 char *ntfsprog_command;
[128]1343 char *sz_devfile;
[296]1344 char *ntfsprog_fifo;
[128]1345 char *file_to_openout = NULL;
[1]1346
[128]1347 struct s_node *node;
[1]1348
[128]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;
[296]1356 bool use_ntfsprog_hack = FALSE;
[128]1357 pid_t pid;
1358 struct s_filename_and_lstat_info biggiestruct;
1359 struct utimbuf the_utime_buf, *ubuf;
1360 ubuf = &the_utime_buf;
[1]1361
[128]1362 malloc_string(tmp);
[296]1363 malloc_string(ntfsprog_fifo);
[128]1364 malloc_string(outfile_fname);
1365 malloc_string(command);
1366 malloc_string(sz_devfile);
[296]1367 malloc_string(ntfsprog_command);
[128]1368 old_loglevel = g_loglevel;
1369 assert(bkpinfo != NULL);
1370 assert(orig_bf_fname != NULL);
1371 assert(orig_checksum != NULL);
[1]1372
[128]1373 pathname_of_last_file_restored[0] = '\0';
[296]1374 if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
1375 use_ntfsprog = 1;
[128]1376 log_msg(1, "%s --- pih=YES", orig_bf_fname);
[296]1377 } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
1378 use_ntfsprog = 0;
[128]1379 log_msg(1, "%s --- pih=NO", orig_bf_fname);
1380 } else {
[296]1381 use_ntfsprog = 0;
[128]1382 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
1383 }
[1]1384
[128]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';
[1]1388
[128]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 }
[1]1405 }
1406
[296]1407 if (use_ntfsprog) {
[128]1408 if (strncmp(orig_bf_fname, "/dev/", 5)) {
1409 log_msg(1,
[296]1410 "I was in error when I set use_ntfsprog to TRUE.");
[128]1411 log_msg(1, "%s isn't even in /dev", orig_bf_fname);
[296]1412 use_ntfsprog = FALSE;
[128]1413 }
1414 }
[1]1415
[296]1416 if (use_ntfsprog) {
[128]1417 g_loglevel = 4;
1418 strcpy(outfile_fname, orig_bf_fname);
[296]1419 use_ntfsprog_hack = TRUE;
[128]1420 log_msg(2,
[296]1421 "Calling ntfsclone in background because %s is a /dev entry",
[128]1422 outfile_fname);
[812]1423 sprintf(sz_devfile, "%s/%d.%d.000",
1424 bkpinfo->tmpdir,
1425 (int) (random() % 32768),
[128]1426 (int) (random() % 32768));
1427 mkfifo(sz_devfile, 0x770);
[296]1428 strcpy(ntfsprog_fifo, sz_devfile);
1429 file_to_openout = ntfsprog_fifo;
[128]1430 switch (pid = fork()) {
1431 case -1:
1432 fatal_error("Fork failure");
1433 case 0:
1434 log_msg(3,
[296]1435 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
1436 outfile_fname, ntfsprog_fifo);
[128]1437 res =
[296]1438 feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
[128]1439// log_msg(3, "CHILD - fip - exiting");
1440 exit(res);
1441 break;
1442 default:
1443 log_msg(3,
[296]1444 "feed_into_ntfsprog() called in background --- pid=%ld",
[128]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 }
[296]1456 use_ntfsprog_hack = FALSE;
1457 ntfsprog_fifo[0] = '\0';
[128]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);
[1]1466 }
[128]1467
1468 if (dummy_restore) {
1469 sprintf(outfile_fname, "/dev/null");
[1]1470 }
[128]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);
[1]1477 }
[128]1478 sprintf(tmp, "Pipe command = '%s'", command);
1479 log_msg(3, tmp);
[1]1480
[128]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);
[1]1530
[128]1531 log_msg(1, "pathname_of_last_file_restored is now %s",
1532 pathname_of_last_file_restored);
[1]1533
[296]1534 if (use_ntfsprog_hack) {
1535 log_msg(3, "Waiting for ntfsclone to finish");
[128]1536 sprintf(tmp,
[433]1537 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
[128]1538 while (system(tmp) == 0) {
1539 sleep(1);
1540 }
[296]1541 log_msg(3, "OK, ntfsclone has really finished");
[128]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);
[296]1558 paranoid_free(ntfsprog_command);
[128]1559 paranoid_free(sz_devfile);
[296]1560 paranoid_free(ntfsprog_fifo);
[128]1561 g_loglevel = old_loglevel;
1562 return (retval);
[1]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,
[128]1584 long current_tarball_number,
1585 struct s_node *filelist)
[1]1586{
[128]1587 int retval = 0;
1588 int res;
1589 char *p;
[1]1590
1591 /** malloc **/
[128]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;
[1]1603// char files_to_restore_this_time_fname[MAX_STR_LEN];
1604
[128]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
[478]1615 log_msg(5, "Entering");
[128]1616 filelist_subset_fname[0] = '\0';
1617 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
[1]1618// sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
[128]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));
[1]1623
[128]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,
[676]1630 "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
[128]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;
[1]1635 }
[128]1636 if (count_lines_in_file(filelist_name) <= 0
1637 || length_of_file(tarball_fname) <= 0) {
[684]1638 log_msg(3, "length_of_file(%s) = %llu", tarball_fname,
[128]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;
[1]1645 }
1646
[128]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) {
[948]1669 if (g_getfattr) {
1670 sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
[128]1671 MNT_CDROM "/archives", current_tarball_number);
[948]1672 }
1673 if (g_getfacl) {
1674 sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
[128]1675 current_tarball_number);
[948]1676 }
[128]1677 if (strstr(tarball_fname, ".bz2")) {
1678 strcpy(executable, "bzip2");
[998]1679 } else if (strstr(tarball_fname, ".gz")) {
1680 strcpy(executable, "gzip");
[128]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
[541]1690 ("(compare_a_tarball) Compression program not found - oh no!");
[128]1691 paranoid_MR_finish(1);
1692 }
1693 strcpy(tmp, executable);
1694 sprintf(executable, "-P %s -Z", tmp);
1695 }
[1]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."))
[128]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,
[543]1713 "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
[128]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
[948]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;
[128]1754 }
1755 }
[948]1756 if (g_getfacl) {
[128]1757 log_msg(1, "Setting acl list %s", acl_fname);
[948]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;
[128]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 }
[1]1777 }
[128]1778 if (does_file_exist("/PAUSE")) {
1779 popup_and_OK
[541]1780 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
[1]1781 }
[128]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);
[1]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,
[128]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)
[1]1827{
[128]1828 int retval = 0;
1829 int res = 0;
[1]1830
1831 /** malloc add ***/
[128]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;
[1]1841
[128]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
[1]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 ****************************************************************************/
[128]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);
[1]1873// sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
[128]1874 res = read_file_from_stream_to_file(bkpinfo, afio_fname, size);
1875 if (strstr(tarball_fname, ".star")) {
1876 bkpinfo->use_star = TRUE;
[1]1877 }
[128]1878 if (res) {
1879 log_msg(1, "Warning - error reading afioball from tape");
[1]1880 }
[128]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 }
[1]1889 }
1890
[128]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
[1]1930// Concoct the call to star/afio to restore files
[128]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);
[1]1949
1950// Call if IF there are files to restore (selectively/unconditionally)
[128]1951 if (restore_this_fileset) {
1952 log_msg(1, "Calling command='%s'", command);
1953 paranoid_system(command);
[1]1954
[948]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;
[128]1964 }
[1]1965
[948]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;
[128]1975 }
1976
1977 } else {
1978 log_msg(1, "NOT CALLING '%s'", command);
1979 }
1980
1981 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
[541]1982 log_to_screen("Paused after set %ld", current_tarball_number);
1983 popup_and_OK("Pausing. Press ENTER to continue.");
[128]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);
[1]1996}
[128]1997
[1]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
[128]2015restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo,
2016 struct s_node *filelist)
[1]2017{
[128]2018 int retval = 0;
2019 int res;
2020 long noof_biggiefiles, bigfileno = 0, total_slices;
[1]2021 /** malloc **/
[128]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;
[1]2029
[128]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);
[1]2042 }
2043
[128]2044 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2045 total_slices = atol(tmp);
[541]2046 sprintf(tmp, "Reassembling large files ");
[128]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);
[1]2051 }
[128]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);
[1]2061
[541]2062 open_progress_form("Reassembling large files",
2063 "I am now reassembling all the large files.",
2064 "Please wait. This may take some time.",
[128]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);
[541]2085 sprintf(tmp, "Restoring from %s #%d",
[128]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;
[541]2099 sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
[128]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 }
[1]2112 }
[128]2113
2114 if (fbw) {
2115 fclose(fbw);
[948]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 }
[128]2121 }
[948]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 }
[128]2127 }
[1]2128 }
[128]2129 if (does_file_exist("/PAUSE")) {
2130 popup_and_OK
[541]2131 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
[128]2132 }
2133 close_progress_form();
2134 if (retval) {
[541]2135 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[128]2136 } else {
[541]2137 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]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);
[1]2145}
[128]2146
[1]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
[128]2164restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo,
2165 struct s_node *filelist)
[1]2166{
[128]2167 int retval = 0;
2168 int res;
2169 int attempts;
2170 long current_tarball_number = 0;
2171 long max_val;
[1]2172 /**malloc ***/
[128]2173 char *tmp;
2174 char *tarball_fname;
2175 char *progress_str;
2176 char *comment;
[1]2177
[128]2178 malloc_string(tmp);
2179 malloc_string(tarball_fname);
2180 malloc_string(progress_str);
2181 malloc_string(comment);
[1]2182
[128]2183 assert(bkpinfo != NULL);
2184
[541]2185 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
[128]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;
[1]2191 }
[128]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;
[541]2195 sprintf(progress_str, "Restoring from %s #%d",
[128]2196 media_descriptor_string(bkpinfo->backup_media_type),
2197 g_current_media_number);
2198 log_to_screen(progress_str);
[541]2199 open_progress_form("Restoring from archives",
2200 "Restoring data from the archives.",
2201 "Please wait. This may take some time.",
[128]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);
[1077]2208 if (!does_file_exist(tarball_fname)) {
2209 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz",
[1053]2210 current_tarball_number);
[1077]2211 }
[128]2212 if (!does_file_exist(tarball_fname)) {
2213 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
2214 current_tarball_number);
2215 }
2216 if (!does_file_exist(tarball_fname)) {
2217 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
2218 current_tarball_number);
2219 }
2220 if (!does_file_exist(tarball_fname)) {
2221 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
2222 current_tarball_number);
2223 }
2224 if (!does_file_exist(tarball_fname)) {
2225 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
2226 current_tarball_number);
2227 }
2228 if (!does_file_exist(tarball_fname)) {
2229 if (current_tarball_number == 0) {
2230 log_to_screen
[541]2231 ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
[128]2232 return (0);
2233 }
2234 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2235 || system("find " MNT_CDROM
2236 "/archives/slice* > /dev/null 2> /dev/null") ==
2237 0) {
2238 break;
2239 }
2240 g_current_media_number++;
[541]2241 sprintf(progress_str, "Restoring from %s #%d",
[128]2242 media_descriptor_string(bkpinfo->backup_media_type),
2243 g_current_media_number);
2244 log_to_screen(progress_str);
2245 } else {
[541]2246 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
[128]2247 current_tarball_number,
2248 media_descriptor_string(bkpinfo->backup_media_type),
2249 g_current_media_number);
2250// log_msg(3, "progress_str = %s", progress_str);
2251 for (res = 999, attempts = 0; attempts < 3 && res != 0;
2252 attempts++) {
2253 res =
2254 restore_a_tarball_from_CD(tarball_fname,
2255 current_tarball_number,
2256 filelist);
2257 }
[541]2258 sprintf(tmp, "%s #%d, fileset #%ld - restore ",
[128]2259 media_descriptor_string(bkpinfo->backup_media_type),
2260 g_current_media_number, current_tarball_number);
2261 if (res) {
[541]2262 strcat(tmp, "reported errors");
[128]2263 } else if (attempts > 1) {
[541]2264 strcat(tmp, "succeeded");
[128]2265 } else {
[541]2266 strcat(tmp, "succeeded");
[128]2267 }
2268 if (attempts > 1) {
[541]2269 sprintf(tmp + strlen(tmp), " (%d attempts) - review logs",
[128]2270 attempts);
2271 }
2272 strcpy(comment, tmp);
2273 if (attempts > 1) {
2274 log_to_screen(comment);
2275 }
2276
2277 retval += res;
2278 current_tarball_number++;
2279 g_current_progress++;
2280 }
[1]2281 }
[128]2282 close_progress_form();
2283 if (retval) {
[541]2284 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[128]2285 } else {
[541]2286 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[1]2287 }
[128]2288 paranoid_free(tmp);
2289 paranoid_free(tarball_fname);
2290 paranoid_free(progress_str);
2291 paranoid_free(comment);
2292
2293 return (retval);
[1]2294}
2295
2296/**************************************************************************
2297 *END_RESTORE_ALL_TARBALLS_FROM_CD *
2298 **************************************************************************/
2299
2300
2301
2302/**
2303 * Restore all biggiefiles from the currently opened stream.
2304 * @param bkpinfo The backup information structure. Passed to other functions.
2305 * @param filelist The node structure containing the list of files to be
2306 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2307 * @return 0 for success, or the number of biggiefiles that failed.
2308 */
2309int
[128]2310restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo,
2311 struct s_node *filelist)
[1]2312{
[128]2313 long noof_biggiefiles;
2314 long current_bigfile_number = 0;
2315 long total_slices;
[1]2316
[128]2317 int retval = 0;
2318 int res = 0;
2319 int ctrl_chr;
[1]2320
2321 /** malloc add ****/
[128]2322 char *tmp;
2323 char *biggie_fname;
2324 char *biggie_cksum;
2325 char *xattr_fname;
2326 char *acl_fname;
2327 char *p;
2328 char *pathname_of_last_biggie_restored;
2329 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes
2330 long long biggie_size;
2331 FILE *fbw = NULL;
[1]2332
[128]2333 malloc_string(tmp);
2334 malloc_string(biggie_fname);
2335 malloc_string(biggie_cksum);
2336 malloc_string(xattr_fname);
2337 malloc_string(acl_fname);
2338 malloc_string(biggies_whose_EXATs_we_should_set);
2339 malloc_string(pathname_of_last_biggie_restored);
2340 assert(bkpinfo != NULL);
[1]2341
[128]2342 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
[1]2343
[128]2344 total_slices = atol(tmp);
2345 sprintf(tmp, "Reassembling large files ");
[948]2346 if (g_getfattr) {
2347 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2348 }
2349 if (g_getfacl) {
2350 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2351 }
[128]2352 mvaddstr_and_log_it(g_currentY, 0, tmp);
2353 sprintf(biggies_whose_EXATs_we_should_set,
2354 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2355 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2356 log_msg(1, "Warning - cannot openout %s",
2357 biggies_whose_EXATs_we_should_set);
2358 }
[1]2359// get xattr and acl files if they're there
[128]2360 res =
2361 read_header_block_from_stream(&biggie_size, biggie_fname,
2362 &ctrl_chr);
2363 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2364 res =
2365 read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname,
2366 &ctrl_chr, xattr_fname, acl_fname);
2367 }
[1]2368
[128]2369 noof_biggiefiles = atol(biggie_fname);
2370 sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2371 noof_biggiefiles);
2372 log_msg(2, tmp);
[541]2373 open_progress_form("Reassembling large files",
2374 "I am now reassembling all the large files.",
2375 "Please wait. This may take some time.",
[128]2376 "", total_slices);
[1]2377
[128]2378 for (res =
2379 read_header_block_from_stream(&biggie_size, biggie_fname,
2380 &ctrl_chr);
2381 ctrl_chr != BLK_STOP_BIGGIEFILES;
2382 res =
2383 read_header_block_from_stream(&biggie_size, biggie_fname,
2384 &ctrl_chr)) {
2385 if (ctrl_chr != BLK_START_A_NORMBIGGIE
2386 && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2387 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2388 }
2389 p = strrchr(biggie_fname, '/');
2390 if (!p) {
2391 p = biggie_fname;
2392 } else {
2393 p++;
2394 }
[541]2395 sprintf(tmp, "Restoring big file %ld (%lld K)",
[128]2396 current_bigfile_number + 1, biggie_size / 1024);
2397 update_progress_form(tmp);
2398 res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
2399 current_bigfile_number,
2400 biggie_cksum,
2401 biggie_size,
2402 filelist, ctrl_chr,
2403 pathname_of_last_biggie_restored);
2404 log_msg(1, "I believe I have restored %s",
2405 pathname_of_last_biggie_restored);
2406 if (fbw && pathname_of_last_biggie_restored[0]) {
2407 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2408 }
2409 retval += res;
2410 current_bigfile_number++;
2411
[1]2412 }
[128]2413 if (current_bigfile_number != noof_biggiefiles
2414 && noof_biggiefiles != 0) {
2415 sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
2416 current_bigfile_number, noof_biggiefiles);
2417 } else {
2418 sprintf(tmp,
2419 "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
2420 noof_biggiefiles, current_bigfile_number);
[1]2421 }
[128]2422 log_msg(1, tmp);
[1]2423
[128]2424 if (fbw) {
2425 fclose(fbw);
2426 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
2427 iamhere("Setting biggie-EXATs");
[948]2428 if (g_getfattr) {
2429 if (length_of_file(xattr_fname) > 0) {
2430 log_msg(1, "set_fattr_List(%s,%s)",
[128]2431 biggies_whose_EXATs_we_should_set, xattr_fname);
[948]2432 set_fattr_list(biggies_whose_EXATs_we_should_set,
[128]2433 xattr_fname);
[948]2434 }
[128]2435 }
[948]2436 if (g_getfacl) {
2437 if (length_of_file(acl_fname) > 0) {
2438 log_msg(1, "set_acl_list(%s,%s)",
2439 biggies_whose_EXATs_we_should_set, acl_fname);
2440 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2441 }
2442 }
[128]2443 } else {
2444 iamhere
2445 ("No biggiefiles selected. So, no biggie-EXATs to set.");
2446 }
[1]2447 }
[128]2448 if (does_file_exist("/PAUSE")) {
2449 popup_and_OK
[541]2450 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
[1]2451 }
2452
[128]2453 close_progress_form();
2454 if (retval) {
[541]2455 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[128]2456 } else {
[541]2457 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]2458 }
2459 paranoid_free(biggies_whose_EXATs_we_should_set);
2460 paranoid_free(pathname_of_last_biggie_restored);
2461 paranoid_free(biggie_fname);
2462 paranoid_free(biggie_cksum);
2463 paranoid_free(xattr_fname);
2464 paranoid_free(acl_fname);
2465 paranoid_free(tmp);
2466 return (retval);
[1]2467}
[128]2468
[1]2469/**************************************************************************
2470 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM *
2471 **************************************************************************/
2472
2473
2474
2475
2476
2477
2478/**
2479 * Restore all afioballs from the currently opened tape stream.
2480 * @param bkpinfo The backup information structure. Fields used:
2481 * - @c bkpinfo->backup_media_type
2482 * - @c bkpinfo->restore_path
2483 * @param filelist The node structure containing the list of files to be
2484 * restored. If no file in an afioball is in this list, afio will still be
2485 * called for that fileset, but nothing will be written.
2486 * @return 0 for success, or the number of filesets that failed.
2487 */
2488int
[128]2489restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo,
2490 struct s_node *filelist)
[1]2491{
[128]2492 int retval = 0;
2493 int res;
2494 long current_afioball_number = 0;
2495 int ctrl_chr;
2496 long max_val /*, total_noof_files */ ;
[1]2497
2498 /** malloc **/
[128]2499 char *tmp;
2500 char *progress_str;
2501 char *tmp_fname;
2502 char *xattr_fname;
2503 char *acl_fname;
[1]2504
[128]2505 long long tmp_size;
[1]2506
[128]2507 malloc_string(tmp);
2508 malloc_string(progress_str);
2509 malloc_string(tmp_fname);
2510 assert(bkpinfo != NULL);
2511 malloc_string(xattr_fname);
2512 malloc_string(acl_fname);
[541]2513 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
[128]2514 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2515 max_val = atol(tmp) + 1;
[1]2516
[128]2517 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
[1]2518
[128]2519 run_program_and_log_output("pwd", 5);
[1]2520
[541]2521 sprintf(progress_str, "Restoring from media #%d",
[128]2522 g_current_media_number);
2523 log_to_screen(progress_str);
[541]2524 open_progress_form("Restoring from archives",
2525 "Restoring data from the archives.",
2526 "Please wait. This may take some time.",
[128]2527 progress_str, max_val);
[1]2528
[128]2529 log_msg(3, "hey");
[1]2530
[128]2531 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2532 if (res) {
2533 log_msg(2, "Warning - error reading afioball from tape");
[1]2534 }
[128]2535 retval += res;
2536 if (ctrl_chr != BLK_START_AFIOBALLS) {
2537 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
[1]2538 }
[128]2539 log_msg(2, "ho");
2540 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2541 while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2542 update_progress_form(progress_str);
[948]2543 if (g_getfattr) {
2544 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
[128]2545 current_afioball_number);
[948]2546 unlink(xattr_fname);
2547 }
2548 if (g_getfacl) {
2549 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
[128]2550 current_afioball_number);
[948]2551 unlink(acl_fname);
2552 }
[128]2553 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2554 iamhere("Reading EXAT files from tape");
2555 res =
2556 read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname,
2557 &ctrl_chr, xattr_fname,
2558 acl_fname);
2559 }
2560 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2561 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2562 }
2563 sprintf(tmp,
[541]2564 "Restoring from fileset #%ld (name=%s, size=%ld K)",
[128]2565 current_afioball_number, tmp_fname, (long) tmp_size >> 10);
2566 res =
2567 restore_a_tarball_from_stream(bkpinfo, tmp_fname,
2568 current_afioball_number,
2569 filelist, tmp_size, xattr_fname,
2570 acl_fname);
2571 retval += res;
2572 if (res) {
[541]2573 sprintf(tmp, "Fileset %ld - errors occurred",
[128]2574 current_afioball_number);
2575 log_to_screen(tmp);
2576 }
2577 res =
2578 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2579 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2580 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2581 }
[1]2582
[128]2583 current_afioball_number++;
2584 g_current_progress++;
[541]2585 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
[128]2586 current_afioball_number,
2587 media_descriptor_string(bkpinfo->backup_media_type),
2588 g_current_media_number);
2589 res =
2590 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
[948]2591 if (g_getfattr) {
2592 unlink(xattr_fname);
2593 }
2594 if (g_getfacl) {
2595 unlink(acl_fname);
2596 }
[128]2597 } // next
2598 log_msg(1, "All done with afioballs");
2599 close_progress_form();
2600 if (retval) {
[541]2601 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[128]2602 } else {
[541]2603 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]2604 }
2605 paranoid_free(tmp);
2606 paranoid_free(progress_str);
2607 paranoid_free(tmp_fname);
2608 paranoid_free(xattr_fname);
2609 paranoid_free(acl_fname);
2610 return (retval);
[1]2611}
[128]2612
[1]2613/**************************************************************************
2614 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM *
2615 **************************************************************************/
2616
2617/* @} - end of LLrestoreGroup */
2618
2619
2620/**
2621 * Restore all files in @p filelist.
2622 * @param bkpinfo The backup information structure. Most fields are used.
2623 * @param filelist The node structure containing the list of files to be
2624 * restored.
2625 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2626 * @ingroup restoreGroup
2627 */
[128]2628int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
[1]2629{
[128]2630 int resA;
2631 int resB;
[1]2632
2633 /** mallco ***/
[128]2634 char *cwd;
2635 char *newpath;
2636 char *tmp;
2637 assert(bkpinfo != NULL);
[1]2638
[128]2639 malloc_string(cwd);
2640 malloc_string(newpath);
2641 malloc_string(tmp);
2642 log_msg(2, "restore_everything() --- starting");
2643 g_current_media_number = 1;
2644 getcwd(cwd, MAX_STR_LEN - 1);
2645 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
2646 run_program_and_log_output(tmp, FALSE);
2647 log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
2648 chdir(bkpinfo->restore_path);
2649 getcwd(newpath, MAX_STR_LEN - 1);
2650 log_msg(1, "path is now %s", newpath);
2651 log_msg(1, "restoring everything");
2652 if (!find_home_of_exe("petris") && !g_text_mode) {
2653 newtDrawRootText(0, g_noof_rows - 2,
[541]2654 "Press ALT-<left cursor> twice to play Petris :-) ");
[128]2655 newtRefresh();
[1]2656 }
[541]2657 mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
[128]2658 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2659 mount_cdrom(bkpinfo);
2660 mvaddstr_and_log_it(g_currentY++, 0,
[541]2661 "Restoring OS and data from streaming media");
[128]2662 if (bkpinfo->backup_media_type == cdstream) {
2663 openin_cdstream(bkpinfo);
2664 } else {
2665 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->
2666 media_device);
2667 openin_tape(bkpinfo);
2668 }
2669 resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
2670 resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
2671 if (bkpinfo->backup_media_type == cdstream) {
2672 closein_cdstream(bkpinfo);
2673 } else {
2674 closein_tape(bkpinfo);
2675 }
2676 } else {
2677 mvaddstr_and_log_it(g_currentY++, 0,
[541]2678 "Restoring OS and data from CD ");
[128]2679 mount_cdrom(bkpinfo);
2680 resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
2681 resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
[1]2682 }
[128]2683 chdir(cwd);
2684 if (resA + resB) {
[541]2685 log_to_screen("Errors occurred while data was being restored.");
[1]2686 }
[128]2687 if (length_of_file("/etc/raidtab") > 0) {
2688 log_msg(2, "Copying local raidtab to restored filesystem");
2689 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
2690 "/etc/raidtab", FALSE);
[1]2691 }
[128]2692 kill_petris();
2693 log_msg(2, "restore_everything() --- leaving");
2694 paranoid_free(cwd);
2695 paranoid_free(newpath);
2696 paranoid_free(tmp);
2697 return (resA + resB);
[1]2698}
2699
2700/**************************************************************************
2701 *END_RESTORE_EVERYTHING *
2702 **************************************************************************/
2703
2704
2705
2706/**
2707 * @brief Haha. You wish! (This function is not implemented :-)
2708 */
2709int
[128]2710restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,
2711 char *monitas_device,
2712 char *restore_this_directory,
2713 char *restore_here)
2714 /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
[1]2715{
[128]2716 FILE *fout;
2717 int retval = 0;
2718 int i;
2719 int j;
2720 struct mountlist_itself the_mountlist;
2721 static struct raidlist_itself the_raidlist;
[1]2722 /** malloc **/
[128]2723 char tmp[MAX_STR_LEN + 1];
2724 char command[MAX_STR_LEN + 1];
2725 char datablock[256 * 1024];
2726 char datadisks_fname[MAX_STR_LEN + 1];
2727 long k;
2728 long length;
2729 long long llt;
2730 struct s_node *filelist = NULL;
2731 assert(bkpinfo != NULL);
2732 assert_string_is_neither_NULL_nor_zerolength(monitas_device);
2733 assert(restore_this_directory != NULL);
2734 assert(restore_here != NULL);
[1]2735
[128]2736 sprintf(tmp, "restore_here = '%s'", restore_here);
[1]2737
[128]2738 log_msg(2, tmp);
[1]2739
[128]2740 log_msg(2, "restore_live_from_monitas_server() - starting");
2741 unlink("/tmp/mountlist.txt");
2742 unlink("/tmp/filelist.full");
2743 unlink("/tmp/biggielist.txt");
2744 if (restore_here[0] == '\0') {
2745 strcpy(bkpinfo->restore_path, MNT_RESTORING);
2746 } else {
2747 strcpy(bkpinfo->restore_path, restore_here);
2748 }
2749 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
2750 sprintf(tmp, "FYI - data will be restored to %s",
2751 bkpinfo->restore_path);
2752 log_msg(3, tmp);
2753 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
2754 sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
2755 (int) (random() % 32768));
2756 chdir(bkpinfo->tmpdir);
[1]2757
[128]2758 sprintf(command, "cat %s", monitas_device);
2759 g_tape_stream = popen(command, "r"); // for compatibility with openin_tape()
2760 if (!(fout = fopen(datadisks_fname, "w"))) {
2761 log_OS_error(datadisks_fname);
2762 return (1);
2763 }
2764 for (i = 0; i < 32; i++) {
2765 for (j = 0; j < 4; j++) {
2766 for (length = k = 0; length < 256 * 1024; length += k) {
2767 k = fread(datablock + length, 1, 256 * 1024 - length,
2768 g_tape_stream);
2769 }
2770 fwrite(datablock, 1, length, fout);
2771 g_tape_posK += length;
2772 }
2773 }
2774 paranoid_fclose(fout);
2775 sprintf(command,
2776 "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
2777 datadisks_fname);
2778 run_program_and_log_output(command, 4);
2779 read_header_block_from_stream(&llt, tmp, &i);
2780 read_header_block_from_stream(&llt, tmp, &i);
[1]2781
[128]2782 unlink(datadisks_fname);
2783 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
2784 retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo strcpy(bkpinfo->media_device, monitas_device);
2785
2786
2787 load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);
2788 iamhere("FIXME");
2789 fatal_error("This will fail");
2790 sprintf(command,
[911]2791 "grep -E '^%s.*$' %s > %s",
[273]2792 restore_this_directory, g_filelist_full, g_filelist_full);
[128]2793 if (system(command)) {
2794 retval++;
2795 log_to_screen
[541]2796 ("Error(s) occurred while processing filelist and wildcard");
[128]2797 }
2798 iamhere("FIXME");
2799 fatal_error("This will fail");
2800 sprintf(command,
[911]2801 "grep -E '^%s.*$' %s > %s",
[273]2802 restore_this_directory, g_biggielist_txt, g_biggielist_txt);
[128]2803 if (system(command)) {
2804 log_msg(1,
2805 "Error(s) occurred while processing biggielist and wildcard");
2806 }
2807 sprintf(command, "touch %s", g_biggielist_txt);
2808 run_program_and_log_output(command, FALSE);
[1]2809// filelist = load_filelist(g_filelist_restthese); // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
[128]2810 retval += restore_everything(bkpinfo, filelist);
2811 free_filelist(filelist);
2812 log_msg(2, "--------End of restore_live_from_monitas_server--------");
2813 return (retval);
[1]2814}
[128]2815
[1]2816/**************************************************************************
2817 *END_RESTORE_LIVE_FROM_MONITAS_SERVER *
2818 **************************************************************************/
2819
2820
2821
2822
[128]2823extern void wait_until_software_raids_are_prepped(char *, int);
[1]2824
2825
2826char which_restore_mode(void);
2827
2828
2829/**
2830 * Log a "don't panic" message to the logfile.
2831 */
2832void welcome_to_mondorestore()
2833{
[251]2834 log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
[128]2835 log_msg(0,
2836 "DON'T PANIC! Mondorestore logs almost everything, so please ");
2837 log_msg(0,
2838 "don't break out in a cold sweat just because you see a few ");
2839 log_msg(0,
2840 "error messages in the log. Read them; analyze them; see if ");
2841 log_msg(0,
2842 "they are significant; above all, verify your backups! Please");
2843 log_msg(0,
2844 "attach a compressed copy of this log to any e-mail you send ");
2845 log_msg(0,
2846 "to the Mondo mailing list when you are seeking technical ");
2847 log_msg(0,
[607]2848 "support. Without it, we can't help you. - DevTeam");
[128]2849 log_msg(0,
2850 "------------------------------------------------------------");
2851 log_msg(0,
2852 "BTW, despite (or perhaps because of) the wealth of messages,");
2853 log_msg(0,
2854 "some users are inclined to stop reading this log. If Mondo ");
2855 log_msg(0,
2856 "stopped for some reason, chances are it's detailed here. ");
2857 log_msg(0,
2858 "More than likely there's a message at the very end of this ");
2859 log_msg(0,
2860 "log that will tell you what is wrong. Please read it! ");
2861 log_msg(0,
2862 "------------------------------------------------------------");
[1]2863}
2864
2865
2866
2867/**
2868 * Restore the user's data.
2869 * What did you think it did, anyway? :-)
2870 */
[128]2871int main(int argc, char *argv[])
[1]2872{
[128]2873 FILE *fin;
2874 FILE *fout;
2875 int retval = 0;
2876 int res;
[1]2877// int c;
[128]2878 char *tmp;
[1]2879
[128]2880 struct mountlist_itself *mountlist;
2881 struct raidlist_itself *raidlist;
2882 struct s_bkpinfo *bkpinfo;
2883 struct s_node *filelist;
2884 char *a, *b;
[818]2885 bool run_postnuke = FALSE;
[1]2886
2887 /**************************************************************************
2888 * hugo- *
2889 * busy stuff here - it needs some comments -stan *
2890 * *
2891 **************************************************************************/
[128]2892 if (getuid() != 0) {
[541]2893 fprintf(stderr, "Please run as root.\r\n");
[128]2894 exit(127);
2895 }
[1]2896
[128]2897 g_loglevel = DEFAULT_MR_LOGLEVEL;
2898 malloc_string(tmp);
2899
[1]2900/* Configure global variables */
2901#ifdef __FreeBSD__
[128]2902 if (strstr
2903 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
2904 "textonly"))
[1]2905#else
[128]2906 if (strstr
2907 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
2908 "textonly"))
[1]2909#endif
[128]2910 {
2911 g_text_mode = TRUE;
2912 log_msg(1, "TEXTONLY MODE");
2913 } else {
2914 g_text_mode = FALSE;
2915 } // newt :-)
2916 if (!
2917 (bkpinfo = g_bkpinfo_DONTUSETHIS =
2918 malloc(sizeof(struct s_bkpinfo)))) {
2919 fatal_error("Cannot malloc bkpinfo");
2920 }
2921 if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
2922 fatal_error("Cannot malloc mountlist");
2923 }
2924 if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
2925 fatal_error("Cannot malloc raidlist");
2926 }
[1]2927
[128]2928 malloc_libmondo_global_strings();
[1]2929
[128]2930 strcpy(g_mondo_home,
2931 call_program_and_get_last_line_of_output("which mondorestore"));
2932 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
2933 make_hole_for_dir(g_tmpfs_mountpt);
2934 g_current_media_number = 1; // precaution
[1]2935
[128]2936 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
2937 run_program_and_log_output("mkdir -p /mnt/floppy", FALSE);
[1]2938
[128]2939 malloc_string(tmp);
2940 malloc_string(a);
2941 malloc_string(b);
2942 setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc.
2943 reset_bkpinfo(bkpinfo);
2944 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
2945 bkpinfo->restore_data = TRUE; // Well, yeah :-)
2946 if (am_I_in_disaster_recovery_mode()) {
2947 run_program_and_log_output("mount / -o remount,rw", 2);
2948 } // for b0rken distros
2949 g_main_pid = getpid();
2950 srandom((int) (time(NULL)));
2951 register_pid(getpid(), "mondo");
2952 set_signals(TRUE);
2953 g_kernel_version = get_kernel_version();
[1]2954
[128]2955 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
2956 if (strlen(g_mountlist_fname) < 3) {
2957 fatal_error
2958 ("Serious error in malloc()'ing. Could be a bug in your glibc.");
2959 }
2960 mkdir(MNT_CDROM, 0x770);
2961
[1]2962/* Backup original mountlist.txt */
[128]2963 sprintf(tmp, "%s.orig", g_mountlist_fname);
2964 if (!does_file_exist(g_mountlist_fname)) {
2965 log_msg(2,
2966 "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
2967 __LINE__, g_mountlist_fname);
2968 } else if (!does_file_exist(tmp)) {
2969 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
2970 g_mountlist_fname);
2971 run_program_and_log_output(tmp, FALSE);
2972 }
[1]2973
2974/* Init directories */
[128]2975 make_hole_for_dir(bkpinfo->tmpdir);
2976 sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir);
2977 run_program_and_log_output(tmp, FALSE);
2978 make_hole_for_dir("/var/log");
2979 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */
2980 run_program_and_log_output("umount " MNT_CDROM, FALSE);
2981 run_program_and_log_output
2982 ("ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log",
2983 FALSE);
[1]2984
[128]2985 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
[1]2986
2987/* Init GUI */
[128]2988 malloc_libmondo_global_strings();
2989 setup_newt_stuff(); /* call newtInit and setup screen log */
2990 welcome_to_mondorestore();
2991 if (bkpinfo->disaster_recovery) {
2992 log_msg(1, "I am in disaster recovery mode");
2993 } else {
2994 log_msg(1, "I am in normal, live mode");
2995 }
[1]2996
[128]2997 iamhere("what time is it");
[1]2998
2999/* Process command-line parameters */
[128]3000 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
[1]3001#ifdef __FreeBSD__
[128]3002 system("mv -f /tmp/raidconf.txt /etc/raidtab");
3003 if (!does_file_exist("/etc/raidtab"))
3004 system("vinum printconfig > /etc/raidtab");
[1]3005#endif
[128]3006 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3007 if (!does_file_exist(g_mountlist_fname)) {
3008 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3009 }
3010 res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
[1]3011#ifdef __FreeBSD__
[128]3012 system("mv -f /etc/raidtab /tmp/raidconf.txt");
[1]3013#endif
[128]3014 paranoid_MR_finish(res);
3015 }
[1]3016
[128]3017 g_loglevel = DEFAULT_MR_LOGLEVEL;
3018 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
3019 fout = fopen("/tmp/out.txt", "w");
3020 fput_string_one_char_at_a_time(stderr, argv[2]);
3021 finish(0);
3022 }
[1]3023
[128]3024 if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
3025 make_grub_install_scriptlet(argv[2]);
3026 finish(0);
3027 }
[1]3028
[128]3029 if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
3030 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
3031 system("mount " MNT_CDROM);
3032 }
3033 bkpinfo->compression_level = 1;
3034 g_current_media_number = 2;
3035 strcpy(bkpinfo->restore_path, "/tmp/TESTING");
3036 bkpinfo->backup_media_type = dvd;
[541]3037 open_progress_form("Reassembling /dev/hda1",
3038 "Shark is a bit of a silly person.",
3039 "Please wait. This may take some time.",
[128]3040 "", 1999);
3041 system("rm -Rf /tmp/*pih*");
[1]3042
[128]3043 restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
3044 }
[1]3045
[128]3046 if (argc == 5 && strcmp(argv[1], "--common") == 0) {
3047 g_loglevel = 6;
3048 filelist = load_filelist(argv[2]);
3049 if (!filelist) {
3050 fatal_error("Failed to load filelist");
3051 }
3052 toggle_node_selection(filelist, FALSE);
3053 toggle_all_root_dirs_on(filelist);
[179]3054 // BERLIOS: /usr/lib ???
[128]3055 toggle_path_selection(filelist, "/usr/share", TRUE);
[1]3056// show_filelist(filelist);
[128]3057 save_filelist(filelist, "/tmp/out.txt");
[1]3058// finish(0);
3059// toggle_path_selection (filelist, "/root/stuff", TRUE);
[128]3060 strcpy(a, argv[3]);
3061 strcpy(b, argv[4]);
[1]3062
[128]3063 res = save_filelist_entries_in_common(a, filelist, b, FALSE);
3064 free_filelist(filelist);
3065 printf("res = %d", res);
3066 finish(0);
3067 }
[1]3068
[128]3069 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
3070 popup_changelist_from_file(argv[2]);
3071 paranoid_MR_finish(0);
3072 }
[1]3073
[128]3074 if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
3075 log_msg(1, "SCORE");
3076 g_loglevel = 10;
3077 if (strstr(argv[2], "save")) {
3078 log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
3079 fin = fopen(argv[3], "r");
3080 fout = fopen(argv[4], "w");
3081 copy_from_src_to_dest(fin, fout, 'w');
3082 fclose(fin);
3083 fin = fopen(argv[3], "r");
3084 copy_from_src_to_dest(fin, fout, 'w');
3085 fclose(fout);
3086 fclose(fin);
3087 } else if (strstr(argv[2], "restore")) {
3088 fout = fopen(argv[3], "w");
3089 fin = fopen(argv[4], "r");
3090 copy_from_src_to_dest(fout, fin, 'r');
3091 fclose(fin);
3092 fin = fopen(argv[4], "r");
3093 copy_from_src_to_dest(fout, fin, 'r');
3094 fclose(fout);
3095 fclose(fin);
3096 } else {
3097 fatal_error("Unknown additional param");
3098 }
3099 finish(0);
3100 }
[1]3101
[128]3102 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
3103 wait_until_software_raids_are_prepped(argv[2], 100);
3104 finish(0);
3105 }
[1]3106
[558]3107 if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
3108 finish(create_raidtab_from_mdstat(argv[2]));
[128]3109 }
[1]3110
[128]3111
3112 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
3113 retval = run_grub(FALSE, "/dev/hda");
3114 if (retval) {
[541]3115 log_to_screen("Failed to write Master Boot Record");
[128]3116 }
3117 paranoid_MR_finish(0);
[1]3118 }
[128]3119 if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
3120 g_current_media_number = atoi(argv[2]);
3121 pause_and_ask_for_cdr(5, NULL);
3122 paranoid_MR_finish(0);
3123 } else if (!bkpinfo->disaster_recovery) { // live!
3124 if (argc != 1) {
3125 popup_and_OK
[541]3126 ("Live mode doesn't support command-line parameters yet.");
[128]3127 paranoid_MR_finish(1);
3128// return(1);
3129 }
3130 log_msg(1, "I am in normal, live mode.");
3131 log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
3132 mount_boot_if_necessary(); /* for Gentoo users */
3133 log_msg(2, "Still here.");
3134 if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) {
3135 g_restoring_live_from_cd = TRUE;
3136 }
3137 if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) {
3138 retval =
3139 restore_live_from_monitas_server(bkpinfo,
3140 argv[2],
3141 argv[3], argv[4]);
3142 } else {
3143 log_msg(2, "Calling restore_to_live_filesystem()");
3144 retval = restore_to_live_filesystem(bkpinfo);
3145 }
3146 log_msg(2, "Still here. Yay.");
3147 if (strlen(bkpinfo->tmpdir) > 0) {
3148 sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
3149 run_program_and_log_output(tmp, FALSE);
3150 }
3151 unmount_boot_if_necessary(); /* for Gentoo users */
3152 paranoid_MR_finish(retval);
3153 } else {
[804]3154 /* Disaster recovery mode (must be) */
[128]3155 log_msg(1, "I must be in disaster recovery mode.");
3156 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
3157 if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) {
[541]3158 log_to_screen("Uh, that hasn't been implemented yet.");
[128]3159 paranoid_MR_finish(1);
3160 }
[1]3161
[128]3162 iamhere("About to call load_mountlist and load_raidtab");
3163 strcpy(bkpinfo->restore_path, MNT_RESTORING);
3164 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
3165 retval = load_mountlist(mountlist, g_mountlist_fname);
3166 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3167 iamhere
3168 ("Returned from calling load_mountlist and load_raidtab successfully");
[1]3169
[128]3170 if (argc > 1
3171 && (strcmp(argv[1], "--compare") == 0
3172 || strcmp(argv[1], "--nuke") == 0)) {
3173 if (bkpinfo->backup_media_type == nfs
3174 && !is_this_device_mounted(bkpinfo->nfs_mount)) {
3175 log_msg(1, "Mounting nfs dir");
3176 sprintf(bkpinfo->isodir, "/tmp/isodir");
3177 run_program_and_log_output("mkdir -p /tmp/isodir", 5);
3178 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir",
3179 bkpinfo->nfs_mount);
3180 run_program_and_log_output(tmp, 1);
3181 }
3182 }
[1]3183
3184
[128]3185 if (retval) {
3186 log_to_screen
[541]3187 ("Warning - load_raidtab_into_raidlist returned an error");
[128]3188 }
[1]3189
3190
[128]3191 log_msg(1, "Send in the clowns.");
[1]3192
[128]3193 if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) {
3194 log_msg(0, "Partitioning only.");
3195 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3196 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3197 load_mountlist(mountlist, g_mountlist_fname);
3198 res = partition_everything(mountlist);
3199 finish(res);
3200 }
[1]3201
[128]3202 if (argc == 2 && strcmp(argv[1], "--format-only") == 0) {
3203 log_msg(0, "Formatting only.");
3204 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3205 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3206 load_mountlist(mountlist, g_mountlist_fname);
[558]3207 res = format_everything(mountlist, FALSE, raidlist);
[128]3208 finish(res);
3209 }
[1]3210
[128]3211 if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) {
3212 log_msg(0, "Stopping LVM and RAID");
3213 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3214 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3215 load_mountlist(mountlist, g_mountlist_fname);
3216 res = do_my_funky_lvm_stuff(TRUE, FALSE);
3217 res += stop_all_raid_devices(mountlist);
3218 finish(res);
3219 }
3220
3221 if (argc == 2 && strcmp(argv[1], "--nuke") == 0) {
3222 iamhere("nuking");
3223 retval += nuke_mode(bkpinfo, mountlist, raidlist);
3224 } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) {
3225 iamhere("catchall");
3226 retval += catchall_mode(bkpinfo, mountlist, raidlist);
3227 } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) {
3228 iamhere("compare");
3229 retval += compare_mode(bkpinfo, mountlist, raidlist);
3230 } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) {
3231 iamhere("iso");
3232 retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE);
3233 } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) {
3234 iamhere("mbr");
3235 retval = mount_all_devices(mountlist, TRUE);
3236 if (!retval) {
3237 retval += run_boot_loader(FALSE);
3238 retval += unmount_all_devices(mountlist);
3239 }
3240 if (retval) {
[541]3241 log_to_screen("Failed to write Master Boot Record");
[128]3242 }
3243 } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) {
3244 iamhere("isonuke");
3245 retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE);
3246 } else if (argc != 1) {
[541]3247 log_to_screen("Invalid paremeters");
[128]3248 paranoid_MR_finish(1);
3249 } else {
3250 iamhere("catchall (no mode specified in command-line call");
3251 retval += catchall_mode(bkpinfo, mountlist, raidlist);
3252 }
[1]3253 }
[128]3254
3255 /* clean up at the end */
3256 if (retval) {
3257 if (does_file_exist("/tmp/changed.files")) {
3258 log_to_screen
[541]3259 ("See /tmp/changed.files for list of files that have changed.");
[128]3260 }
3261 mvaddstr_and_log_it(g_currentY++,
3262 0,
[541]3263 "Run complete. Errors were reported. Please review the logfile.");
[128]3264 } else {
3265 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3266 mvaddstr_and_log_it(g_currentY++,
3267 0,
[541]3268 "Run complete. Please remove floppy/CD/media and reboot.");
[128]3269 } else {
3270 run_program_and_log_output("sync", FALSE);
3271 if (is_this_device_mounted(MNT_CDROM)) {
3272 res =
3273 run_program_and_log_output("umount " MNT_CDROM, FALSE);
3274 } else {
3275 res = 0;
3276 }
3277
3278 if (!bkpinfo->please_dont_eject) {
3279 res = eject_device("/dev/cdrom");
[1]3280/*
3281 if (res)
3282 {
3283 log_to_screen( "WARNING - failed to eject CD-ROM disk" );
3284 }
3285*/
[128]3286 }
3287 mvaddstr_and_log_it(g_currentY++,
3288 0,
[541]3289 "Run complete. Please remove media and reboot.");
[128]3290 }
[1]3291 }
3292
3293// g_I_have_just_nuked is set true by nuke_mode() just before it returns
[818]3294 if (!system("which post-nuke > /dev/null 2> /dev/null")) {
3295 log_msg(1, "post-nuke found; find out whether we should run it...");
3296 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
3297 run_postnuke = TRUE;
3298 log_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
3299 } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
3300 run_postnuke = TRUE;
3301 log_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
3302 } else {
3303 run_postnuke = FALSE;
3304 log_msg(1, "No, will not run post-nuke.");
3305 }
3306 } else {
3307 log_msg(1, "No post-nuke found.");
[128]3308 }
[818]3309 if (run_postnuke) {
3310 log_to_screen("Running post-nuke...");
3311 if (mount_all_devices(mountlist, TRUE)) {
3312 log_to_screen
3313 ("Unable to re-mount partitions for post-nuke stuff");
3314 } else {
3315 log_msg(1, "Re-mounted partitions for post-nuke stuff");
3316 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
3317 retval);
3318 log_msg(2, "Calling '%s'", tmp);
3319 if ((res = run_program_and_log_output(tmp, 0))) {
3320 log_OS_error(tmp);
3321 }
3322 log_msg(1, "post-nuke returned w/ res=%d", res);
3323 }
3324 unmount_all_devices(mountlist);
3325 log_to_screen("I've finished post-nuking.");
3326 }
3327
[1]3328/*
3329 log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
3330 log_to_screen("Otherwise, please wait until the RAID disks are done.");
3331 wait_until_software_raids_are_prepped("/proc/mdstat", 100);
3332 log_to_screen("Thank you.");
[128]3333*/
3334 unlink("/tmp/mondo-run-prog.tmp");
3335 set_signals(FALSE);
3336 sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
3337 run_program_and_log_output(tmp, FALSE);
3338 log_to_screen
[541]3339 ("Restore log copied to /tmp/mondo-restore.log on your hard disk");
[128]3340 sprintf(tmp,
[541]3341 "Mondo-restore is exiting (retval=%d) ",
[128]3342 retval);
3343 log_to_screen(tmp);
3344 sprintf(tmp, "umount %s", bkpinfo->isodir);
3345 run_program_and_log_output(tmp, 5);
3346 paranoid_free(mountlist);
3347 paranoid_free(raidlist);
3348 if (am_I_in_disaster_recovery_mode()) {
3349 run_program_and_log_output("mount / -o remount,rw", 2);
3350 } // for b0rken distros
3351 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
3352 free_libmondo_global_strings(); // it's fine to have this here :) really :)
3353 paranoid_free(a);
3354 paranoid_free(b);
3355 paranoid_free(tmp);
[1]3356
[128]3357 unlink("/tmp/filelist.full");
3358 unlink("/tmp/filelist.full.gz");
3359
3360 exit(retval);
[1]3361}
3362
3363/**************************************************************************
3364 *END_MAIN *
3365 **************************************************************************/
3366
3367
3368
3369
3370
3371/**************************************************************************
3372 *END_MONDO-RESTORE.C *
3373 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.