source: MondoRescue/trunk/mondo/src/mondorestore/mondo-restore.c@ 1079

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

merge -r1045:1078 £SVN_M/branches/stable

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