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

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