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

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

More conf file items handled

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