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

Last change on this file since 3193 was 3193, checked in by Bruno Cornec, 11 years ago
  • Finish with backports from 3.1 for now. Still some work to do, but we will now make that version compile and work again and serve as a base

so the gettext patch can be added

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