source: MondoRescue/branches/stable/mondo/src/mondorestore/mondorestore.c@ 1625

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

remove g_loglevel and replaced with mr_conf->log_level

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