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

Last change on this file since 3161 was 3161, checked in by Bruno Cornec, 11 years ago
  • Apply fixes to 3.1 tree so that at least mondo compiles again (but that branch probably doesn't work at all again).
  • Property svn:keywords set to Id
File size: 93.8 KB
Line 
1/***************************************************************************
2$Id: mondorestore.c 3161 2013-06-25 20:53:14Z 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 3161 2013-06-25 20:53:14Z 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 if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) {
1233 // FIXME
1234 }
1235 chmod(outfile_fname, biggiestruct.properties.st_mode);
1236 ubuf->actime = biggiestruct.properties.st_atime;
1237 ubuf->modtime = biggiestruct.properties.st_mtime;
1238 utime(outfile_fname, ubuf);
1239 }
1240 mr_free(outfile_fname);
1241 paranoid_free(bigblk);
1242
1243 return (retval);
1244}
1245
1246/**************************************************************************
1247 *END_ RESTORE_A_BIGGIEFILE_FROM_CD *
1248 **************************************************************************/
1249
1250
1251
1252/**
1253 * Restore a biggiefile from the currently opened stream.
1254 * @param bkpinfo The backup information structure. Fields used:
1255 * - @c bkpinfo->restore_path
1256 * - @c bkpinfo->zip_exe
1257 * @param orig_bf_fname The original filename of the biggiefile.
1258 * @param biggiefile_number The number of the biggiefile (starting from 0).
1259 * @param orig_checksum Unused.
1260 * @param biggiefile_size Unused.
1261 * @param filelist The node structure containing the list of files to be restored.
1262 * If @p orig_bf_fname is not in the list, it will be ignored.
1263 * @return 0 for success (or skip), nonzero for failure.
1264 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL).
1265 */
1266int restore_a_biggiefile_from_stream(char *orig_bf_fname, long biggiefile_number, char *orig_checksum, //UNUSED
1267 long long biggiefile_size, //UNUSED
1268 struct s_node *filelist,
1269 int use_ntfsprog,
1270 char *pathname_of_last_file_restored)
1271{
1272 FILE *pout;
1273 FILE *fin;
1274
1275 /** mallocs ********/
1276 char *tmp = NULL;
1277 char *tmp1 = NULL;
1278 char *command = NULL;
1279 char *outfile_fname = NULL;
1280 char *sz_devfile = NULL;
1281 char *ntfsprog_fifo = NULL;
1282 char *file_to_openout = NULL;
1283
1284 struct s_node *node;
1285
1286 int old_loglevel;
1287 long current_slice_number = 0;
1288 int retval = 0;
1289 int res = 0;
1290 int ctrl_chr = '\0';
1291 long long slice_siz;
1292 bool dummy_restore = FALSE;
1293 bool use_ntfsprog_hack = FALSE;
1294 pid_t pid;
1295 struct s_filename_and_lstat_info biggiestruct;
1296 struct utimbuf the_utime_buf, *ubuf;
1297 ubuf = &the_utime_buf;
1298
1299 malloc_string(tmp);
1300 old_loglevel = g_loglevel;
1301 assert(bkpinfo != NULL);
1302 assert(orig_bf_fname != NULL);
1303 assert(orig_checksum != NULL);
1304
1305 pathname_of_last_file_restored[0] = '\0';
1306 if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
1307 use_ntfsprog = 1;
1308 log_msg(1, "%s --- pih=YES", orig_bf_fname);
1309 } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
1310 use_ntfsprog = 0;
1311 log_msg(1, "%s --- pih=NO", orig_bf_fname);
1312 } else {
1313 use_ntfsprog = 0;
1314 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
1315 }
1316
1317 strncpy(pathname_of_last_file_restored, orig_bf_fname,
1318 MAX_STR_LEN - 1);
1319 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1320
1321 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
1322
1323 if (filelist != NULL) {
1324 node = find_string_at_node(filelist, orig_bf_fname);
1325 if (!node) {
1326 dummy_restore = TRUE;
1327 log_msg(1,
1328 "Skipping big file %ld (%s) - not in biggielist subset",
1329 biggiefile_number + 1, orig_bf_fname);
1330 pathname_of_last_file_restored[0] = '\0';
1331 } else if (!(node->selected)) {
1332 dummy_restore = TRUE;
1333 log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1334 orig_bf_fname);
1335 pathname_of_last_file_restored[0] = '\0';
1336 }
1337 }
1338
1339 if (use_ntfsprog) {
1340 if (strncmp(orig_bf_fname, "/dev/", 5)) {
1341 log_msg(1,
1342 "I was in error when I set use_ntfsprog to TRUE.");
1343 log_msg(1, "%s isn't even in /dev", orig_bf_fname);
1344 use_ntfsprog = FALSE;
1345 }
1346 }
1347
1348 if (use_ntfsprog) {
1349 g_loglevel = 4;
1350 mr_asprintf(outfile_fname, "%s", orig_bf_fname);
1351 use_ntfsprog_hack = TRUE;
1352 log_msg(2, "Calling ntfsclone in background because %s is a /dev entry", outfile_fname);
1353 mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
1354 mkfifo(sz_devfile, 0x770);
1355 mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
1356 mr_free(sz_devfile);
1357
1358 file_to_openout = ntfsprog_fifo;
1359 switch (pid = fork()) {
1360 case -1:
1361 fatal_error("Fork failure");
1362 case 0:
1363 log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", outfile_fname, ntfsprog_fifo);
1364 res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
1365 mr_free(ntfsprog_fifo);
1366 exit(res);
1367 break;
1368 default:
1369 log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
1370 }
1371 mr_free(ntfsprog_fifo);
1372 } else {
1373 if (!strncmp(orig_bf_fname, "/dev/", 5)) {
1374 // non-NTFS partition
1375 mr_asprintf(outfile_fname, "%s", orig_bf_fname);
1376 } else {
1377 // biggiefile
1378 mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname);
1379 }
1380 use_ntfsprog_hack = FALSE;
1381 file_to_openout = outfile_fname;
1382 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
1383 {
1384 make_hole_for_file(outfile_fname);
1385 }
1386 log_msg(2, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname);
1387 }
1388
1389 if (dummy_restore) {
1390 mr_free(outfile_fname);
1391 mr_asprintf(outfile_fname, "/dev/null");
1392 }
1393
1394 if (bkpinfo->zip_exe == NULL) {
1395 mr_asprintf(command, "cat > \"%s\"", file_to_openout);
1396 } else {
1397 mr_asprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE);
1398 if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
1399 /* Ignore SIGPIPE for gzip as it causes errors on big files
1400 * Cf: http://trac.mondorescue.org/ticket/244 */
1401 signal(SIGPIPE,SIG_IGN);
1402 }
1403 }
1404 log_msg(3, "Pipe command = '%s'", command);
1405
1406 /* restore biggiefile, one slice at a time */
1407 if (!(pout = popen(command, "w"))) {
1408 fatal_error("Cannot pipe out");
1409 }
1410 mr_free(command);
1411
1412 for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1413 ctrl_chr != BLK_STOP_A_BIGGIE;
1414 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
1415 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
1416 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
1417 }
1418 log_msg(2, "Working on file #%ld, slice #%ld ", biggiefile_number + 1, current_slice_number);
1419 if (!g_text_mode) {
1420 newtDrawRootText(0, g_noof_rows - 2, tmp);
1421 newtRefresh();
1422 }
1423 strip_spaces(tmp);
1424 update_progress_form(tmp);
1425 if (current_slice_number == 0) {
1426 res =
1427 read_file_from_stream_to_file("/tmp/biggie-blah.txt",
1428 slice_siz);
1429 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
1430 log_OS_error("blah blah");
1431 } else {
1432 if (fread
1433 ((void *) &biggiestruct, 1, sizeof(biggiestruct),
1434 fin) < sizeof(biggiestruct)) {
1435 log_msg(2,
1436 "Warning - unable to get biggiestruct of bigfile #%d",
1437 biggiefile_number + 1);
1438 }
1439 paranoid_fclose(fin);
1440 }
1441 } else {
1442 res =
1443 read_file_from_stream_to_stream(pout, slice_siz);
1444 }
1445 retval += res;
1446 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1447 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
1448 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
1449 }
1450 current_slice_number++;
1451 g_current_progress++;
1452 }
1453 paranoid_pclose(pout);
1454
1455 if (bkpinfo->zip_exe != NULL) {
1456 if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
1457 /* Re-enable SIGPIPE for gzip */
1458 signal(SIGPIPE, terminate_daemon);
1459 }
1460 }
1461
1462 log_msg(1, "pathname_of_last_file_restored is now %s",
1463 pathname_of_last_file_restored);
1464
1465 if (use_ntfsprog_hack) {
1466 log_msg(3, "Waiting for ntfsclone to finish");
1467 mr_asprintf(tmp1, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
1468 while (system(tmp1) == 0) {
1469 sleep(1);
1470 }
1471 mr_free(tmp1);
1472 log_msg(3, "OK, ntfsclone has really finished");
1473 }
1474
1475 log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
1476 log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
1477 if (strcmp(outfile_fname, "/dev/null")) {
1478 chmod(outfile_fname, biggiestruct.properties.st_mode);
1479 if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) {
1480 // FIXME
1481 }
1482 ubuf->actime = biggiestruct.properties.st_atime;
1483 ubuf->modtime = biggiestruct.properties.st_mtime;
1484 utime(outfile_fname, ubuf);
1485 }
1486 mr_free(outfile_fname);
1487
1488 paranoid_free(tmp);
1489 g_loglevel = old_loglevel;
1490 return (retval);
1491}
1492
1493/**************************************************************************
1494 *END_RESTORE_A_BIGGIEFILE_FROM_STREAM *
1495 **************************************************************************/
1496
1497
1498
1499/**
1500 * Restore @p tarball_fname from CD.
1501 * @param tarball_fname The filename of the tarball to restore (in /mnt/cdrom).
1502 * This will be used unmodified.
1503 * @param current_tarball_number The number (starting from 0) of the fileset
1504 * we're restoring now.
1505 * @param filelist The node structure containing the list of files to be
1506 * restored. If no file in the afioball is in this list, afio will still be
1507 * called, but nothing will be written.
1508 * @return 0 for success, nonzero for failure.
1509 */
1510int
1511restore_a_tarball_from_CD(char *tarball_fname,
1512 long current_tarball_number,
1513 struct s_node *filelist)
1514{
1515 int retval = 0;
1516 int res;
1517 char *p;
1518
1519 /** malloc **/
1520 char *command = NULL;
1521 char *tmp = NULL;
1522 char *filelist_name = NULL;
1523 char *filelist_subset_fname = NULL;
1524 char *executable = NULL;
1525 char *temp_log = NULL;
1526 long matches = 0;
1527 bool use_star;
1528 char *xattr_fname = NULL;
1529 char *acl_fname = NULL;
1530
1531 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1532
1533 log_msg(5, "Entering");
1534 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1535 mr_asprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
1536 run_program_and_log_output(command, 9);
1537 paranoid_free(command);
1538
1539 mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", current_tarball_number);
1540 if (length_of_file(filelist_name) <= 2) {
1541 log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name);
1542 log_msg(2, "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
1543 log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");
1544 retval = 0;
1545 mr_free(filelist_name);
1546 log_msg(5, "Leaving");
1547 return(0);
1548 }
1549 if (count_lines_in_file(filelist_name) <= 0 || length_of_file(tarball_fname) <= 0) {
1550 log_msg(3, "length_of_file(%s) = %llu", tarball_fname, length_of_file(tarball_fname));
1551 log_msg(3, "count_lines_in_file(%s) = %llu", tarball_fname, count_lines_in_file(tarball_fname));
1552 log_to_screen("Unable to restore fileset #%ld (CD I/O error)", current_tarball_number);
1553 mr_free(filelist_name);
1554 log_msg(5, "Leaving");
1555 return(1);
1556 }
1557
1558 if (filelist) {
1559 mr_asprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);
1560 if ((matches =
1561 save_filelist_entries_in_common(filelist_name, filelist,
1562 filelist_subset_fname,
1563 use_star)) <= 0) {
1564 log_msg(1, "Skipping fileset %ld", current_tarball_number);
1565 } else {
1566 log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);
1567 }
1568 log_to_screen("Tarball #%ld --- %ld matches", current_tarball_number, matches);
1569 }
1570 mr_free(filelist_name);
1571
1572 if (filelist == NULL || matches > 0) {
1573 if (g_getfattr) {
1574 mr_asprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
1575 }
1576 if (g_getfacl) {
1577 mr_asprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
1578 }
1579 if (strstr(tarball_fname, ".bz2")) {
1580 mr_asprintf(executable, "bzip2");
1581 } else if (strstr(tarball_fname, ".lzma")) {
1582 mr_asprintf(executable, "lzma");
1583 } else if (strstr(tarball_fname, ".gz")) {
1584 mr_asprintf(executable, "gzip");
1585 } else if (strstr(tarball_fname, ".lzo")) {
1586 mr_asprintf(executable, "lzop");
1587 }
1588 if (executable) {
1589 mr_asprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
1590 res = run_program_and_log_output(tmp, FALSE);
1591 mr_free(tmp);
1592
1593 if (res) {
1594 log_to_screen("(compare_a_tarball) Compression program %s not found - oh no!", executable);
1595 paranoid_MR_finish(1);
1596 }
1597 tmp = executable;
1598 mr_asprintf(executable, "-P %s -Z", tmp);
1599 mr_free(tmp);
1600 }
1601#ifdef __FreeBSD__
1602#define BUFSIZE 512
1603#else
1604#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
1605#endif
1606
1607 if (use_star) {
1608 mr_asprintf(command, "star -x -force-remove -sparse -U " STAR_ACL_SZ " file=%s", tarball_fname);
1609 if (strstr(tarball_fname, ".bz2")) {
1610 mr_strcat(command, " -bz");
1611 }
1612 } else {
1613 if (! executable) {
1614 log_msg(2, "Mo executable, this shouldn't happen !");
1615 } else {
1616 if (filelist_subset_fname != NULL) {
1617 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);
1618 } else {
1619 mr_asprintf(command, "afio -i -b %ld -c %ld -M 8m %s %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, tarball_fname);
1620 }
1621 }
1622 }
1623 mr_free(executable);
1624
1625#undef BUFSIZE
1626 mr_asprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), (int) (random() % 32768));
1627
1628 mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
1629 log_msg(1, "command = '%s'", command);
1630 unlink(temp_log);
1631 res = system(command);
1632 if (res) {
1633 p = strstr(command, "-acl ");
1634 if (p) {
1635 p[0] = p[1] = p[2] = p[3] = ' ';
1636 log_msg(1, "new command = '%s'", command);
1637 res = system(command);
1638 }
1639 }
1640 paranoid_free(command);
1641
1642 if (res && length_of_file(temp_log) < 5) {
1643 res = 0;
1644 }
1645
1646 if (! use_star) {
1647 if (g_getfattr) {
1648 log_msg(1, "Setting fattr list %s", xattr_fname);
1649 if (length_of_file(xattr_fname) > 0) {
1650 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1651 if (res) {
1652 log_to_screen("Errors occurred while setting extended attributes");
1653 } else {
1654 log_msg(1, "I set xattr OK");
1655 }
1656 retval += res;
1657 }
1658 }
1659 if (g_getfacl) {
1660 log_msg(1, "Setting acl list %s", acl_fname);
1661 if (length_of_file(acl_fname) > 0) {
1662 res = set_acl_list(filelist_subset_fname, acl_fname);
1663 if (res) {
1664 log_to_screen("Errors occurred while setting access control lists");
1665 } else {
1666 log_msg(1, "I set ACL OK");
1667 }
1668 retval += res;
1669 }
1670 }
1671 } else {
1672 retval = res;
1673 }
1674 // Be verbose for star
1675 if (retval || use_star) {
1676 mr_asprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
1677 paranoid_system(command);
1678 paranoid_free(command);
1679
1680 if (retval) {
1681 log_msg(2, "Errors occurred while processing fileset #%d", current_tarball_number);
1682 }
1683 } else {
1684 log_msg(2, "Fileset #%d processed OK", current_tarball_number);
1685 }
1686 unlink(temp_log);
1687 mr_free(temp_log);
1688 }
1689 if (does_file_exist("/PAUSE")) {
1690 popup_and_OK
1691 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
1692 }
1693 unlink(filelist_subset_fname);
1694 mr_free(filelist_subset_fname);
1695 if (g_getfattr) {
1696 unlink(xattr_fname);
1697 mr_free(xattr_fname);
1698 }
1699 if (g_getfacl) {
1700 unlink(acl_fname);
1701 mr_free(acl_fname);
1702 }
1703
1704 log_msg(5, "Leaving");
1705 return (retval);
1706}
1707
1708/**************************************************************************
1709 *END_RESTORE_A_TARBALL_FROM_CD *
1710 **************************************************************************/
1711
1712
1713/**
1714 * Restore a tarball from the currently opened stream.
1715 * @param bkpinfo The backup information structure. Fields used:
1716 * - @c bkpinfo->backup_media_type
1717 * - @c bkpinfo->media_device
1718 * - @c bkpinfo->zip_exe
1719 * @param tarball_fname The filename of the afioball to restore.
1720 * @param current_tarball_number The number (starting from 0) of the fileset
1721 * we're restoring now.
1722 * @param filelist The node structure containing the list of files to be
1723 * restored. If no file in the afioball is in this list, afio will still be
1724 * called, but nothing will be written.
1725 * @param size The size (in @b bytes) of the afioball.
1726 * @return 0 for success, nonzero for failure.
1727 */
1728int
1729restore_a_tarball_from_stream(char *tarball_fname,
1730 long current_tarball_number,
1731 struct s_node *filelist,
1732 long long size, char *xattr_fname,
1733 char *acl_fname)
1734{
1735 int retval = 0;
1736 int res = 0;
1737
1738 /** malloc add ***/
1739 char *mds = NULL;
1740 char *command = NULL;
1741 char *afio_fname = NULL;
1742 char *filelist_fname = NULL;
1743 char *filelist_subset_fname = NULL;
1744 char *executable = NULL;
1745 long matches = 0;
1746 bool restore_this_fileset = FALSE;
1747 bool use_star;
1748
1749 assert(bkpinfo != NULL);
1750 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1751
1752 /* to do it with a file... */
1753 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1754 mds = media_descriptor_string(bkpinfo->backup_media_type);
1755 log_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d",
1756 current_tarball_number, (long) size >> 10, mds, g_current_media_number);
1757 mr_free(mds);
1758
1759 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
1760
1761 /****************************************************************************
1762 * Use RAMDISK's /tmp; saves time; oh wait, it's too small *
1763 * Well, pipe from tape to afio, then; oh wait, can't do that either: bug *
1764 * in afio or someting; oh darn.. OK, use tmpfs :-) *
1765 ****************************************************************************/
1766 mr_asprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number);
1767 mr_asprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number);
1768 mr_asprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number);
1769
1770 res = read_file_from_stream_to_file(afio_fname, size);
1771 if (strstr(tarball_fname, ".star")) {
1772 bkpinfo->use_star = TRUE;
1773 }
1774 if (res) {
1775 log_msg(1, "Warning - error reading afioball from tape");
1776 }
1777 if (bkpinfo->compression_level == 0) {
1778 mr_asprintf(executable, "%s", "");
1779 } else {
1780 if (bkpinfo->use_star) {
1781 mr_asprintf(executable, "%s", " -bz");
1782 } else {
1783 mr_asprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
1784 }
1785 }
1786
1787 if (!filelist) // if unconditional restore then restore entire fileset
1788 {
1789 restore_this_fileset = TRUE;
1790 } else // If restoring selectively then get TOC from tarball
1791 {
1792 if (strstr(tarball_fname, ".star.")) {
1793 use_star = TRUE;
1794 mr_asprintf(command, "star -sparse -t file=%s %s", afio_fname, executable);
1795 } else {
1796 use_star = FALSE;
1797 mr_asprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, executable, afio_fname);
1798 }
1799 mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
1800 log_msg(1, "command = %s", command);
1801 if (system(command)) {
1802 log_msg(4, "Warning - error occurred while retrieving TOC");
1803 }
1804 mr_free(command);
1805
1806 if ((matches =
1807 save_filelist_entries_in_common(filelist_fname, filelist,
1808 filelist_subset_fname,
1809 use_star))
1810 <= 0 || length_of_file(filelist_subset_fname) < 2) {
1811 if (length_of_file(filelist_subset_fname) < 2) {
1812 log_msg(1, "No matches found in fileset %ld",
1813 current_tarball_number);
1814 }
1815 log_msg(2, "Skipping fileset %ld", current_tarball_number);
1816 restore_this_fileset = FALSE;
1817 } else {
1818 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
1819 matches, current_tarball_number,
1820 filelist_subset_fname);
1821 restore_this_fileset = TRUE;
1822 }
1823 }
1824
1825// Concoct the call to star/afio to restore files
1826 if (strstr(tarball_fname, ".star.")) {
1827 // star
1828 mr_asprintf(command, "star -sparse -x file=%s %s", afio_fname, executable);
1829 if (filelist) {
1830 mr_strcat(command, " list=%s", filelist_subset_fname);
1831 }
1832 } else {
1833 // afio
1834 mr_asprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable);
1835 if (filelist) {
1836 mr_strcat(command, " -w %s", filelist_subset_fname);
1837 }
1838 mr_strcat(command, " %s", afio_fname);
1839 }
1840 mr_strcat(command, " 2>> %s", MONDO_LOGFILE);
1841 mr_free(executable);
1842
1843// Call if IF there are files to restore (selectively/unconditionally)
1844 if (restore_this_fileset) {
1845 log_msg(1, "Calling command='%s'", command);
1846 paranoid_system(command);
1847
1848 if (g_getfattr) {
1849 log_it("Restoring xattr stuff");
1850 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1851 if (res) {
1852 log_msg(1, "Errors occurred while setting xattr");
1853 } else {
1854 log_msg(1, "I set xattr OK");
1855 }
1856 retval += res;
1857 }
1858
1859 if (g_getfacl) {
1860 log_it("Restoring acl stuff");
1861 res = set_acl_list(filelist_subset_fname, acl_fname);
1862 if (res) {
1863 log_msg(1, "Errors occurred while setting ACL");
1864 } else {
1865 log_msg(1, "I set ACL OK");
1866 }
1867 retval += res;
1868 }
1869
1870 } else {
1871 log_msg(1, "NOT CALLING '%s'", command);
1872 }
1873 mr_free(command);
1874
1875 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
1876 log_to_screen("Paused after set %ld", current_tarball_number);
1877 popup_and_OK("Pausing. Press ENTER to continue.");
1878 }
1879
1880 unlink(filelist_subset_fname);
1881 mr_free(filelist_subset_fname);
1882 unlink(filelist_fname);
1883 mr_free(filelist_fname);
1884 unlink(afio_fname);
1885 mr_free(afio_fname);
1886
1887 return (retval);
1888}
1889
1890/**************************************************************************
1891 *END_RESTORE_A_TARBALL_FROM_STREAM *
1892 **************************************************************************/
1893
1894
1895
1896
1897/**
1898 * Restore all biggiefiles from all media in this CD backup.
1899 * The CD with the last afioball should be currently mounted.
1900 * @param bkpinfo The backup information structure. @c backup_media_type is the
1901 * only field used in this function.
1902 * @param filelist The node structure containing the list of files to be
1903 * restored. If a prospective biggiefile is not in this list, it will be ignored.
1904 * @return 0 for success, nonzero for failure.
1905 */
1906int restore_all_biggiefiles_from_CD(struct s_node *filelist) {
1907
1908 int retval = 0;
1909 int res = 0;
1910 long noof_biggiefiles, bigfileno = 0, total_slices;
1911 /** malloc **/
1912 char *tmp1 = NULL;
1913 char *mds = NULL;
1914 bool just_changed_cds = FALSE;
1915 char *xattr_fname = NULL;
1916 char *acl_fname = NULL;
1917 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
1918 char *pathname_of_last_biggie_restored;
1919 FILE *fbw = NULL;
1920
1921 malloc_string(pathname_of_last_biggie_restored);
1922 assert(bkpinfo != NULL);
1923
1924 mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
1925 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
1926 log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
1927 }
1928
1929 tmp1 = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "total-slices");
1930 total_slices = atol(tmp1);
1931 mr_free(tmp1);
1932
1933 mr_asprintf(tmp1, "Reassembling large files ");
1934 mvaddstr_and_log_it(g_currentY, 0, tmp1);
1935 mr_free(tmp1);
1936
1937 if (length_of_file(BIGGIELIST) < 6) {
1938 log_msg(1, "OK, no biggielist; not restoring biggiefiles");
1939 return (0);
1940 }
1941 noof_biggiefiles = count_lines_in_file(BIGGIELIST);
1942 if (noof_biggiefiles <= 0) {
1943 log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles");
1944 return (0);
1945 }
1946 log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
1947
1948 open_progress_form("Reassembling large files",
1949 "I am now reassembling all the large files.",
1950 "Please wait. This may take some time.",
1951 "", total_slices);
1952 for (bigfileno = 0 ; bigfileno < noof_biggiefiles ;) {
1953 log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
1954 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
1955 log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
1956 mds = media_descriptor_string(bkpinfo->backup_media_type);
1957 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno + 1, mds, g_current_media_number);
1958 log_msg(3, "Slicename would have been %s",
1959 slice_fname(bigfileno, 0, ARCHIVES_PATH, ""));
1960 // I'm not positive 'just_changed_cds' is even necessary...
1961 if (just_changed_cds) {
1962 just_changed_cds = FALSE;
1963 log_msg(3, "I'll continue to scan this CD for bigfiles to be restored.");
1964 } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
1965 insist_on_this_cd_number(++g_current_media_number);
1966 log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
1967 just_changed_cds = TRUE;
1968 } else {
1969 /* That big file doesn't exist, but the followings may */
1970 /* So we need to continue looping */
1971 log_msg(2, "There was no bigfile #%ld. That's OK.", bigfileno + 1);
1972 log_msg(2, "I'm going to stop restoring bigfiles now.");
1973 retval++;
1974 bigfileno++;
1975 }
1976 mr_free(mds);
1977 } else {
1978 just_changed_cds = FALSE;
1979 mr_asprintf(tmp1, "Restoring big file %ld", bigfileno + 1);
1980 update_progress_form(tmp1);
1981 mr_free(tmp1);
1982 res = restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored);
1983 log_it("%s",pathname_of_last_biggie_restored);
1984 if (fbw && pathname_of_last_biggie_restored[0]) {
1985 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
1986 }
1987 retval += res;
1988 bigfileno++;
1989
1990 }
1991 }
1992
1993 if (fbw) {
1994 fclose(fbw);
1995 if (g_getfattr) {
1996 mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
1997 if (length_of_file(xattr_fname) > 0) {
1998 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
1999 }
2000 mr_free(xattr_fname);
2001 }
2002 if (g_getfacl) {
2003 mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2004 if (length_of_file(acl_fname) > 0) {
2005 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2006 }
2007 mr_free(acl_fname);
2008 }
2009 }
2010 mr_free(biggies_whose_EXATs_we_should_set);
2011
2012 if (does_file_exist("/PAUSE")) {
2013 popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2014 }
2015 close_progress_form();
2016 if (retval) {
2017 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2018 } else {
2019 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2020 }
2021 paranoid_free(pathname_of_last_biggie_restored);
2022 return (retval);
2023}
2024
2025/**************************************************************************
2026 *END_RESTORE_ALL_BIGGIFILES_FROM_CD *
2027 **************************************************************************/
2028
2029
2030
2031/**
2032 * Restore all afioballs from all CDs in the backup.
2033 * The first CD should be inserted (if not, it will be asked for).
2034 * @param bkpinfo The backup information structure. @c backup_media_type is the
2035 * only field used in @e this function.
2036 * @param filelist The node structure containing the list of files to be
2037 * restored. If no file in some particular afioball is in this list, afio will
2038 * still be called for that fileset, but nothing will be written.
2039 * @return 0 for success, or the number of filesets that failed.
2040 */
2041int
2042restore_all_tarballs_from_CD(struct s_node *filelist)
2043{
2044 int retval = 0;
2045 int res;
2046 int attempts;
2047 long current_tarball_number = 0;
2048 long max_val;
2049 /**malloc ***/
2050 char *mds = NULL;
2051 char *tmp1 = NULL;
2052 char *tarball_fname = NULL;
2053 char *progress_str = NULL;
2054
2055 assert(bkpinfo != NULL);
2056
2057 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2058 log_msg(2, "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER");
2059 if (g_current_media_number != 1) {
2060 log_msg(3, "OK, that's jacked up.");
2061 g_current_media_number = 1;
2062 }
2063 insist_on_this_cd_number(g_current_media_number);
2064 tmp1 = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "last-filelist-number");
2065 max_val = atol(tmp1) + 1;
2066 mr_free(tmp1);
2067
2068 mds = media_descriptor_string(bkpinfo->backup_media_type);
2069 mr_asprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);
2070
2071 log_to_screen(progress_str);
2072 open_progress_form("Restoring from archives",
2073 "Restoring data from the archives.",
2074 "Please wait. This may take some time.",
2075 progress_str, max_val);
2076 for (;;) {
2077 insist_on_this_cd_number(g_current_media_number);
2078 update_progress_form(progress_str);
2079 mr_free(progress_str);
2080
2081 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", current_tarball_number);
2082 if (!does_file_exist(tarball_fname)) {
2083 mr_free(tarball_fname);
2084 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz", 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.lzma", 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.lzo", 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.afio.", 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.bz2", current_tarball_number);
2101 }
2102 if (!does_file_exist(tarball_fname)) {
2103 mr_free(tarball_fname);
2104 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", current_tarball_number);
2105 }
2106 if (!does_file_exist(tarball_fname)) {
2107 if (current_tarball_number == 0) {
2108 log_to_screen
2109 ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
2110 mr_free(tarball_fname);
2111 return (0);
2112 }
2113 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2114 || system("find " MNT_CDROM
2115 "/archives/slice* > /dev/null 2> /dev/null") ==
2116 0) {
2117 break;
2118 }
2119 g_current_media_number++;
2120 mr_asprintf(progress_str, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
2121 log_to_screen(progress_str);
2122 } else {
2123 mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_tarball_number, mds, g_current_media_number);
2124 for (res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) {
2125 res = restore_a_tarball_from_CD(tarball_fname, current_tarball_number, filelist);
2126 }
2127 mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ", mds, g_current_media_number, current_tarball_number);
2128 if (res) {
2129 mr_strcat(tmp1, "reported errors");
2130 } else if (attempts > 1) {
2131 mr_strcat(tmp1, "succeeded");
2132 } else {
2133 mr_strcat(tmp1, "succeeded");
2134 }
2135 if (attempts > 1) {
2136 mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
2137 }
2138 if (attempts > 1) {
2139 log_to_screen(tmp1);
2140 }
2141 mr_free(tmp1);
2142
2143 retval += res;
2144 current_tarball_number++;
2145 g_current_progress++;
2146 }
2147 mr_free(tarball_fname);
2148
2149 /* Now we need to umount the current media to have the next mounted by insist_on_this_cd_number */
2150 /* run_program_and_log_output("umount " MNT_CDROM, FALSE); */
2151 }
2152 mr_free(mds);
2153 mr_free(progress_str);
2154
2155 close_progress_form();
2156 if (retval) {
2157 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2158 } else {
2159 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2160 }
2161
2162 return (retval);
2163}
2164
2165/**************************************************************************
2166 *END_RESTORE_ALL_TARBALLS_FROM_CD *
2167 **************************************************************************/
2168
2169
2170
2171/**
2172 * Restore all biggiefiles from the currently opened stream.
2173 * @param bkpinfo The backup information structure. Passed to other functions.
2174 * @param filelist The node structure containing the list of files to be
2175 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2176 * @return 0 for success, or the number of biggiefiles that failed.
2177 */
2178int
2179restore_all_biggiefiles_from_stream(struct s_node *filelist)
2180{
2181 long noof_biggiefiles;
2182 long current_bigfile_number = 0;
2183 long total_slices;
2184
2185 int retval = 0;
2186 int res = 0;
2187 int ctrl_chr;
2188
2189 /** malloc add ****/
2190 char *tmp1 = NULL;
2191 char *biggie_fname;
2192 char *biggie_cksum;
2193 char *xattr_fname = NULL;
2194 char *acl_fname = NULL;
2195 char *p;
2196 char *pathname_of_last_biggie_restored;
2197 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
2198 long long biggie_size;
2199 FILE *fbw = NULL;
2200
2201 malloc_string(biggie_fname);
2202 malloc_string(biggie_cksum);
2203 malloc_string(pathname_of_last_biggie_restored);
2204 assert(bkpinfo != NULL);
2205
2206 tmp1 = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "total-slices");
2207 total_slices = atol(tmp1);
2208 mr_free(tmp1);
2209
2210 if (g_getfattr) {
2211 mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2212 }
2213 if (g_getfacl) {
2214 mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2215 }
2216 mr_asprintf(tmp1, "Reassembling large files ");
2217 mvaddstr_and_log_it(g_currentY, 0, tmp1);
2218 mr_free(tmp1);
2219
2220 mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2221 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2222 log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
2223 }
2224
2225 // get xattr and acl files if they're there
2226 res = read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr);
2227 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2228 res = read_EXAT_files_from_tape(&biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname);
2229 }
2230
2231 noof_biggiefiles = atol(biggie_fname);
2232 log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
2233 open_progress_form("Reassembling large files",
2234 "I am now reassembling all the large files.",
2235 "Please wait. This may take some time.",
2236 "", total_slices);
2237
2238 for (res =
2239 read_header_block_from_stream(&biggie_size, biggie_fname,
2240 &ctrl_chr);
2241 ctrl_chr != BLK_STOP_BIGGIEFILES;
2242 res =
2243 read_header_block_from_stream(&biggie_size, biggie_fname,
2244 &ctrl_chr)) {
2245 if (ctrl_chr != BLK_START_A_NORMBIGGIE
2246 && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2247 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2248 }
2249 p = strrchr(biggie_fname, '/');
2250 if (!p) {
2251 p = biggie_fname;
2252 } else {
2253 p++;
2254 }
2255 mr_asprintf(tmp1, "Restoring big file %ld (%lld K)", current_bigfile_number + 1, biggie_size / 1024);
2256 update_progress_form(tmp1);
2257 mr_free(tmp1);
2258 res = restore_a_biggiefile_from_stream(biggie_fname,
2259 current_bigfile_number,
2260 biggie_cksum,
2261 biggie_size,
2262 filelist, ctrl_chr,
2263 pathname_of_last_biggie_restored);
2264 log_msg(1, "I believe I have restored %s",
2265 pathname_of_last_biggie_restored);
2266 if (fbw && pathname_of_last_biggie_restored[0]) {
2267 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2268 }
2269 retval += res;
2270 current_bigfile_number++;
2271
2272 }
2273 if (current_bigfile_number != noof_biggiefiles
2274 && noof_biggiefiles != 0) {
2275 log_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", current_bigfile_number, noof_biggiefiles);
2276 } else {
2277 log_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", noof_biggiefiles, current_bigfile_number);
2278 }
2279
2280 if (fbw) {
2281 fclose(fbw);
2282 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
2283 log_it("Setting biggie-EXATs");
2284 if (g_getfattr) {
2285 if (length_of_file(xattr_fname) > 0) {
2286 log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname);
2287 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2288 }
2289 }
2290 if (g_getfacl) {
2291 if (length_of_file(acl_fname) > 0) {
2292 log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname);
2293 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2294 }
2295 }
2296 } else {
2297 log_it("No biggiefiles selected. So, no biggie-EXATs to set.");
2298 }
2299 }
2300 mr_free(xattr_fname);
2301 mr_free(acl_fname);
2302 mr_free(biggies_whose_EXATs_we_should_set);
2303
2304 if (does_file_exist("/PAUSE")) {
2305 popup_and_OK
2306 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2307 }
2308
2309 close_progress_form();
2310 if (retval) {
2311 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2312 } else {
2313 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2314 }
2315 paranoid_free(pathname_of_last_biggie_restored);
2316 paranoid_free(biggie_fname);
2317 paranoid_free(biggie_cksum);
2318 return (retval);
2319}
2320
2321/**************************************************************************
2322 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM *
2323 **************************************************************************/
2324
2325
2326
2327
2328
2329
2330/**
2331 * Restore all afioballs from the currently opened tape stream.
2332 * @param bkpinfo The backup information structure. Fields used:
2333 * - @c bkpinfo->backup_media_type
2334 * - @c bkpinfo->restore_path
2335 * @param filelist The node structure containing the list of files to be
2336 * restored. If no file in an afioball is in this list, afio will still be
2337 * called for that fileset, but nothing will be written.
2338 * @return 0 for success, or the number of filesets that failed.
2339 */
2340int restore_all_tarballs_from_stream(struct s_node *filelist)
2341{
2342 int retval = 0;
2343 int res;
2344 long current_afioball_number = 0;
2345 int ctrl_chr;
2346 long max_val /*, total_noof_files */ ;
2347
2348 /** malloc **/
2349 char *tmp = NULL;
2350 char *mds = NULL;
2351 char *progress_str = NULL;
2352 char *tmp_fname;
2353 char *xattr_fname = NULL;
2354 char *acl_fname = NULL;
2355
2356 long long tmp_size;
2357
2358 malloc_string(tmp_fname);
2359 assert(bkpinfo != NULL);
2360 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2361 tmp = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "last-filelist-number");
2362 max_val = atol(tmp) + 1;
2363 mr_free(tmp);
2364
2365 if (chdir(bkpinfo->restore_path)) { /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
2366 //FIXME
2367 }
2368
2369 run_program_and_log_output("pwd", 5);
2370
2371 mr_asprintf(progress_str, "Restoring from media #%d", g_current_media_number);
2372 log_to_screen(progress_str);
2373 open_progress_form("Restoring from archives",
2374 "Restoring data from the archives.",
2375 "Please wait. This may take some time.",
2376 progress_str, max_val);
2377
2378 log_msg(3, "hey");
2379
2380 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2381 if (res) {
2382 log_msg(2, "Warning - error reading afioball from tape");
2383 }
2384 retval += res;
2385 if (ctrl_chr != BLK_START_AFIOBALLS) {
2386 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
2387 }
2388 log_msg(2, "ho");
2389 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2390 while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2391 update_progress_form(progress_str);
2392 if (g_getfattr) {
2393 mr_asprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
2394 unlink(xattr_fname);
2395 }
2396 if (g_getfacl) {
2397 mr_asprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
2398 unlink(acl_fname);
2399 }
2400 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2401 log_it("Reading EXAT files from tape");
2402 res = read_EXAT_files_from_tape(&tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname);
2403 }
2404 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2405 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2406 }
2407 log_msg(4, "Restoring from fileset #%ld (name=%s, size=%ld K)", current_afioball_number, tmp_fname, (long) tmp_size >> 10);
2408 res = restore_a_tarball_from_stream(tmp_fname, current_afioball_number, filelist, tmp_size, xattr_fname, acl_fname);
2409 retval += res;
2410 if (res) {
2411 log_to_screen("Fileset %ld - errors occurred", current_afioball_number);
2412 }
2413 res =
2414 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2415 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2416 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2417 }
2418
2419 current_afioball_number++;
2420 g_current_progress++;
2421 mds = media_descriptor_string(bkpinfo->backup_media_type),
2422
2423 mr_free(progress_str);
2424 mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_afioball_number, mds, g_current_media_number);
2425 mr_free(mds);
2426 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2427 if (g_getfattr) {
2428 unlink(xattr_fname);
2429 }
2430 if (g_getfacl) {
2431 unlink(acl_fname);
2432 }
2433 } // next
2434 mr_free(progress_str);
2435 if (g_getfattr) {
2436 mr_free(xattr_fname);
2437 }
2438 if (g_getfacl) {
2439 mr_free(acl_fname);
2440 }
2441
2442 log_msg(1, "All done with afioballs");
2443 close_progress_form();
2444 if (retval) {
2445 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2446 } else {
2447 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2448 }
2449 paranoid_free(tmp_fname);
2450 return (retval);
2451}
2452
2453/**************************************************************************
2454 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM *
2455 **************************************************************************/
2456
2457/* @} - end of LLrestoreGroup */
2458
2459
2460/**
2461 * Restore all files in @p filelist.
2462 * @param bkpinfo The backup information structure. Most fields are used.
2463 * @param filelist The node structure containing the list of files to be
2464 * restored.
2465 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2466 * @ingroup restoreGroup
2467 */
2468int restore_everything(struct s_node *filelist)
2469{
2470 int resA;
2471 int resB;
2472
2473 /** mallco ***/
2474 char *cwd;
2475 char *newpath;
2476 char *tmp = NULL;
2477 assert(bkpinfo != NULL);
2478
2479 malloc_string(cwd);
2480 malloc_string(newpath);
2481 log_msg(2, "restore_everything() --- starting");
2482 g_current_media_number = 1;
2483 if (getcwd(cwd, MAX_STR_LEN - 1)) {
2484 // FIXME
2485 }
2486 mr_asprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
2487 run_program_and_log_output(tmp, FALSE);
2488 mr_free(tmp);
2489
2490 log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
2491 if (chdir(bkpinfo->restore_path)) {
2492 //FIXME
2493 }
2494 if (getcwd(newpath, MAX_STR_LEN - 1)) {
2495 // FIXME
2496 }
2497 log_msg(1, "path is now %s", newpath);
2498 log_msg(1, "restoring everything");
2499 tmp = find_home_of_exe("petris");
2500 if (!tmp && !g_text_mode) {
2501 newtDrawRootText(0, g_noof_rows - 2,
2502 "Press ALT-<left cursor> twice to play Petris :-) ");
2503 newtRefresh();
2504 }
2505 mr_free(tmp);
2506
2507 mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
2508 mount_media();
2509 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2510 mvaddstr_and_log_it(g_currentY++, 0,
2511 "Restoring OS and data from streaming media");
2512 if (bkpinfo->backup_media_type == cdstream) {
2513 openin_cdstream();
2514 } else {
2515 openin_tape();
2516 }
2517 resA = restore_all_tarballs_from_stream(filelist);
2518 resB = restore_all_biggiefiles_from_stream(filelist);
2519 if (bkpinfo->backup_media_type == cdstream) {
2520 closein_cdstream();
2521 } else {
2522 closein_tape();
2523 }
2524 } else {
2525 mvaddstr_and_log_it(g_currentY++, 0,
2526 "Restoring OS and data from CD/USB ");
2527 resA = restore_all_tarballs_from_CD(filelist);
2528 resB = restore_all_biggiefiles_from_CD(filelist);
2529 }
2530 if (chdir(cwd)) {
2531 //FIXME
2532 }
2533 if (resA + resB) {
2534 log_to_screen("Errors occurred while data was being restored.");
2535 }
2536 if (length_of_file("/etc/raidtab") > 0) {
2537 log_msg(2, "Copying local raidtab to restored filesystem");
2538 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
2539 "/etc/raidtab", FALSE);
2540 }
2541 kill_petris();
2542 log_msg(2, "restore_everything() --- leaving");
2543 paranoid_free(cwd);
2544 paranoid_free(newpath);
2545 return (resA + resB);
2546}
2547
2548/**************************************************************************
2549 *END_RESTORE_EVERYTHING *
2550 **************************************************************************/
2551
2552
2553extern void wait_until_software_raids_are_prepped(char *, int);
2554
2555
2556char which_restore_mode(void);
2557
2558
2559/**
2560 * Log a "don't panic" message to the logfile.
2561 */
2562void welcome_to_mondorestore()
2563{
2564 log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
2565 log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please ");
2566 log_msg(0, "don't break out in a cold sweat just because you see a few ");
2567 log_msg(0, "error messages in the log. Read them; analyze them; see if ");
2568 log_msg(0, "they are significant; above all, verify your backups! Please");
2569 log_msg(0, "attach a compressed copy of this log to any e-mail you send ");
2570 log_msg(0, "to the Mondo mailing list when you are seeking technical ");
2571 log_msg(0, "support. Without it, we can't help you. - DevTeam");
2572 log_msg(0, "------------------------------------------------------------");
2573 log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages,");
2574 log_msg(0, "some users are inclined to stop reading this log. If Mondo ");
2575 log_msg(0, "stopped for some reason, chances are it's detailed here. ");
2576 log_msg(0, "More than likely there's a message at the very end of this ");
2577 log_msg(0, "log that will tell you what is wrong. Please read it! ");
2578 log_msg(0, "------------------------------------------------------------");
2579}
2580
2581
2582
2583/**
2584 * Restore the user's data.
2585 * What did you think it did, anyway? :-)
2586 */
2587int main(int argc, char *argv[])
2588{
2589 FILE *fin;
2590 FILE *fout;
2591 int retval = 0;
2592 int res;
2593 char *tmp = NULL;
2594
2595 struct mountlist_itself *mountlist;
2596 struct raidlist_itself *raidlist;
2597 struct s_node *filelist;
2598 char *tmp1 = NULL;
2599 char *tmp2 = NULL;
2600 bool run_postnuke = FALSE;
2601
2602 if (getuid() != 0) {
2603 fprintf(stderr, "Please run as root.\r\n");
2604 exit(127);
2605 }
2606 bkpinfo = (struct s_bkpinfo *)mr_malloc(sizeof(struct s_bkpinfo));
2607 init_bkpinfo();
2608
2609 g_loglevel = DEFAULT_MR_LOGLEVEL;
2610
2611 /* Configure global variables */
2612 malloc_libmondo_global_strings();
2613 tmp1 = call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE);
2614 if (strstr(tmp1, "textonly")) {
2615 g_text_mode = TRUE;
2616 log_msg(1, "TEXTONLY MODE");
2617 } else {
2618 g_text_mode = FALSE;
2619 } // newt :-)
2620 mr_free(tmp1);
2621
2622 /* Init GUI */
2623 setup_newt_stuff(); /* call newtInit and setup screen log */
2624
2625 tmp1 = call_program_and_get_last_line_of_output("which mondorestore",TRUE);
2626 strcpy(g_mondo_home, tmp1);
2627 mr_free(tmp1);
2628
2629 g_current_media_number = 1; // precaution
2630
2631 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
2632
2633 setup_MR_global_filenames(); // malloc() and set globals, using bkpinfo->tmpdir etc.
2634 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
2635 bkpinfo->restore_data = TRUE; // Well, yeah :-)
2636 if (am_I_in_disaster_recovery_mode()) {
2637 run_program_and_log_output("mount / -o remount,rw", 2);
2638 } // for b0rken distros
2639 g_main_pid = getpid();
2640 srandom((int) (time(NULL)));
2641 set_signals(TRUE);
2642 g_kernel_version = get_kernel_version();
2643
2644 log_msg(1, "FYI - mountlist = %s", MINDI_CACHE"/mountlist.txt");
2645 mkdir(MNT_CDROM, 0x770);
2646 make_hole_for_dir(MONDO_CACHE);
2647
2648 /* Backup original mountlist.txt */
2649 mr_asprintf(tmp, "cp -f "MINDI_CACHE"/mountlist.txt "MINDI_CACHE"/mountlist.txt.orig");
2650 run_program_and_log_output(tmp, FALSE);
2651 mr_free(tmp);
2652
2653 /* Init directories */
2654 make_hole_for_dir("/var/log");
2655 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */
2656 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
2657
2658 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
2659
2660 welcome_to_mondorestore();
2661 if (bkpinfo->disaster_recovery) {
2662 log_msg(1, "I am in disaster recovery mode");
2663 } else {
2664 log_msg(1, "I am in normal, live mode");
2665 }
2666
2667 log_it("what time is it");
2668
2669 mountlist = (struct mountlist_itself *)mr_malloc(sizeof(struct mountlist_itself));
2670 raidlist = (struct raidlist_itself *)mr_malloc(sizeof(struct raidlist_itself));
2671
2672 /* Process command-line parameters */
2673 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
2674#ifdef __FreeBSD__
2675 paranoid_system("mv -f /tmp/raidconf.txt /etc/raidtab");
2676 if (!does_file_exist("/etc/raidtab"))
2677 paranoid_system("vinum printconfig > /etc/raidtab");
2678#endif
2679 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2680 res = let_user_edit_the_mountlist(mountlist, raidlist);
2681#ifdef __FreeBSD__
2682 paranoid_system("mv -f /etc/raidtab /tmp/raidconf.txt");
2683#endif
2684 paranoid_MR_finish(res);
2685 }
2686
2687 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
2688 fout = fopen("/tmp/out.txt", "w");
2689 fput_string_one_char_at_a_time(stderr, argv[2]);
2690 finish(0);
2691 }
2692
2693 if (argc == 5 && strcmp(argv[1], "--common") == 0) {
2694 g_loglevel = 6;
2695 filelist = load_filelist(argv[2]);
2696 if (!filelist) {
2697 fatal_error("Failed to load filelist");
2698 }
2699 toggle_node_selection(filelist, FALSE);
2700 toggle_all_root_dirs_on(filelist);
2701 // BERLIOS: /usr/lib ???
2702 toggle_path_selection(filelist, "/usr/share", TRUE);
2703 save_filelist(filelist, "/tmp/out.txt");
2704 mr_asprintf(tmp1, "%s", argv[3]);
2705 mr_asprintf(tmp2, "%s", argv[4]);
2706
2707 res = save_filelist_entries_in_common(tmp1, filelist, tmp2, FALSE);
2708 mr_free(tmp1);
2709 mr_free(tmp2);
2710
2711 free_filelist(filelist);
2712 printf("res = %d", res);
2713 finish(0);
2714 }
2715
2716 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
2717 popup_changelist_from_file(argv[2]);
2718 paranoid_MR_finish(0);
2719 }
2720
2721 if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
2722 log_msg(1, "SCORE");
2723 g_loglevel = 10;
2724 if (strstr(argv[2], "save")) {
2725 log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
2726 fin = fopen(argv[3], "r");
2727 fout = fopen(argv[4], "w");
2728 copy_from_src_to_dest(fin, fout, 'w');
2729 fclose(fin);
2730 fin = fopen(argv[3], "r");
2731 copy_from_src_to_dest(fin, fout, 'w');
2732 fclose(fout);
2733 fclose(fin);
2734 } else if (strstr(argv[2], "restore")) {
2735 fout = fopen(argv[3], "w");
2736 fin = fopen(argv[4], "r");
2737 copy_from_src_to_dest(fout, fin, 'r');
2738 fclose(fin);
2739 fin = fopen(argv[4], "r");
2740 copy_from_src_to_dest(fout, fin, 'r');
2741 fclose(fout);
2742 fclose(fin);
2743 } else {
2744 fatal_error("Unknown additional param");
2745 }
2746 finish(0);
2747 }
2748
2749 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
2750 wait_until_software_raids_are_prepped(argv[2], 100);
2751 finish(0);
2752 }
2753
2754 if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
2755 finish(create_raidtab_from_mdstat(MDSTAT_FILE,argv[2]));
2756 }
2757
2758 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
2759 retval = run_grub(FALSE, "/dev/hda");
2760 if (retval) {
2761 log_to_screen("Failed to write Master Boot Record");
2762 }
2763 paranoid_MR_finish(0);
2764 }
2765 if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
2766 g_current_media_number = atoi(argv[2]);
2767 pause_and_ask_for_cdr(5, NULL);
2768 paranoid_MR_finish(0);
2769 }
2770 if ((argc == 2 && strcmp(argv[1], "--partition-only") == 0) && (bkpinfo->disaster_recovery)) {
2771 log_msg(0, "Partitioning only.");
2772 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2773 load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt");
2774 res = partition_everything(mountlist);
2775 finish(res);
2776 }
2777
2778 if ((argc == 2 && strcmp(argv[1], "--format-only") == 0) && (bkpinfo->disaster_recovery)) {
2779 log_msg(0, "Formatting only.");
2780 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2781 res = format_everything(mountlist, FALSE, raidlist);
2782 finish(res);
2783 }
2784
2785 if ((argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) && (bkpinfo->disaster_recovery)) {
2786 log_msg(0, "Stopping LVM and RAID");
2787 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2788 load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt");
2789 res = do_my_funky_lvm_stuff(TRUE, FALSE);
2790 res += stop_all_raid_devices(mountlist);
2791 finish(res);
2792 }
2793
2794 // Handle params here first
2795 handle_incoming_parameters(argc,argv);
2796
2797 if (!bkpinfo->disaster_recovery) { // live!
2798 log_msg(1, "I am in normal, live mode.");
2799 mount_boot_if_necessary(); /* for Gentoo users */
2800 log_msg(2, "Still here.");
2801 /* Adding an initialisation in order to avoid to hndle NULL pointer later */
2802 mr_free(bkpinfo->restore_path);
2803 mr_asprintf(bkpinfo->restore_path, "%s", "/tmp");
2804
2805 log_msg(2, "Calling restore_to_live_filesystem()");
2806 retval = restore_to_live_filesystem();
2807
2808 log_msg(2, "Still here. Yay.");
2809 if ((strlen(bkpinfo->tmpdir) > 0) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
2810 mr_asprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
2811 run_program_and_log_output(tmp, FALSE);
2812 mr_free(tmp);
2813 }
2814 unmount_boot_if_necessary(); /* for Gentoo users */
2815 paranoid_MR_finish(retval);
2816 } else {
2817 /* Disaster recovery mode (must be) */
2818 log_msg(1, "I must be in disaster recovery mode.");
2819
2820 log_it("About to call load_mountlist and load_raidtab");
2821 mr_free(bkpinfo->restore_path);
2822 mr_asprintf(bkpinfo->restore_path, "%s", MNT_RESTORING);
2823 read_cfg_file_into_bkpinfo(MINDI_CACHE"/mondorestore.cfg");
2824 retval = load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt");
2825 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2826 log_it("Returned from calling load_mountlist and load_raidtab successfully");
2827
2828 // BCO:To be reviewed
2829 if ((bkpinfo->restore_mode == compare) || (bkpinfo->restore_mode == nuke)) {
2830 if ((bkpinfo->backup_media_type == netfs) && bkpinfo->netfs_mount && !is_this_device_mounted(bkpinfo->netfs_mount)) {
2831 log_msg(1, "Mounting remote %s dir", bkpinfo->netfs_proto);
2832 mr_free(bkpinfo->isodir);
2833 mr_asprintf(bkpinfo->isodir, "/tmp/isodir");
2834 run_program_and_log_output("mkdir -p /tmp/isodir", 5);
2835 if (strstr(bkpinfo->netfs_proto, "sshfs")) {
2836 if (bkpinfo->netfs_user) {
2837 mr_asprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
2838 } else {
2839 mr_asprintf(tmp, "sshfs -o ro %s /tmp/isodir", bkpinfo->netfs_mount);
2840 }
2841 } else {
2842 if (strstr(bkpinfo->netfs_proto, "smbfs")) {
2843 if (bkpinfo->netfs_user) {
2844 mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o user=%s,nolock,ro ", bkpinfo->netfs_mount,bkpinfo->netfs_user);
2845 } else {
2846 mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o nolock,ro ", bkpinfo->netfs_mount);
2847 }
2848 } else {
2849 if (bkpinfo->netfs_user) {
2850 mr_asprintf(tmp, "mount %s@%s -o nolock,ro /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
2851 } else {
2852 mr_asprintf(tmp, "mount %s -o nolock,ro /tmp/isodir", bkpinfo->netfs_mount);
2853 }
2854 }
2855 }
2856 run_program_and_log_output(tmp, 1);
2857 mr_free(tmp);
2858 }
2859 }
2860
2861 if (retval) {
2862 log_to_screen("Warning - load_raidtab_into_raidlist returned an error");
2863 }
2864
2865 log_msg(1, "Send in the clowns.");
2866
2867
2868 if (bkpinfo->restore_mode == nuke) {
2869 log_it("nuking");
2870 retval += nuke_mode(mountlist, raidlist);
2871 } else if (bkpinfo->restore_mode == interactive) {
2872 log_it("catchall");
2873 retval += catchall_mode(mountlist, raidlist);
2874 } else if (bkpinfo->restore_mode == compare) {
2875 log_it("compare");
2876 retval += compare_mode(mountlist, raidlist);
2877 } else if (bkpinfo->restore_mode == isoonly) {
2878 log_it("iso");
2879 retval = iso_mode(mountlist, raidlist, FALSE);
2880 } else if (bkpinfo->restore_mode == mbr) {
2881 log_it("mbr");
2882 retval = mount_all_devices(mountlist, TRUE);
2883 if (!retval) {
2884 retval += run_boot_loader(FALSE);
2885 retval += unmount_all_devices(mountlist);
2886 }
2887 if (retval) {
2888 log_to_screen("Failed to write Master Boot Record");
2889 }
2890 } else if (bkpinfo->restore_mode == isonuke) {
2891 log_it("isonuke");
2892 retval = iso_mode(mountlist, raidlist, TRUE);
2893 } else {
2894 log_it("catchall (no mode specified in command-line call");
2895 retval += catchall_mode(mountlist, raidlist);
2896 }
2897 }
2898
2899 /* clean up at the end */
2900 if (retval) {
2901 if (does_file_exist(MONDO_CACHE"/changed.files")) {
2902 log_to_screen
2903 ("See "MONDO_CACHE"/changed.files for list of files that have changed.");
2904 }
2905 mvaddstr_and_log_it(g_currentY++,
2906 0,
2907 "Run complete. Errors were reported. Please review the logfile.");
2908 } else {
2909 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2910 mvaddstr_and_log_it(g_currentY++,
2911 0,
2912 "Run complete. Please remove media and reboot.");
2913 } else {
2914 sync();
2915 if (is_this_device_mounted(MNT_CDROM)) {
2916 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
2917 }
2918
2919 if (!bkpinfo->please_dont_eject) {
2920 (void)eject_device("/dev/cdrom");
2921 }
2922 mvaddstr_and_log_it(g_currentY++,
2923 0,
2924 "Run complete. Please remove media and reboot.");
2925 }
2926 }
2927
2928// g_I_have_just_nuked is set true by nuke_mode() just before it returns
2929 if (!system("which post-nuke > /dev/null 2> /dev/null")) {
2930 log_msg(1, "post-nuke found; find out whether we should run it...");
2931 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
2932 run_postnuke = TRUE;
2933 log_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
2934 } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
2935 run_postnuke = TRUE;
2936 log_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
2937 } else {
2938 run_postnuke = FALSE;
2939 log_msg(1, "No, will not run post-nuke.");
2940 }
2941 } else {
2942 log_msg(1, "No post-nuke found.");
2943 }
2944 if (run_postnuke) {
2945 log_to_screen("Running post-nuke...");
2946 if (mount_all_devices(mountlist, TRUE)) {
2947 log_to_screen
2948 ("Unable to re-mount partitions for post-nuke stuff");
2949 } else {
2950 log_msg(1, "Re-mounted partitions for post-nuke stuff");
2951 mr_asprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval);
2952 log_msg(2, "Calling '%s'", tmp);
2953 if ((res = run_program_and_log_output(tmp, 0))) {
2954 log_OS_error(tmp);
2955 }
2956 mr_free(tmp);
2957 log_msg(1, "post-nuke returned w/ res=%d", res);
2958 }
2959 unmount_all_devices(mountlist);
2960 log_to_screen("I've finished post-nuking.");
2961 }
2962
2963/*
2964 log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
2965 log_to_screen("Otherwise, please wait until the RAID disks are done.");
2966 wait_until_software_raids_are_prepped("/proc/mdstat", 100);
2967 log_to_screen("Thank you.");
2968*/
2969 unlink("/tmp/mondo-run-prog.tmp");
2970 set_signals(FALSE);
2971 log_to_screen("Restore log (%s) copied to /var/log on your hard disk", MONDO_LOGFILE);
2972 log_to_screen("Mondo-restore is exiting (retval=%d) ", retval);
2973
2974 mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
2975 run_program_and_log_output(tmp, 5);
2976 mr_free(tmp);
2977
2978 paranoid_free(mountlist);
2979 paranoid_free(raidlist);
2980 if (am_I_in_disaster_recovery_mode()) {
2981 run_program_and_log_output("mount / -o remount,rw", 2);
2982 } // for b0rken distros
2983 if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) {
2984 mr_asprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
2985 paranoid_system(tmp);
2986 mr_free(tmp);
2987 }
2988 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
2989 free_libmondo_global_strings(); // it's fine to have this here :) really :)
2990
2991 unlink("/tmp/filelist.full");
2992
2993 exit(retval);
2994}
2995
2996/**************************************************************************
2997 *END_MAIN *
2998 **************************************************************************/
2999
3000
3001
3002
3003
3004/**************************************************************************
3005 *END_MONDO-RESTORE.C *
3006 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.