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

Last change on this file since 783 was 783, checked in by Bruno Cornec, 18 years ago
  • Massive rewrite continues for memory management.
  • main structure should now have all parameters allocated dynamically
  • new lib libmr.a + dir + build process reviewed to support it.
  • new include subdir to host external definitions of the new lib
  • code now compiles. Still one remaining link issues for mondorestore. This should allow for some tests soon.

(goal is to separate completely reviewed code and functions and provide clean interfaces)

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