source: MondoRescue/branches/3.1/mondo/src/mondorestore/mondorestore.c@ 3147

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