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

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

Fix #114

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