source: MondoRescue/branches/2.2.10/mondo/src/mondorestore/mondorestore.c @ 2331

Last change on this file since 2331 was 2331, checked in by Bruno Cornec, 12 years ago

r3342@localhost: bruno | 2009-08-14 00:46:51 +0200

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