source: MondoRescue/branches/stable/mondo/src/mondorestore/mondo-restore.c @ 947

Last change on this file since 947 was 947, checked in by Bruno Cornec, 14 years ago

Grrr typo again
--Cette ligne, et les suivantes ci-dessous, serontGrr typo again ignorées--

M mondo/src/mondorestore/mondo-restore.c

  • Property svn:keywords set to Id
File size: 114.0 KB
Line 
1/***************************************************************************
2       mondo-restore.c  -  restores mondoarchive data
3                             -------------------
4    begin                : Fri May 19 2000
5    copyright            : (C) 2000 by Hugo Rabson
6    email                : Hugo Rabson <hugorabson@msn.com>
7    cvsid                : $Id: mondo-restore.c 947 2006-11-18 01:06:57Z bruno $
8***************************************************************************/
9
10/***************************************************************************
11 *                                                                         *
12 *   This program is free software; you can redistribute it and/or modify  *
13 *   it under the terms of the GNU General Public License as published by  *
14 *   the Free Software Foundation; either version 2 of the License, or     *
15 *   (at your option) any later version.                                   *
16 *                                                                         *
17 ***************************************************************************/
18
19/***************************************************************************
20 *                         Change Log                                      *
21 ***************************************************************************
22.
23
24
2507/26
26- workaround - if not /dev then don't call partimagehack
27
2807/21
29- if switch to Interactive Mode during nuke then don't nuke twice :) just once
30
3107/18
32- better support of users who boot from LVM CD and nuke-restore non-LVM backups
33
3407/10
35- when using 'star', exclude all 'not removed.' messages from log (misleading, they are)
36- try w/ ACLs, then w/o ACLs if star fails w/ ACLs
37- added ACL, xattr support for afio
38
3906/26
40- remove make_relevant_partition_bootable(); roll into mondo-prep.c
41- changed various newtDrawRootText() calls to use g_noof_rows instead of
42  integers
43
4406/19
45- don't try to access biggiestruct before it is populated w/ data relating
46  to biggiefile; instead, use control char to find out if biggiefile is
47  to be restored w/ partimagehack or not
48- added AUX_VER
49
5006/15
51- read_cfg_file_into_bkpinfo() --- use user-supplied 'isodir' instead of
52  archive's 'isodir' if different
53  Conor Daly <conor.daly@met.ie>
54
5506/17
56- restore with partimagehack if NTFS device; dd, if non-NTFS device
57
5806/14
59- unmount all; remount, run grub-mr; unmount again
60
6104/09
62- fixed subset restoration bug introduced when I added 'star' support
63
6404/04
65- cleaned up restore_a_tarball_from_stream()
66
6704/03
68- added star support
69- pause for 3s between partitioning and formatting (if in Nuke Mode)
70
7103/28
72- check that g_mountlist_fname was correcfly set; abort if it wasn't
73
7403/25
75- removed dev_null code
76
7703/22/04
78- added mode_of_file()
79- added code to check for unauthorised modification of /dev/null
80  by afio (for instance)
81
8212/27/03
83- check /tmp/cmdline instead of /proc/cmdline if on FreeBSD
84
8511/15
86- added g_fprep
87- "Switch to interactive mode?" msg is now more informative
88
8911/05
90- after 'Are you sure?' when user specifies / as restore path, set
91  restore_path[] to "" so that files are restored to [blank]/file/name :)
92
9310/29
94- moved "No restoring or comparing will take place today" block
95  up to before iso_fiddly_bits (if iso) is called - fix bug
96  if you're in ISO Mode and you say "exit to shell"
97
9810/22
99- swapped calls to chmod() and chown() after restoration
100  of big files (Jens)
101
10210/21
103- changed "/mnt/cdrom" to MNT_CDROM
104
10510/19
106- restore biggiefiles selectively from CD properly
107- use find_my_editor() to find pico/vi/whatever
108- better use of call_program_and_get_last_line_of_output() to
109  scan /proc/cmdline
110
11110/18
112- don't report 'missing compressor' if no compressor used at all
113
11410/14
115- log afio's error messages to /var/log/mondo-archive.log
116  when restoring :)
117- call vi if pico is not available
118
11910/09
120- better logging if fatal error (cannot openout bigfile)
121- better GUI feedback when restoring big files
122- restore_everything() now uses s_node* instead of char*
123- ditto restore_all_*_from_*()
124
12510/02
126- succinct msg instead of pop-ups, if used -H
127
12809/27
129- tweaked restore-time gui
130
13109/26
132- proper reporting of DVD/CDR/etc. type in displayed dialogs
133
13409/23
135- malloc/free global strings in new subroutines - malloc_libmondo_global_strings()
136  and free_libmondo_global_strings() - which are in libmondo-tools.c
137
13809/21
139- trying to fix "mondorestore <no params>" segfault
140
14109/18
142- better remounting of /
143- cleaned up run_grub()
144- sensible command-line handling in Live Mode
145
14609/17
147- cleaned up GRUB installer script a bit
148
14909/15
150- remount / as r/w if in disaster recovery mode;
151  helps for b0rken distros
152
15309/13
154- major NTFS hackage
155
15609/12
157- changed some in-sub var decl'ns to malloc()'s
158
15909/05
160- don't let me run unless I'm root
161- finished NTFS/partimagehack support (CD only); working on tape now
162
16309/01
164- fixed cosmetic bug in biggiefile restore window
165
16606/01 - 08/31
167- added code to main() to make sure NFS
168  (backup) share is mounted in Nuke and Compare Modes
169- added code to run_grub() to mount /boot before running grub-install
170- fixed some stray assert()'s in restore_a_biggiefile_from_stream()
171- fixed bugs in extract_config_file_from_ramdisk()
172  and get_cfg_file_from_archive() which
173  stopped fape+floppy users from being able to
174  boot from floppy and leave floppy in drive :)
175- added hooks to partimage for doing imagedevs
176- fixed calls to popup_and_get_string()
177
17805/01 - 05/31
179- fixed biggiefile atime/utime dates restoration bug, I think
180- added misc clean-up (Steve Hindle)
181- fixed support for subdir-within-NFS-mount
182- if nuke mode fails & user reverts to interactive mode _and succeeds_,
183  don't claim nuke mode aborted :)
184- unmount_all_devices() uses mountlist->el[lino].mountpt
185  instead of mountlist->el[lino].device where possible
186- added Joshua Oreman's FreeBSD patches
187- copied missing paragraph from 1.6x's read_cfg_file_into_bkpinfo()
188  to 1.7x's; affected tape streamer users (badly!)
189- cleaned up some paranoid assert()'s
190- use which("post-nuke") instead of find_home_of_exe("post-nuke")
191- fixed "Don't eject while restoring" mode
192- get_cfg_file_from_archive() --- also recovers mountlist.txt now :)
193- don't eject if 'donteject' is in kernel's command line
194- added 'don't panic' msg to start of log
195
19604/01 - 04/30
197- added text mode (cat /proc/cmdline; if textonly then text mode is on)
198- delete /var/lock/subsys/ * when nuking
199- don't resize mountlist if "noresize" present in /proc/cmdline
200- changed from chmod -R 1777 tmp to chmod 1777 tmp
201- replace newtFinished() and newtInit() with
202  newtSuspend() and newtResume()
203- get_cfg_file_from_archive() returns 1 instead of aborting now
204- read_cfg_file_into_bkpinfo) --- if autorun CD but its config
205  file indicates a non-CD backup media then ask, just in case
206- sped up restore_a_tarball_from_CD() a bit
207- line 4469 --- if post-nuke not found then don't run it :)
208- replaced "/mnt/RESTORING" with MNT_RESTORING (#define'd)
209- moved compare_*() into mondorestore/mondo-rstr-compare.c
210- moved some RAID subroutines into common/libmondo-raid.c
211- fixed some iso live compare problems
212- replaced FILELIST_FULL with g_filelist_full and FILELIST_FULL_STUB;
213  g_filelist_full being the full path of the filelist.full text file and
214  FILELIST_FULL_STUB being "tmp/filelist.full" (relative path);
215- ditto BIGGIELIST_TXT, MONDO_CFG_FILE
216- added lots of assert()'s and log_OS_error()'s
217- in Nuke Mode, check mountlist's sanity before doing anything else;
218  if it fails sanity test, offer to revert to Interactive Mode (or abort)
219- copy log to /mnt/RESTORING/root at end
220- read_cfg_file_into_bkpinfo() --- read iso-dev and isodir if bkptype==iso
221- line 1701 --- delete ramdisk file after extracting config info
222- moved call to make_relevant_partitions_bootable() from
223  within run_boot_loader() to within interactive_mode() and
224  nuke_mode(), after unmounting disks
225- if editing fstab or *.conf, try to use pico if available
226- better calling of make-me-bootable
227- don't sort mountlist anywhere anymore except _locally_ in
228  mount_all_devices() and unmount_all_devices()
229- edit fstab, grub.conf _after_ stabgrub-me if it fails
230- run_boot_loader() --- backup all crucial files to /etc/ *.pristine first
231- added iso_fiddly_bits()
232- fixed ISO mode support
233- mount_cdrom() only searches for device if NOT in disaster recovery mode
234- changed lost of system()'s into run_program_and_log_output()'s
235- don't eject if bkpinfo->please_dont_eject_when_restoring
236- cleaned up post-nuke handling code
237- always eject CD at end, unless bkpinfo->please_dont_...
238- misc clean-up (Tom Mortell)
239- afio uses -c (1024L*1024L)/TAPE_BLOCK_SIZE now
240  instead of -c 1024
241
24201/01 - 03/31/2003
243- commented out sort_... line (BB)
244- clean-up (Stan Benoit)
245- added code for LVM and SW Raid (Brian Borgeson)
246- line 814 - added -p to 'mkdir -p tmp'
247- mount_cdrom() - calls find_cdrom_device() if
248  bkpinfo->media_device is blank (to fill it)
249
25011/01 - 12/31/2002
251- mount_cdrom() better at handling multiple CD drives
252- minor clean-up in restore_a_tarball_from_CD()
253- if --live-from-cd then assume restoring live from CD
254- tweaked it to run better w/ ArkLinux
255- create /mnt/RESTORING/mnt/.boot.d for Gentoo users
256  after restoring
257- cleaned up iso_mode(); no longer asks for NFS info 3 times
258- mount_cdrom() was trying to mount /mnt/isodir/%s/%d.iso;
259  is now just %s/%d.iso
260- mount/unmount /boot if necessary (Gentoo)
261- added RAW MBR support; added run_raw_mbr() for the purpose
262- unmount & remount supermounts at start/end of live restore
263- copy /tmp/mountlist.txt to /tmp/mountlist.txt.orig at start
264- cleaned up string-handling in get_cfg_info_from_archives()
265- fixed run_grub() to call new stabgrub-me script
266- popup list of changed files after Compare Mode
267- permit mondorestore --edit-mountlist even if live mode
268- create a repaired copy of grub-install which is RAID-friendly;
269  use it when initializing boot sector with run_grub()
270- use grub-MR instead of grub-install
271- fixed read_cfg_file_into_bkpinfo() to ignore cfg file's backup_media_type
272  if user has already specified a backup media type interactively
273
27410/01 - 10/31
275- run_grub() will let you specify the boot device as well as edit the system
276  files, if grub-install fails
277- fixed bug in fwrite() call in restore_biggiefile_from_CD()
278- fixed bug affecting restoration of bigfiles from CD's w/0 compression
279- run_grub() will run 'grub-install {boot device}' instead of
280  'grub-install (hd0)'
281
28209/01 - 09/30
283- use /tmp/tmpfs/mondo.tmp instead of /tmp/mondo.tmp
284- initialize MOUNTLIST_FNAME at start of main()
285- differential-related cleanup
286- better handling of CD-ROM drives which aren't /dev/cdrom :)
287- run_program_and_log_output() now takes boolean operator to specify
288  whether it will log its activities in the event of _success_
289- always load config file from archive before operating on it
290- moved some subroutines around; now closer to alphabetical order
291- changed mount.mindi to mount.bootisk
292- mount disks readonly if in Compare Mode
293- set /dev/null's permissions to 777, just in case it somehow gets mangled
294  ...which apparently happen with some devfs-based Linux distributions
295- remove /var/run/ *.pid after restoring
296- move spurious lockfiles from /home/ * to /home/ * /.disabled
297- if Interactive Mode then ask user which media, etc. (i.e. catchall mode
298  is now same as Interactive Mode)
299
30008/01 - 08/30
301- use data structure to store the fname, checksum, mods & perms of each bigfile
302  ... biggiestruct :)
303- if a filelist is tiny (2 bytes or less) then ignore it
304- insist_on_this_cd_number() --- now takes 2 params, not 1
305- re-enabled 'g_current_media_number = 1' in restore_everything()
306- added same to compare_mode()
307- replaced lots of global char[]'s with malloc()'s
308- if differential backup then don't permit formatting or fdisking,
309  whether Interactive or Nuke mode
310- added call to register_pid() at start of main()
311- if Nuke Mode & it succeeds then ask user if they have contributed yet
312- changed tape-size to media-size (config file)
313- changed using_* to backup_media_type
314- changed *_from_tape to *_from_stream
315
31607/01 - 07/31
317- added find_and_mount_actual_cdrom()
318- temp dir is always random
319- skip tarballs if they don't contain files we're looking for
320  (used to read the whole thing & _then_ skip)
321- use media_size[1] instead of media_size[0]
322- fixed serious bug in line 1546 - should have been !=, not ==; stopped
323  mondorestore from correctly restoring big files
324- bigfile piping enhancements (Philippe de Muyter)
325- unmount CD-ROM after restoring from live filesystem
326- TAPE_BLOCK_SIZE treated as %ld, not %d
327
32806/01 - 06/30
329- added signal-trapping
330- disabled 'nr-failed-disks' flag
331- fixed problem w/selective restore
332- don't change /tmp's permissions unless it doesn't exist & must be created
333- fixed bug in --mbr
334- is_file_in_list() enhanced to exclude /mnt/RESTORING or whatever
335- added support for uncompressed archives
336- --monitas-live now accepts path-to-restore_to_, not just path to restore
337- added some debugging/tracking code to the NFS section
338- various monitas-related enhancements
339- added --isonuke and --mbr switches
340- better logging in run_grub()
341- improved --monitas-live
342- mkdir -p /mnt/RESTORING/var/run/console just in case user excludes it
343- afio now uses 16MB buffer instead of 8MB
344- always use bkpinfo->media_size[0], now that -s has been expanded
345- popup and ask where to restore data, if restoring selectively
346
34705/01 - 05/31
348- add '--monitas' flag
349- don't run chmod -R 1777 /mnt/RESTORING/tmp before unmounting unless
350  restoring at the time...
351
35204/01 - 04/30
353- delete old /tmp/filelist.full,biggielist.txt if found when restoring to
354  live filesystem
355- replace MONDO_VERSION #define with VERSION from ../config.h
356- write fname of bigfile to screen when having trouble reading/comparing it
357- if restoring to live filesystem then wipe /tmp/tmpfs/ * afterwards
358- removed spurious finish(0) from main()
359
36003/01 - 03/31/2002
361- if /tmp/m*ndo-restore.cfg not found then assume live restore; restore
362  to / instead of /mnt/RESTORING
363- clean up is_file_in_list() to deal with the /mnt/RESTORING/ prefix
364- exclude leading '/' from filelist.restore-these
365- if /tmp/fstab.new exists then use _it_ instead of /tmp/fstab to label
366  ext2 or ext3 partitions
367- improved logging
368
369[...]
370
37107/10/2001 --- first incarnation
372*/
373
374
375/**
376 * @file
377 * The main file for mondorestore.
378 */
379
380/**************************************************************************
381 * #include statements                                                    *
382 **************************************************************************/
383#include <pthread.h>
384#include "../common/my-stuff.h"
385#include "../common/mondostructures.h"
386#include "../common/libmondo.h"
387#include "mr-externs.h"
388#include "mondo-restore.h"
389#include "mondo-rstr-compare-EXT.h"
390#include "mondo-rstr-tools-EXT.h"
391
392extern void twenty_seconds_til_yikes(void);
393
394
395/* For use in other programs (ex. XMondo) */
396#ifdef MONDORESTORE_MODULE
397#define main __mondorestore_main
398#define g_ISO_restore_mode __mondorestore_g_ISO_restore_mode
399#endif
400
401//static char cvsid[] = "$Id: mondo-restore.c 947 2006-11-18 01:06:57Z bruno $";
402
403/**************************************************************************
404 * Globals                                                                *
405 **************************************************************************/
406extern char *g_tmpfs_mountpt;   // declared in libmondo-tools.c
407extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; // used by finish() to free
408                                                // up global bkpinfo struct
409extern bool g_text_mode;
410extern FILE *g_fprep;
411extern double g_kernel_version;
412extern int g_partition_table_locked_up;
413extern int g_noof_rows;
414
415extern int partition_everything(struct mountlist_itself *mountlist);
416
417
418/**
419 * @name Restore-Time Globals
420 * @ingroup globalGroup
421 * @{
422 */
423/**
424 * If TRUE, then SIGPIPE was just caught.
425 * Set by the signal handler; cleared after it's handled.
426 */
427bool g_sigpipe_caught = FALSE;
428
429/**
430 * If TRUE, then we're restoring from ISOs or an NFS server.
431 * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.)
432 */
433bool g_ISO_restore_mode = FALSE;    /* are we in Iso Mode? */
434
435/**
436 * If TRUE, then we have had a successful "nuke" restore.
437 */
438bool g_I_have_just_nuked = FALSE;
439
440/**
441 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
442 */
443char *g_isodir_device;
444
445/**
446 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
447 */
448char *g_isodir_format;
449
450/**
451 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
452 */
453char *g_biggielist_txt;
454
455/**
456 * The location of 'filelist.full', containing all files (<em>including biggiefiles</em>) on
457 * the current archive set.
458 */
459char *g_filelist_full;
460
461/**
462 * The location of a file containing a list of the devices that were archived
463 * as images, not as individual files.
464 */
465char *g_filelist_imagedevs;
466
467/**
468 * The location of a file containing a list of imagedevs to actually restore.
469 * @see g_filelist_imagedevs
470 */
471char *g_imagedevs_restthese;
472
473/**
474 * The location of 'mondo-restore.cfg', containing the metadata
475 * information for this backup.
476 */
477char *g_mondo_cfg_file;
478
479/**
480 * The location of 'mountlist.txt', containing the information on the
481 * user's partitions and hard drives.
482 */
483char *g_mountlist_fname;
484
485/**
486 * Mondo's home directory during backup. Unused in mondo-restore; included
487 * to avoid link errors.
488 */
489char *g_mondo_home;
490
491/* Busybox ps has no option and PID in first pos */
492char *ps_options = "";
493char *ps_proc_id = "$1";
494
495char *g_getfacl = NULL;
496char *g_getfattr = NULL;
497
498/* @} - end of "Restore-Time Globals" in globalGroup */
499
500
501
502extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
503                                 char direction);
504
505
506
507/**************************************************************************
508 * COMPAQ PROLIANT Stuff:  needs some special help                        *
509**************************************************************************/
510
511/**
512 * The message to display if we detect that the user is using a Compaq Proliant.
513 */
514#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 CD/floppy in Interactive Mode."
515
516
517
518
519/**
520 * Allow the user to modify the mountlist before we partition & format their drives.
521 * @param bkpinfo The backup information structure. @c disaster_recovery is the only field used.
522 * @param mountlist The mountlist to let the user modify.
523 * @param raidlist The raidlist that goes with @p mountlist.
524 * @return 0 for success, nonzero for failure.
525 * @ingroup restoreGuiGroup
526 */
527int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo,
528                                struct mountlist_itself *mountlist,
529                                struct raidlist_itself *raidlist)
530{
531    int retval = 0, res = 0;
532
533    log_msg(2, "let_user_edit_the_mountlist() --- starting");
534
535    assert(bkpinfo != NULL);
536    assert(mountlist != NULL);
537    assert(raidlist != NULL);
538    if (!bkpinfo->disaster_recovery) {
539        strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
540        log_msg(2, "I guess you're testing edit_mountlist()");
541    }
542    if (!does_file_exist(g_mountlist_fname)) {
543        log_to_screen(g_mountlist_fname);
544        log_to_screen("does not exist");
545        return (1);
546    }
547
548    retval = load_mountlist(mountlist, g_mountlist_fname);
549    load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
550    if (retval) {
551        log_to_screen
552            ("Warning - load_raidtab_into_raidlist returned an error");
553    }
554    res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
555    if (res) {
556        return (1);
557    }
558
559    save_mountlist_to_disk(mountlist, g_mountlist_fname);
560    save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
561
562    log_to_screen("I have finished editing the mountlist for you.");
563
564    return (retval);
565}
566
567
568
569
570
571/**
572 * Determine whether @p mountlist contains a Compaq diagnostic partition.
573 * @param mountlist The mountlist to examine.
574 * @return TRUE if there's a Compaq diagnostic partition; FALSE if not.
575 * @ingroup restoreUtilityGroup
576 */
577bool
578partition_table_contains_Compaq_diagnostic_partition(struct
579                                                     mountlist_itself *
580                                                     mountlist)
581{
582    int i;
583
584    assert(mountlist != NULL);
585
586    for (i = 0; i < mountlist->entries; i++) {
587        if (strstr(mountlist->el[i].format, "ompaq")) {
588            log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
589                    i, mountlist->el[i].device, mountlist->el[i].format);
590
591            return (TRUE);
592        }
593    }
594    return (FALSE);
595}
596
597/**************************************************************************
598 *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION                *
599 **************************************************************************/
600
601
602/**
603 * Allow the user to abort the backup if we find that there is a Compaq diagnostic partition.
604 * @note This function does not actually check for the presence of a Compaq partition.
605 * @ingroup restoreUtilityGroup
606 */
607void offer_to_abort_because_Compaq_Proliants_suck(void)
608{
609    popup_and_OK(COMPAQ_PROLIANTS_SUCK);
610    if (ask_me_yes_or_no
611        ("Would you like to reboot and use your Compaq CD to prep your hard drive?"))
612    {
613        fatal_error
614            ("Aborting. Please reboot and prep your hard drive with your Compaq CD.");
615    }
616}
617
618/**************************************************************************
619 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK                        *
620 **************************************************************************/
621
622
623
624/**
625 * Call interactive_mode(), nuke_mode(), or compare_mode() depending on the user's choice.
626 * @param bkpinfo The backup information structure. Most fields are used.
627 * @param mountlist The mountlist containing information about the user's partitions.
628 * @param raidlist The raidlist to go with @p mountlist.
629 * @return The return code from the mode function called.
630 * @ingroup restoreGroup
631 */
632int
633catchall_mode(struct s_bkpinfo *bkpinfo,
634              struct mountlist_itself *mountlist,
635              struct raidlist_itself *raidlist)
636{
637    char c, *tmp;
638    int retval = 0;
639
640    iamhere("inside catchall");
641    assert(bkpinfo != NULL);
642    assert(mountlist != NULL);
643    assert(raidlist != NULL);
644    malloc_string(tmp);
645    iamhere("pre wrm");
646    c = which_restore_mode();
647    iamhere("post wrm");
648    if (c == 'I' || c == 'N' || c == 'C') {
649        interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
650    } else {
651        popup_and_OK("No restoring or comparing will take place today.");
652        if (is_this_device_mounted("/mnt/cdrom")) {
653            run_program_and_log_output("umount /mnt/cdrom", FALSE);
654        }
655        if (g_ISO_restore_mode) {
656            sprintf(tmp, "umount %s", bkpinfo->isodir);
657            run_program_and_log_output(tmp, FALSE);
658        }
659        paranoid_MR_finish(0);
660    }
661
662    iamhere("post int");
663
664    if (bkpinfo->backup_media_type == iso) {
665        if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) {
666            log_msg(2,
667                    "catchall_mode --- iso_fiddly_bits returned w/ error");
668            return (1);
669        } else {
670            log_msg(2, "catchall_mode --- iso_fiddly_bits ok");
671        }
672    }
673
674    if (c == 'I') {
675        log_msg(2, "IM selected");
676        retval += interactive_mode(bkpinfo, mountlist, raidlist);
677    } else if (c == 'N') {
678        log_msg(2, "NM selected");
679        retval += nuke_mode(bkpinfo, mountlist, raidlist);
680    } else if (c == 'C') {
681        log_msg(2, "CM selected");
682        retval += compare_mode(bkpinfo, mountlist, raidlist);
683    }
684    paranoid_free(tmp);
685    return (retval);
686}
687
688/**************************************************************************
689 *END_CATCHALL_MODE                                                      *
690 **************************************************************************/
691
692/**************************************************************************
693 *END_  EXTRACT_CONFIG_FILE_FROM_RAMDISK                                  *
694 **************************************************************************/
695
696
697/**
698 * Locate an executable in the directory structure rooted at @p restg.
699 * @param out_path Where to put the executable.
700 * @param fname The basename of the executable.
701 * @param restg The directory structure to look in.
702 * @note If it could not be found in @p restg then @p fname is put in @p out_path.
703 * @ingroup restoreUtilityGroup
704 */
705void
706find_pathname_of_executable_preferably_in_RESTORING(char *out_path,
707                                                    char *fname,
708                                                    char *restg)
709{
710    assert(out_path != NULL);
711    assert_string_is_neither_NULL_nor_zerolength(fname);
712
713    sprintf(out_path, "%s/sbin/%s", restg, fname);
714    if (does_file_exist(out_path)) {
715        sprintf(out_path, "%s/usr/sbin/%s", restg, fname);
716        if (does_file_exist(out_path)) {
717            sprintf(out_path, "%s/bin/%s", restg, fname);
718            if (does_file_exist(out_path)) {
719                sprintf(out_path, "%s/usr/bin/%s", restg, fname);
720                if (does_file_exist(out_path)) {
721                    strcpy(out_path, fname);
722                }
723            }
724        }
725    }
726}
727
728/**************************************************************************
729 *END_FIND_PATHNAME_OF_EXECUTABLE_PREFERABLY_IN_RESTORING                 *
730 **************************************************************************/
731
732
733
734
735/**
736 * @addtogroup restoreGroup
737 * @{
738 */
739/**
740 * Restore the user's data, in a disaster recovery situation, prompting the
741 * user about whether or not to do every step.
742 * The user can edit the mountlist, choose files to restore, etc.
743 * @param bkpinfo The backup information structure. Most fields are used.
744 * @param mountlist The mountlist containing information about the user's partitions.
745 * @param raidlist The raidlist to go with @p mountlist.
746 * @return 0 for success, or the number of errors encountered.
747 */
748int
749interactive_mode(struct s_bkpinfo *bkpinfo,
750                 struct mountlist_itself *mountlist,
751                 struct raidlist_itself *raidlist)
752{
753    int retval = 0;
754    int res;
755    int ptn_errs = 0;
756    int fmt_errs = 0;
757
758    bool done;
759    bool restore_all;
760
761  /** needs malloc **********/
762    char *tmp;
763    char *fstab_fname;
764    char *old_restpath;
765
766    struct s_node *filelist;
767
768    /* try to partition and format */
769
770    log_msg(2, "interactive_mode --- starting (great, assertions OK)");
771
772    malloc_string(tmp);
773    malloc_string(fstab_fname);
774    malloc_string(old_restpath);
775    assert(bkpinfo != NULL);
776    assert(mountlist != NULL);
777    assert(raidlist != NULL);
778
779    log_msg(2, "interactive_mode --- assertions OK");
780
781    if (g_text_mode) {
782        if (!ask_me_yes_or_no
783            ("Interactive Mode + textonly = experimental! Proceed anyway?"))
784        {
785            fatal_error("Wise move.");
786        }
787    }
788
789    iamhere("About to load config file");
790    get_cfg_file_from_archive_or_bust(bkpinfo);
791    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
792    iamhere("Done loading config file; resizing ML");
793#ifdef __FreeBSD__
794    if (strstr
795        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
796         "noresize"))
797#else
798    if (strstr
799        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
800         "noresize"))
801#endif
802    {
803        log_msg(1, "Not resizing mountlist.");
804    } else {
805        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
806    }
807    for (done = FALSE; !done;) {
808        iamhere("About to edit mountlist");
809        if (g_text_mode) {
810            save_mountlist_to_disk(mountlist, g_mountlist_fname);
811            sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
812            res = system(tmp);
813            load_mountlist(mountlist, g_mountlist_fname);
814        } else {
815            res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
816        }
817        iamhere("Finished editing mountlist");
818        if (res) {
819            paranoid_MR_finish(1);
820        }
821        log_msg(2, "Proceeding...");
822        save_mountlist_to_disk(mountlist, g_mountlist_fname);
823        save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
824        mvaddstr_and_log_it(1, 30, "Restoring Interactively");
825        if (bkpinfo->differential) {
826            log_to_screen("Because this is a differential backup, disk");
827            log_to_screen
828                (" partitioning and formatting will not take place.");
829            done = TRUE;
830        } else {
831            if (ask_me_yes_or_no
832                ("Do you want to erase and partition your hard drives?")) {
833                if (partition_table_contains_Compaq_diagnostic_partition
834                    (mountlist)) {
835                    offer_to_abort_because_Compaq_Proliants_suck();
836                    done = TRUE;
837                } else {
838                    twenty_seconds_til_yikes();
839                    g_fprep = fopen("/tmp/prep.sh", "w");
840                    ptn_errs = partition_everything(mountlist);
841                    if (ptn_errs) {
842                        log_to_screen
843                            ("Warning. Errors occurred during disk partitioning.");
844                    }
845
846                    fmt_errs = format_everything(mountlist, FALSE, raidlist);
847                    if (!fmt_errs) {
848                        log_to_screen
849                            ("Errors during disk partitioning were handled OK.");
850                        log_to_screen
851                            ("Partitions were formatted OK despite those errors.");
852                        ptn_errs = 0;
853                    }
854                    if (!ptn_errs && !fmt_errs) {
855                        done = TRUE;
856                    }
857                }
858                paranoid_fclose(g_fprep);
859            } else {
860                mvaddstr_and_log_it(g_currentY++, 0,
861                                    "User opted not to partition the devices");
862                if (ask_me_yes_or_no
863                    ("Do you want to format your hard drives?")) {
864                    fmt_errs = format_everything(mountlist, TRUE, raidlist);
865                    if (!fmt_errs) {
866                        done = TRUE;
867                    }
868                } else {
869                    ptn_errs = fmt_errs = 0;
870                    done = TRUE;
871                }
872            }
873            if (fmt_errs) {
874                mvaddstr_and_log_it(g_currentY++,
875                                    0,
876                                    "Errors occurred. Please repartition and format drives manually.");
877                done = FALSE;
878            }
879            if (ptn_errs & !fmt_errs) {
880                mvaddstr_and_log_it(g_currentY++,
881                                    0,
882                                    "Errors occurred during partitioning. Formatting, however, went OK.");
883                done = TRUE;
884            }
885            if (!done) {
886                if (!ask_me_yes_or_no("Re-edit the mountlist?")) {
887                    retval++;
888                    goto end_of_func;
889                }
890            }
891        }
892    }
893
894    /* mount */
895    if (mount_all_devices(mountlist, TRUE)) {
896        unmount_all_devices(mountlist);
897        retval++;
898        goto end_of_func;
899    }
900    /* restore */
901    if ((restore_all =
902         ask_me_yes_or_no("Do you want me to restore all of your data?")))
903    {
904        log_msg(1, "Restoring all data");
905        retval += restore_everything(bkpinfo, NULL);
906    } else
907        if ((restore_all =
908             ask_me_yes_or_no
909             ("Do you want me to restore _some_ of your data?"))) {
910        strcpy(old_restpath, bkpinfo->restore_path);
911        for (done = FALSE; !done;) {
912            unlink("/tmp/filelist.full");
913            filelist = process_filelist_and_biggielist(bkpinfo);
914            /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
915               the former is a list of regular files; the latter, biggiefiles and imagedevs.
916             */
917            if (filelist) {
918              gotos_suck:
919                strcpy(tmp, old_restpath);
920// (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
921                if (popup_and_get_string
922                    ("Restore path", "Restore files to where?", tmp,
923                     MAX_STR_LEN / 4)) {
924                    if (!strcmp(tmp, "/")) {
925                        if (!ask_me_yes_or_no("Are you sure?")) {
926                            goto gotos_suck;
927                        }
928                        tmp[0] = '\0';  // so we restore to [blank]/file/name :)
929                    }
930                    strcpy(bkpinfo->restore_path, tmp);
931                    log_msg(1, "Restoring subset");
932                    retval += restore_everything(bkpinfo, filelist);
933                    free_filelist(filelist);
934                } else {
935                    strcpy(bkpinfo->restore_path, old_restpath);
936                    free_filelist(filelist);
937                }
938                if (!ask_me_yes_or_no
939                    ("Restore another subset of your backup?")) {
940                    done = TRUE;
941                }
942            } else {
943                done = TRUE;
944            }
945        }
946        strcpy(old_restpath, bkpinfo->restore_path);
947    } else {
948        mvaddstr_and_log_it(g_currentY++,
949                            0,
950                            "User opted not to restore any data.                                  ");
951    }
952    if (retval) {
953        mvaddstr_and_log_it(g_currentY++,
954                            0,
955                            "Errors occurred during the restore phase.            ");
956    }
957
958    if (ask_me_yes_or_no("Initialize the boot loader?")) {
959        run_boot_loader(TRUE);
960    } else {
961        mvaddstr_and_log_it(g_currentY++,
962                            0,
963                            "User opted not to initialize the boot loader.");
964    }
965
966//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
967    protect_against_braindead_sysadmins();
968    //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
969    retval += unmount_all_devices(mountlist);
970    /*  if (restore_some || restore_all || */
971    if (ask_me_yes_or_no
972        ("Label your ext2 and ext3 partitions if necessary?")) {
973        mvaddstr_and_log_it(g_currentY, 0,
974                            "Using e2label to label your ext2,3 partitions");
975        if (does_file_exist("/tmp/fstab.new")) {
976            strcpy(fstab_fname, "/tmp/fstab.new");
977        } else {
978            strcpy(fstab_fname, "/tmp/fstab");
979        }
980        sprintf(tmp,
981                "label-partitions-as-necessary %s < %s >> %s 2>> %s",
982                g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
983                MONDO_LOGFILE);
984        res = system(tmp);
985        if (res) {
986            log_to_screen
987                ("label-partitions-as-necessary returned an error");
988            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
989        } else {
990            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
991        }
992        retval += res;
993    }
994
995    iamhere("About to leave interactive_mode()");
996    if (retval) {
997        mvaddstr_and_log_it(g_currentY++,
998                            0,
999                            "Warning - errors occurred during the restore phase.");
1000    }
1001  end_of_func:
1002    paranoid_free(tmp);
1003    paranoid_free(fstab_fname);
1004    paranoid_free(old_restpath);
1005    iamhere("Leaving interactive_mode()");
1006    return (retval);
1007}
1008
1009/**************************************************************************
1010 *END_INTERACTIVE_MODE                                                    *
1011 **************************************************************************/
1012
1013
1014
1015/**
1016 * Run an arbitrary restore mode (prompt the user), but from ISO images
1017 * instead of real media.
1018 * @param bkpinfo The backup information structure. Most fields are used.
1019 * @param mountlist The mountlist containing information about the user's partitions.
1020 * @param raidlist The raidlist that goes with @p mountlist.
1021 * @param nuke_me_please If TRUE, we plan to run Nuke Mode.
1022 * @return 0 for success, or the number of errors encountered.
1023 */
1024int
1025iso_mode(struct s_bkpinfo *bkpinfo,
1026         struct mountlist_itself *mountlist,
1027         struct raidlist_itself *raidlist, bool nuke_me_please)
1028{
1029    char c;
1030    int retval = 0;
1031
1032    assert(bkpinfo != NULL);
1033    assert(mountlist != NULL);
1034    assert(raidlist != NULL);
1035    if (iso_fiddly_bits(bkpinfo, nuke_me_please)) {
1036        log_msg(1, "iso_mode --- returning w/ error");
1037        return (1);
1038    } else {
1039        c = which_restore_mode();
1040        if (c == 'I' || c == 'N' || c == 'C') {
1041            interactively_obtain_media_parameters_from_user(bkpinfo,
1042                                                            FALSE);
1043        }
1044        if (c == 'I') {
1045            retval += interactive_mode(bkpinfo, mountlist, raidlist);
1046        } else if (c == 'N') {
1047            retval += nuke_mode(bkpinfo, mountlist, raidlist);
1048        } else if (c == 'C') {
1049            retval += compare_mode(bkpinfo, mountlist, raidlist);
1050        } else {
1051            log_to_screen("OK, I shan't restore/compare any files.");
1052        }
1053    }
1054    if (is_this_device_mounted(MNT_CDROM)) {
1055        paranoid_system("umount " MNT_CDROM);
1056    }
1057//  if (! already_mounted)
1058//    {
1059    if (system("umount /tmp/isodir 2> /dev/null")) {
1060        log_to_screen
1061            ("WARNING - unable to unmount device where the ISO files are stored.");
1062    }
1063//    }
1064    return (retval);
1065}
1066
1067/**************************************************************************
1068 *END_ISO_MODE                                                            *
1069 **************************************************************************/
1070
1071
1072/*            MONDO - saving your a$$ since Feb 18th, 2000            */
1073
1074
1075
1076
1077/**
1078 * Restore the user's data automatically (no prompts), after a twenty-second
1079 * warning period.
1080 * @param bkpinfo The backup information structure. Most fields are used.
1081 * @param mountlist The mountlist containing information about the user's partitions.
1082 * @param raidlist The raidlist that goes with @p mountlist.
1083 * @return 0 for success, or the number of errors encountered.
1084 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b>
1085 */
1086int
1087nuke_mode(struct s_bkpinfo *bkpinfo,
1088          struct mountlist_itself *mountlist,
1089          struct raidlist_itself *raidlist)
1090{
1091    int retval = 0;
1092    int res = 0;
1093    bool boot_loader_installed = FALSE;
1094  /** malloc **/
1095    char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN],
1096        tmpC[MAX_STR_LEN];
1097
1098    assert(bkpinfo != NULL);
1099    assert(mountlist != NULL);
1100    assert(raidlist != NULL);
1101
1102    log_msg(2, "nuke_mode --- starting");
1103
1104    get_cfg_file_from_archive_or_bust(bkpinfo);
1105    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo updated the mountlist
1106#ifdef __FreeBSD__
1107    if (strstr
1108        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
1109         "noresize"))
1110#else
1111    if (strstr
1112        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
1113         "noresize"))
1114#endif
1115    {
1116        log_msg(2, "Not resizing mountlist.");
1117    } else {
1118        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
1119    }
1120    if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
1121        sprintf(tmp,
1122                "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?",
1123                tmpA, tmpB, tmpC);
1124        if (ask_me_yes_or_no(tmp)) {
1125            retval = interactive_mode(bkpinfo, mountlist, raidlist);
1126            goto after_the_nuke;
1127        } else {
1128            fatal_error("Nuke Mode aborted. ");
1129        }
1130    }
1131    save_mountlist_to_disk(mountlist, g_mountlist_fname);
1132    mvaddstr_and_log_it(1, 30, "Restoring Automatically");
1133    if (bkpinfo->differential) {
1134        log_to_screen("Because this is a differential backup, disk");
1135        log_to_screen("partitioning and formatting will not take place.");
1136        res = 0;
1137    } else {
1138        if (partition_table_contains_Compaq_diagnostic_partition
1139            (mountlist)) {
1140            offer_to_abort_because_Compaq_Proliants_suck();
1141        } else {
1142            twenty_seconds_til_yikes();
1143            g_fprep = fopen("/tmp/prep.sh", "w");
1144#ifdef __FreeBSD__
1145            if (strstr
1146                (call_program_and_get_last_line_of_output
1147                 ("cat /tmp/cmdline"), "nopart"))
1148#else
1149            if (strstr
1150                (call_program_and_get_last_line_of_output
1151                 ("cat /proc/cmdline"), "nopart"))
1152#endif
1153            {
1154                log_msg(2,
1155                        "Not partitioning drives due to 'nopart' option.");
1156                res = 0;
1157            } else {
1158                res = partition_everything(mountlist);
1159                if (res) {
1160                    log_to_screen
1161                        ("Warning. Errors occurred during partitioning.");
1162                    res = 0;
1163                }
1164            }
1165            retval += res;
1166            if (!res) {
1167                log_to_screen("Preparing to format your disk(s)");
1168                sleep(1);
1169                system("sync");
1170                log_to_screen("Please wait. This may take a few minutes.");
1171                res += format_everything(mountlist, FALSE, raidlist);
1172            }
1173            paranoid_fclose(g_fprep);
1174        }
1175    }
1176    retval += res;
1177    if (res) {
1178        mvaddstr_and_log_it(g_currentY++,
1179                            0,
1180                            "Failed to partition and/or format your hard drives.");
1181
1182        if (ask_me_yes_or_no("Try in interactive mode instead?")) {
1183            retval = interactive_mode(bkpinfo, mountlist, raidlist);
1184            goto after_the_nuke;
1185        } else
1186            if (!ask_me_yes_or_no
1187                ("Would you like to try to proceed anyway?")) {
1188            return (retval);
1189        }
1190    }
1191    retval = mount_all_devices(mountlist, TRUE);
1192    if (retval) {
1193        unmount_all_devices(mountlist);
1194        log_to_screen
1195            ("Unable to mount all partitions. Sorry, I cannot proceed.");
1196        return (retval);
1197    }
1198    iamhere("Restoring everything");
1199    retval += restore_everything(bkpinfo, NULL);
1200    if (!run_boot_loader(FALSE)) {
1201        log_msg(1,
1202                "Great! Boot loader was installed. No need for msg at end.");
1203        boot_loader_installed = TRUE;
1204    }
1205    protect_against_braindead_sysadmins();
1206//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
1207    //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
1208    retval += unmount_all_devices(mountlist);
1209    mvaddstr_and_log_it(g_currentY,
1210                        0,
1211                        "Using e2label to label your ext2,3 partitions");
1212
1213    sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab",
1214            g_mountlist_fname);
1215    res = run_program_and_log_output(tmp, TRUE);
1216    if (res) {
1217        log_to_screen("label-partitions-as-necessary returned an error");
1218        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1219    } else {
1220        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1221    }
1222    retval += res;
1223
1224  after_the_nuke:
1225    if (retval) {
1226        log_to_screen("Errors occurred during the nuke phase.");
1227    } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE"))    // Bruno's thing
1228    {
1229        log_to_screen
1230            ("PC was restored successfully. Thank you for using Mondo Rescue.");
1231        log_to_screen
1232            ("Please visit our website at http://www.mondorescue.org for more information.");
1233    } else {
1234        strcpy(tmp,"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.");
1235        if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) {
1236            popup_and_OK(tmp);
1237        }
1238        log_to_screen
1239          ("Mondo has restored your system. Please wait for the command prompt.");
1240        log_to_screen
1241            ("Then remove the backup media and reboot.");
1242        log_to_screen
1243            ("Please visit our website at http://www.mondorescue.org for more information.");
1244    }
1245    g_I_have_just_nuked = TRUE;
1246/*
1247  if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE))
1248    {
1249      log_to_screen("PLEASE RUN 'mondorestore --mbr' NOW TO INITIALIZE YOUR BOOT SECTOR");
1250      write_one_liner_data_file(DO_MBR_PLEASE, "mondorestore --mbr");
1251    }
1252*/
1253    return (retval);
1254}
1255
1256/**************************************************************************
1257 *END_NUKE_MODE                                                           *
1258 **************************************************************************/
1259
1260
1261
1262/**
1263 * Restore the user's data (or a subset of it) to the live filesystem.
1264 * This should not be called if we're booted from CD!
1265 * @param bkpinfo The backup information structure. Most fields are used.
1266 * @return 0 for success, or the number of errors encountered.
1267 */
1268int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo)
1269{
1270    int retval = 0;
1271
1272  /** malloc **/
1273    char *old_restpath;
1274
1275    struct mountlist_itself *mountlist;
1276//  static
1277    struct raidlist_itself *raidlist;
1278    struct s_node *filelist;
1279
1280    log_msg(1, "restore_to_live_filesystem() - starting");
1281    assert(bkpinfo != NULL);
1282    malloc_string(old_restpath);
1283    mountlist = malloc(sizeof(struct mountlist_itself));
1284    raidlist = malloc(sizeof(struct raidlist_itself));
1285    if (!mountlist || !raidlist) {
1286        fatal_error("Cannot malloc() mountlist and/or raidlist");
1287    }
1288
1289    strcpy(bkpinfo->restore_path, "/");
1290    if (!g_restoring_live_from_cd) {
1291        popup_and_OK
1292            ("Please insert tape/CD/boot floppy, then hit 'OK' to continue.");
1293        sleep(1);
1294    }
1295    interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
1296    log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
1297    if (!bkpinfo->media_device[0]) {
1298        log_msg(2, "Warning - failed to find media dev");
1299    }
1300
1301
1302    log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
1303
1304    open_evalcall_form("Thinking...");
1305
1306    get_cfg_file_from_archive_or_bust(bkpinfo);
1307    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
1308    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo
1309
1310    close_evalcall_form();
1311    retval = load_mountlist(mountlist, g_mountlist_fname);
1312    load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
1313    filelist = process_filelist_and_biggielist(bkpinfo);
1314    if (filelist) {
1315        save_filelist(filelist, "/tmp/selected-files.txt");
1316        strcpy(old_restpath, bkpinfo->restore_path);
1317        if (popup_and_get_string("Restore path",
1318                                 "Restore files to where? )",
1319                                 bkpinfo->restore_path, MAX_STR_LEN / 4)) {
1320            iamhere("Restoring everything");
1321            retval += restore_everything(bkpinfo, filelist);
1322            free_filelist(filelist);
1323            strcpy(bkpinfo->restore_path, old_restpath);
1324        } else {
1325            free_filelist(filelist);
1326        }
1327        strcpy(bkpinfo->restore_path, old_restpath);
1328    }
1329    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1330        log_msg(2,
1331                "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway.");
1332    }
1333    run_program_and_log_output("umount " MNT_CDROM, FALSE);
1334    if (!bkpinfo->please_dont_eject) {
1335        eject_device(bkpinfo->media_device);
1336    }
1337    paranoid_free(old_restpath);
1338    free(mountlist);
1339    free(raidlist);
1340    return (retval);
1341}
1342
1343/**************************************************************************
1344 *END_RESTORE_TO_LIVE_FILESYSTEM                                          *
1345 **************************************************************************/
1346
1347/* @} - end of restoreGroup */
1348
1349
1350#include <utime.h>
1351/**
1352 * @addtogroup LLrestoreGroup
1353 * @{
1354 */
1355/**
1356 * Restore biggiefile @p bigfileno from the currently mounted CD.
1357 * @param bkpinfo The backup information structure. Fields used:
1358 * - @c bkpinfo->backup_media_type
1359 * - @c bkpinfo->restore_path
1360 * @param bigfileno The biggiefile number (starting from 0) to restore.
1361 * @param filelist The node structure containing the list of files to restore.
1362 * If the biggiefile is not in this list, it will be skipped (return value will
1363 * still indicate success).
1364 * @return 0 for success (or skip), nonzero for failure.
1365 */
1366int
1367restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo,
1368                             long bigfileno,
1369                             struct s_node *filelist,
1370                             char *pathname_of_last_file_restored)
1371{
1372    FILE *fin;
1373    FILE *fout;
1374    FILE *fbzip2;
1375
1376  /** malloc ***/
1377    char *checksum, *outfile_fname, *tmp, *bzip2_command,
1378        *ntfsprog_command, *suffix, *sz_devfile;
1379    char *bigblk;
1380    char *p;
1381    int retval = 0;
1382    int finished = FALSE;
1383    long sliceno;
1384    long siz;
1385    char ntfsprog_fifo[MAX_STR_LEN];
1386    char *file_to_openout = NULL;
1387    struct s_filename_and_lstat_info biggiestruct;
1388    struct utimbuf the_utime_buf, *ubuf;
1389    bool use_ntfsprog_hack = FALSE;
1390    pid_t pid;
1391    int res = 0;
1392    int old_loglevel;
1393    char sz_msg[MAX_STR_LEN];
1394    struct s_node *node;
1395
1396    old_loglevel = g_loglevel;
1397    ubuf = &the_utime_buf;
1398    assert(bkpinfo != NULL);
1399
1400    malloc_string(checksum);
1401    malloc_string(outfile_fname);
1402    malloc_string(tmp);
1403    malloc_string(bzip2_command);
1404    malloc_string(ntfsprog_command);
1405    malloc_string(suffix);
1406    malloc_string(sz_devfile);
1407
1408    pathname_of_last_file_restored[0] = '\0';
1409    if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
1410        fatal_error("Cannot malloc bigblk");
1411    }
1412
1413    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
1414        log_to_screen("Cannot even open bigfile's info file");
1415        return (1);
1416    }
1417
1418    memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
1419    if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
1420        sizeof(biggiestruct)) {
1421        log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
1422                bigfileno + 1);
1423    }
1424    paranoid_fclose(fin);
1425
1426    strcpy(checksum, biggiestruct.checksum);
1427
1428    if (!checksum[0]) {
1429        sprintf(tmp, "Warning - bigfile %ld does not have a checksum",
1430                bigfileno + 1);
1431        log_msg(3, tmp);
1432        p = checksum;
1433    }
1434
1435    if (!strncmp(biggiestruct.filename, "/dev/", 5))    // Whether NTFS or not :)
1436    {
1437        strcpy(outfile_fname, biggiestruct.filename);
1438    } else {
1439        sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
1440                biggiestruct.filename);
1441    }
1442
1443    /* skip file if we have a selective restore subset & it doesn't match */
1444    if (filelist != NULL) {
1445        node = find_string_at_node(filelist, biggiestruct.filename);
1446        if (!node) {
1447            log_msg(0, "Skipping %s (name isn't in filelist)",
1448                    biggiestruct.filename);
1449            pathname_of_last_file_restored[0] = '\0';
1450            return (0);
1451        } else if (!(node->selected)) {
1452            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1453                    biggiestruct.filename);
1454            pathname_of_last_file_restored[0] = '\0';
1455            return (0);
1456        }
1457    }
1458    /* otherwise, continue */
1459
1460    log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
1461    if (biggiestruct.use_ntfsprog) {
1462        if (strncmp(biggiestruct.filename, "/dev/", 5)) {
1463            log_msg(1,
1464                    "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
1465            log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
1466            biggiestruct.use_ntfsprog = FALSE;
1467        }
1468    }
1469
1470    if (biggiestruct.use_ntfsprog)  // if it's an NTFS device
1471//  if (!strncmp ( biggiestruct.filename, "/dev/", 5))
1472    {
1473        g_loglevel = 4;
1474        use_ntfsprog_hack = TRUE;
1475        log_msg(2,
1476                "Calling ntfsclone in background because %s is an NTFS /dev entry",
1477                outfile_fname);
1478        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
1479                (int) (random() % 32768));
1480        mkfifo(sz_devfile, 0x770);
1481        strcpy(ntfsprog_fifo, sz_devfile);
1482        file_to_openout = ntfsprog_fifo;
1483        switch (pid = fork()) {
1484        case -1:
1485            fatal_error("Fork failure");
1486        case 0:
1487            log_msg(3,
1488                    "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
1489                    biggiestruct.filename, ntfsprog_fifo);
1490            res =
1491                feed_outfrom_ntfsprog(biggiestruct.filename,
1492                                       ntfsprog_fifo);
1493//          log_msg(3, "CHILD - fip - exiting");
1494            exit(res);
1495            break;
1496        default:
1497            log_msg(3,
1498                    "feed_into_ntfsprog() called in background --- pid=%ld",
1499                    (long int) (pid));
1500        }
1501    } else {
1502        use_ntfsprog_hack = FALSE;
1503        ntfsprog_fifo[0] = '\0';
1504        file_to_openout = outfile_fname;
1505        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
1506        {
1507            make_hole_for_file(outfile_fname);
1508        }
1509    }
1510
1511    sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
1512            outfile_fname);
1513    log_msg(2, tmp);
1514
1515    /*
1516       last slice is zero-length and uncompressed; when we find it, we stop.
1517       We DON'T wait until there are no more slices; if we did that,
1518       We might stop at end of CD, not at last slice (which is 0-len and uncompd)
1519     */
1520
1521    strncpy(pathname_of_last_file_restored, biggiestruct.filename,
1522            MAX_STR_LEN - 1);
1523    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1524
1525    log_msg(3, "file_to_openout = %s", file_to_openout);
1526    if (!(fout = fopen(file_to_openout, "w"))) {
1527        log_to_screen("Cannot openout outfile_fname - hard disk full?");
1528        return (1);
1529    }
1530    log_msg(3, "Opened out to %s", outfile_fname);  // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
1531
1532    for (sliceno = 1, finished = FALSE; !finished;) {
1533        if (!does_file_exist
1534            (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
1535            &&
1536            !does_file_exist(slice_fname
1537                             (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
1538            &&
1539            !does_file_exist(slice_fname
1540                             (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1541            log_msg(3,
1542                    "Cannot find a data slice or terminator slice on CD %d",
1543                    g_current_media_number);
1544            g_current_media_number++;
1545            sprintf(tmp,
1546                    "Asking for %s #%d so that I may read slice #%ld\n",
1547                    media_descriptor_string(bkpinfo->backup_media_type),
1548                    g_current_media_number, sliceno);
1549            log_msg(2, tmp);
1550            sprintf(tmp, "Restoring from %s #%d",
1551                    media_descriptor_string(bkpinfo->backup_media_type),
1552                    g_current_media_number);
1553            log_to_screen(tmp);
1554            insist_on_this_cd_number(bkpinfo, g_current_media_number);
1555            log_to_screen("Continuing to restore.");
1556        } else {
1557            strcpy(tmp,
1558                   slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
1559            if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
1560                log_msg(2,
1561                        "End of bigfile # %ld (slice %ld is the terminator)",
1562                        bigfileno + 1, sliceno);
1563                finished = TRUE;
1564                continue;
1565            } else {
1566                if (does_file_exist
1567                    (slice_fname
1568                     (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
1569                    strcpy(bzip2_command, "lzop");
1570                    strcpy(suffix, "lzo");
1571                } else
1572                    if (does_file_exist
1573                        (slice_fname
1574                         (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1575                    strcpy(bzip2_command, "bzip2");
1576                    strcpy(suffix, "bz2");
1577                } else
1578                    if (does_file_exist
1579                        (slice_fname
1580                         (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
1581                    strcpy(bzip2_command, "");
1582                    strcpy(suffix, "");
1583                } else {
1584                    log_to_screen("OK, that's pretty fsck0red...");
1585                    return (1);
1586                }
1587            }
1588            if (bzip2_command[0] != '\0') {
1589                sprintf(bzip2_command + strlen(bzip2_command),
1590                        " -dc %s 2>> %s",
1591                        slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
1592                                    suffix), MONDO_LOGFILE);
1593            } else {
1594                sprintf(bzip2_command, "cat %s 2>> %s",
1595                        slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
1596                                    suffix), MONDO_LOGFILE);
1597            }
1598            sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ",
1599                    media_descriptor_string(bkpinfo->backup_media_type),
1600                    g_current_media_number, bigfileno + 1, sliceno);
1601            log_msg(2, tmp);
1602
1603            if (!g_text_mode) {
1604                newtDrawRootText(0, g_noof_rows - 2, tmp);
1605                newtRefresh();
1606                strip_spaces(tmp);
1607                update_progress_form(tmp);
1608            }
1609            if (!(fbzip2 = popen(bzip2_command, "r"))) {
1610                fatal_error("Can't run popen command");
1611            }
1612            while (!feof(fbzip2)) {
1613                siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
1614                if (siz > 0) {
1615                    sprintf(sz_msg, "Read %ld from fbzip2", siz);
1616                    siz = fwrite(bigblk, 1, siz, fout);
1617                    sprintf(sz_msg + strlen(sz_msg),
1618                            "; written %ld to fout", siz);
1619//        log_msg(2. sz_msg);
1620                }
1621            }
1622            paranoid_pclose(fbzip2);
1623
1624
1625            sliceno++;
1626            g_current_progress++;
1627        }
1628    }
1629/*
1630  memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy...
1631  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1632  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1633  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1634  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1635*/
1636    paranoid_fclose(fout);
1637    g_loglevel = old_loglevel;
1638
1639    if (use_ntfsprog_hack) {
1640        log_msg(3, "Waiting for ntfsclone to finish");
1641        sprintf(tmp,
1642                " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
1643        while (system(tmp) == 0) {
1644            sleep(1);
1645        }
1646        log_it("OK, ntfsclone has really finished");
1647    }
1648
1649    if (strcmp(outfile_fname, "/dev/null")) {
1650        chown(outfile_fname, biggiestruct.properties.st_uid,
1651              biggiestruct.properties.st_gid);
1652        chmod(outfile_fname, biggiestruct.properties.st_mode);
1653        ubuf->actime = biggiestruct.properties.st_atime;
1654        ubuf->modtime = biggiestruct.properties.st_mtime;
1655        utime(outfile_fname, ubuf);
1656    }
1657    paranoid_free(bigblk);
1658    paranoid_free(checksum);
1659    paranoid_free(outfile_fname);
1660    paranoid_free(tmp);
1661    paranoid_free(bzip2_command);
1662    paranoid_free(ntfsprog_command);
1663    paranoid_free(suffix);
1664    paranoid_free(sz_devfile);
1665
1666    return (retval);
1667}
1668
1669/**************************************************************************
1670 *END_ RESTORE_A_BIGGIEFILE_FROM_CD                                       *
1671 **************************************************************************/
1672
1673
1674
1675/**
1676 * Restore a biggiefile from the currently opened stream.
1677 * @param bkpinfo The backup information structure. Fields used:
1678 * - @c bkpinfo->restore_path
1679 * - @c bkpinfo->zip_exe
1680 * @param orig_bf_fname The original filename of the biggiefile.
1681 * @param biggiefile_number The number of the biggiefile (starting from 0).
1682 * @param orig_checksum Unused.
1683 * @param biggiefile_size Unused.
1684 * @param filelist The node structure containing the list of files to be restored.
1685 * If @p orig_bf_fname is not in the list, it will be ignored.
1686 * @return 0 for success (or skip), nonzero for failure.
1687 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL).
1688 */
1689int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum,   //UNUSED
1690                                     long long biggiefile_size, //UNUSED
1691                                     struct s_node *filelist,
1692                                     int use_ntfsprog,
1693                                     char *pathname_of_last_file_restored)
1694{
1695    FILE *pout;
1696    FILE *fin;
1697
1698  /** mallocs ********/
1699    char *tmp;
1700    char *command;
1701    char *outfile_fname;
1702    char *ntfsprog_command;
1703    char *sz_devfile;
1704    char *ntfsprog_fifo;
1705    char *file_to_openout = NULL;
1706
1707    struct s_node *node;
1708
1709    int old_loglevel;
1710    long current_slice_number = 0;
1711    int retval = 0;
1712    int res = 0;
1713    int ctrl_chr = '\0';
1714    long long slice_siz;
1715    bool dummy_restore = FALSE;
1716    bool use_ntfsprog_hack = FALSE;
1717    pid_t pid;
1718    struct s_filename_and_lstat_info biggiestruct;
1719    struct utimbuf the_utime_buf, *ubuf;
1720    ubuf = &the_utime_buf;
1721
1722    malloc_string(tmp);
1723    malloc_string(ntfsprog_fifo);
1724    malloc_string(outfile_fname);
1725    malloc_string(command);
1726    malloc_string(sz_devfile);
1727    malloc_string(ntfsprog_command);
1728    old_loglevel = g_loglevel;
1729    assert(bkpinfo != NULL);
1730    assert(orig_bf_fname != NULL);
1731    assert(orig_checksum != NULL);
1732
1733    pathname_of_last_file_restored[0] = '\0';
1734    if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
1735        use_ntfsprog = 1;
1736        log_msg(1, "%s --- pih=YES", orig_bf_fname);
1737    } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
1738        use_ntfsprog = 0;
1739        log_msg(1, "%s --- pih=NO", orig_bf_fname);
1740    } else {
1741        use_ntfsprog = 0;
1742        log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
1743    }
1744
1745    strncpy(pathname_of_last_file_restored, orig_bf_fname,
1746            MAX_STR_LEN - 1);
1747    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1748
1749    /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
1750
1751    if (filelist != NULL) {
1752        node = find_string_at_node(filelist, orig_bf_fname);
1753        if (!node) {
1754            dummy_restore = TRUE;
1755            log_msg(1,
1756                    "Skipping big file %ld (%s) - not in biggielist subset",
1757                    biggiefile_number + 1, orig_bf_fname);
1758            pathname_of_last_file_restored[0] = '\0';
1759        } else if (!(node->selected)) {
1760            dummy_restore = TRUE;
1761            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1762                    orig_bf_fname);
1763            pathname_of_last_file_restored[0] = '\0';
1764        }
1765    }
1766
1767    if (use_ntfsprog) {
1768        if (strncmp(orig_bf_fname, "/dev/", 5)) {
1769            log_msg(1,
1770                    "I was in error when I set use_ntfsprog to TRUE.");
1771            log_msg(1, "%s isn't even in /dev", orig_bf_fname);
1772            use_ntfsprog = FALSE;
1773        }
1774    }
1775
1776    if (use_ntfsprog) {
1777        g_loglevel = 4;
1778        strcpy(outfile_fname, orig_bf_fname);
1779        use_ntfsprog_hack = TRUE;
1780        log_msg(2,
1781                "Calling ntfsclone in background because %s is a /dev entry",
1782                outfile_fname);
1783        sprintf(sz_devfile, "%s/%d.%d.000", 
1784                bkpinfo->tmpdir,
1785                (int) (random() % 32768),
1786                (int) (random() % 32768));
1787        mkfifo(sz_devfile, 0x770);
1788        strcpy(ntfsprog_fifo, sz_devfile);
1789        file_to_openout = ntfsprog_fifo;
1790        switch (pid = fork()) {
1791        case -1:
1792            fatal_error("Fork failure");
1793        case 0:
1794            log_msg(3,
1795                    "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
1796                    outfile_fname, ntfsprog_fifo);
1797            res =
1798                feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
1799//          log_msg(3, "CHILD - fip - exiting");
1800            exit(res);
1801            break;
1802        default:
1803            log_msg(3,
1804                    "feed_into_ntfsprog() called in background --- pid=%ld",
1805                    (long int) (pid));
1806        }
1807    } else {
1808        if (!strncmp(orig_bf_fname, "/dev/", 5))    // non-NTFS partition
1809        {
1810            strcpy(outfile_fname, orig_bf_fname);
1811        } else                  // biggiefile
1812        {
1813            sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
1814                    orig_bf_fname);
1815        }
1816        use_ntfsprog_hack = FALSE;
1817        ntfsprog_fifo[0] = '\0';
1818        file_to_openout = outfile_fname;
1819        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
1820        {
1821            make_hole_for_file(outfile_fname);
1822        }
1823        sprintf(tmp, "Reassembling big file %ld (%s)",
1824                biggiefile_number + 1, orig_bf_fname);
1825        log_msg(2, tmp);
1826    }
1827
1828    if (dummy_restore) {
1829        sprintf(outfile_fname, "/dev/null");
1830    }
1831
1832    if (!bkpinfo->zip_exe[0]) {
1833        sprintf(command, "cat > \"%s\"", file_to_openout);
1834    } else {
1835        sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
1836                file_to_openout, MONDO_LOGFILE);
1837    }
1838    sprintf(tmp, "Pipe command = '%s'", command);
1839    log_msg(3, tmp);
1840
1841    /* restore biggiefile, one slice at a time */
1842    if (!(pout = popen(command, "w"))) {
1843        fatal_error("Cannot pipe out");
1844    }
1845    for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1846         ctrl_chr != BLK_STOP_A_BIGGIE;
1847         res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
1848        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
1849            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
1850        }
1851        sprintf(tmp, "Working on file #%ld, slice #%ld    ",
1852                biggiefile_number + 1, current_slice_number);
1853        log_msg(2, tmp);
1854        if (!g_text_mode) {
1855            newtDrawRootText(0, g_noof_rows - 2, tmp);
1856            newtRefresh();
1857        }
1858        strip_spaces(tmp);
1859        update_progress_form(tmp);
1860        if (current_slice_number == 0) {
1861            res =
1862                read_file_from_stream_to_file(bkpinfo,
1863                                              "/tmp/biggie-blah.txt",
1864                                              slice_siz);
1865            if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
1866                log_OS_error("blah blah");
1867            } else {
1868                if (fread
1869                    ((void *) &biggiestruct, 1, sizeof(biggiestruct),
1870                     fin) < sizeof(biggiestruct)) {
1871                    log_msg(2,
1872                            "Warning - unable to get biggiestruct of bigfile #%d",
1873                            biggiefile_number + 1);
1874                }
1875                paranoid_fclose(fin);
1876            }
1877        } else {
1878            res =
1879                read_file_from_stream_to_stream(bkpinfo, pout, slice_siz);
1880        }
1881        retval += res;
1882        res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1883        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
1884            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
1885        }
1886        current_slice_number++;
1887        g_current_progress++;
1888    }
1889    paranoid_pclose(pout);
1890
1891    log_msg(1, "pathname_of_last_file_restored is now %s",
1892            pathname_of_last_file_restored);
1893
1894    if (use_ntfsprog_hack) {
1895        log_msg(3, "Waiting for ntfsclone to finish");
1896        sprintf(tmp,
1897                " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
1898        while (system(tmp) == 0) {
1899            sleep(1);
1900        }
1901        log_msg(3, "OK, ntfsclone has really finished");
1902    }
1903
1904    log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
1905    log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
1906    if (strcmp(outfile_fname, "/dev/null")) {
1907        chmod(outfile_fname, biggiestruct.properties.st_mode);
1908        chown(outfile_fname, biggiestruct.properties.st_uid,
1909              biggiestruct.properties.st_gid);
1910        ubuf->actime = biggiestruct.properties.st_atime;
1911        ubuf->modtime = biggiestruct.properties.st_mtime;
1912        utime(outfile_fname, ubuf);
1913    }
1914
1915    paranoid_free(tmp);
1916    paranoid_free(outfile_fname);
1917    paranoid_free(command);
1918    paranoid_free(ntfsprog_command);
1919    paranoid_free(sz_devfile);
1920    paranoid_free(ntfsprog_fifo);
1921    g_loglevel = old_loglevel;
1922    return (retval);
1923}
1924
1925/**************************************************************************
1926 *END_RESTORE_A_BIGGIEFILE_FROM_STREAM                                    *
1927 **************************************************************************/
1928
1929
1930
1931/**
1932 * Restore @p tarball_fname from CD.
1933 * @param tarball_fname The filename of the tarball to restore (in /mnt/cdrom).
1934 * This will be used unmodified.
1935 * @param current_tarball_number The number (starting from 0) of the fileset
1936 * we're restoring now.
1937 * @param filelist The node structure containing the list of files to be
1938 * restored. If no file in the afioball is in this list, afio will still be
1939 * called, but nothing will be written.
1940 * @return 0 for success, nonzero for failure.
1941 */
1942int
1943restore_a_tarball_from_CD(char *tarball_fname,
1944                          long current_tarball_number,
1945                          struct s_node *filelist)
1946{
1947    int retval = 0;
1948    int res;
1949    char *p;
1950
1951  /** malloc **/
1952    char *command;
1953    char *tmp;
1954    char *filelist_name;
1955    char *filelist_subset_fname;
1956    char *executable;
1957    char *temp_log;
1958    char screen_message[100];
1959    long matches = 0;
1960    bool use_star;
1961    char *xattr_fname;
1962    char *acl_fname;
1963//  char files_to_restore_this_time_fname[MAX_STR_LEN];
1964
1965    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1966    malloc_string(command);
1967    malloc_string(tmp);
1968    malloc_string(filelist_name);
1969    malloc_string(filelist_subset_fname);
1970    malloc_string(executable);
1971    malloc_string(temp_log);
1972    malloc_string(xattr_fname);
1973    malloc_string(acl_fname);
1974
1975    log_msg(5, "Entering");
1976    filelist_subset_fname[0] = '\0';
1977    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1978//  sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
1979    sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
1980    run_program_and_log_output(command, 9);
1981    sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
1982            (int) (random() % 32768));
1983
1984    sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld",
1985            current_tarball_number);
1986    if (length_of_file(filelist_name) <= 2) {
1987        log_msg(2, "There are _zero_ files in filelist '%s'",
1988                filelist_name);
1989        log_msg(2,
1990                "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
1991        log_msg(2,
1992                "but it's non-critical. It's cosmetic. Don't worry about it.");
1993        retval = 0;
1994        goto leave_sub;
1995    }
1996    if (count_lines_in_file(filelist_name) <= 0
1997        || length_of_file(tarball_fname) <= 0) {
1998        log_msg(3, "length_of_file(%s) = %llu", tarball_fname,
1999                length_of_file(tarball_fname));
2000        sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)",
2001                current_tarball_number);
2002        log_to_screen(tmp);
2003        retval = 1;
2004        goto leave_sub;
2005    }
2006
2007    if (filelist) {
2008        sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
2009                current_tarball_number);
2010        if ((matches =
2011             save_filelist_entries_in_common(filelist_name, filelist,
2012                                             filelist_subset_fname,
2013                                             use_star))
2014            <= 0) {
2015            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
2016            log_msg(1, tmp);
2017        } else {
2018            log_msg(3, "Saved fileset %ld's subset to %s",
2019                    current_tarball_number, filelist_subset_fname);
2020        }
2021        sprintf(screen_message, "Tarball #%ld --- %ld matches",
2022                current_tarball_number, matches);
2023        log_to_screen(screen_message);
2024    } else {
2025        filelist_subset_fname[0] = '\0';
2026    }
2027
2028    if (filelist == NULL || matches > 0) {
2029        sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
2030                MNT_CDROM "/archives", current_tarball_number);
2031        sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
2032                current_tarball_number);
2033        if (strstr(tarball_fname, ".bz2")) {
2034            strcpy(executable, "bzip2");
2035        } else if (strstr(tarball_fname, ".lzo")) {
2036            strcpy(executable, "lzop");
2037        } else {
2038            executable[0] = '\0';
2039        }
2040        if (executable[0]) {
2041            sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
2042            if (run_program_and_log_output(tmp, FALSE)) {
2043                log_to_screen
2044                    ("(compare_a_tarball) Compression program not found - oh no!");
2045                paranoid_MR_finish(1);
2046            }
2047            strcpy(tmp, executable);
2048            sprintf(executable, "-P %s -Z", tmp);
2049        }
2050#ifdef __FreeBSD__
2051#define BUFSIZE 512
2052#else
2053#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
2054#endif
2055
2056//      if (strstr(tarball_fname, ".star."))
2057        if (use_star) {
2058            sprintf(command,
2059                    "star -x -force-remove -U " STAR_ACL_SZ
2060                    " errctl= file=%s", tarball_fname);
2061            if (strstr(tarball_fname, ".bz2")) {
2062                strcat(command, " -bz");
2063            }
2064        } else {
2065            if (filelist_subset_fname[0] != '\0') {
2066                sprintf(command,
2067                        "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
2068                        TAPE_BLOCK_SIZE,
2069                        BUFSIZE, executable, filelist_subset_fname,
2070//             files_to_restore_this_time_fname,
2071                        tarball_fname);
2072            } else {
2073                sprintf(command,
2074                        "afio -i -b %ld -c %ld -M 8m %s %s",
2075                        TAPE_BLOCK_SIZE,
2076                        BUFSIZE, executable, tarball_fname);
2077            }
2078        }
2079#undef BUFSIZE
2080        sprintf(command + strlen(command), " 2>> %s >> %s", temp_log,
2081                temp_log);
2082        log_msg(1, "command = '%s'", command);
2083        unlink(temp_log);
2084        res = system(command);
2085        if (res) {
2086            p = strstr(command, "-acl ");
2087            if (p) {
2088                p[0] = p[1] = p[2] = p[3] = ' ';
2089                log_msg(1, "new command = '%s'", command);
2090                res = system(command);
2091            }
2092        }
2093        if (res && length_of_file(temp_log) < 5) {
2094            res = 0;
2095        }
2096
2097        log_msg(1, "Setting fattr list %s", xattr_fname);
2098        if (length_of_file(xattr_fname) > 0) {
2099            res = set_fattr_list(filelist_subset_fname, xattr_fname);
2100            if (res) {
2101                log_to_screen
2102                    ("Errors occurred while setting extended attributes");
2103            } else {
2104                log_msg(1, "I set xattr OK");
2105            }
2106            retval += res;
2107        }
2108        if (length_of_file(acl_fname) > 0) {
2109            log_msg(1, "Setting acl list %s", acl_fname);
2110            res = set_acl_list(filelist_subset_fname, acl_fname);
2111            if (res) {
2112                log_to_screen
2113                    ("Errors occurred while setting access control lists");
2114            } else {
2115                log_msg(1, "I set ACL OK");
2116            }
2117            retval += res;
2118        }
2119        if (retval) {
2120            sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
2121            system(command);
2122            log_msg(2, "Errors occurred while processing fileset #%d",
2123                    current_tarball_number);
2124        } else {
2125            log_msg(2, "Fileset #%d processed OK", current_tarball_number);
2126        }
2127    }
2128    if (does_file_exist("/PAUSE")) {
2129        popup_and_OK
2130            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2131    }
2132    unlink(filelist_subset_fname);
2133    unlink(xattr_fname);
2134    unlink(acl_fname);
2135    unlink(temp_log);
2136
2137  leave_sub:
2138    paranoid_free(command);
2139    paranoid_free(tmp);
2140    paranoid_free(filelist_name);
2141    paranoid_free(filelist_subset_fname);
2142    paranoid_free(executable);
2143    paranoid_free(temp_log);
2144    paranoid_free(xattr_fname);
2145    paranoid_free(acl_fname);
2146    log_msg(5, "Leaving");
2147    return (retval);
2148}
2149
2150/**************************************************************************
2151 *END_RESTORE_A_TARBALL_FROM_CD                                           *
2152 **************************************************************************/
2153
2154
2155/**
2156 * Restore a tarball from the currently opened stream.
2157 * @param bkpinfo The backup information structure. Fields used:
2158 * - @c bkpinfo->backup_media_type
2159 * - @c bkpinfo->media_device
2160 * - @c bkpinfo->zip_exe
2161 * @param tarball_fname The filename of the afioball to restore.
2162 * @param current_tarball_number The number (starting from 0) of the fileset
2163 * we're restoring now.
2164 * @param filelist The node structure containing the list of files to be
2165 * restored. If no file in the afioball is in this list, afio will still be
2166 * called, but nothing will be written.
2167 * @param size The size (in @b bytes) of the afioball.
2168 * @return 0 for success, nonzero for failure.
2169 */
2170int
2171restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo,
2172                              char *tarball_fname,
2173                              long current_tarball_number,
2174                              struct s_node *filelist,
2175                              long long size, char *xattr_fname,
2176                              char *acl_fname)
2177{
2178    int retval = 0;
2179    int res = 0;
2180
2181  /** malloc add ***/
2182    char *tmp;
2183    char *command;
2184    char *afio_fname;
2185    char *filelist_fname;
2186    char *filelist_subset_fname;
2187    char *executable;
2188    long matches = 0;
2189    bool restore_this_fileset = FALSE;
2190    bool use_star;
2191
2192    assert(bkpinfo != NULL);
2193    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
2194    malloc_string(filelist_subset_fname);
2195    malloc_string(filelist_fname);
2196    malloc_string(afio_fname);
2197    malloc_string(executable);
2198    malloc_string(command);
2199    malloc_string(tmp);
2200    filelist_subset_fname[0] = '\0';
2201    /* to do it with a file... */
2202    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
2203    sprintf(tmp,
2204            "Restoring from fileset #%ld (%ld KB) on %s #%d",
2205            current_tarball_number, (long) size >> 10,
2206            media_descriptor_string(bkpinfo->backup_media_type),
2207            g_current_media_number);
2208    log_msg(2, tmp);
2209    run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
2210
2211  /****************************************************************************
2212   * Use RAMDISK's /tmp; saves time; oh wait, it's too small                  *
2213   * Well, pipe from tape to afio, then; oh wait, can't do that either: bug   *
2214   * in afio or someting; oh darn.. OK, use tmpfs :-)                         *
2215   ****************************************************************************/
2216    filelist_fname[0] = filelist_subset_fname[0] = '\0';
2217    sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
2218            current_tarball_number);
2219    sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
2220            current_tarball_number);
2221    sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
2222            bkpinfo->tmpdir, current_tarball_number);
2223//  sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
2224    res = read_file_from_stream_to_file(bkpinfo, afio_fname, size);
2225    if (strstr(tarball_fname, ".star")) {
2226        bkpinfo->use_star = TRUE;
2227    }
2228    if (res) {
2229        log_msg(1, "Warning - error reading afioball from tape");
2230    }
2231    if (bkpinfo->compression_level == 0) {
2232        executable[0] = '\0';
2233    } else {
2234        if (bkpinfo->use_star) {
2235            strcpy(executable, " -bz");
2236        } else {
2237            sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
2238        }
2239    }
2240
2241    if (!filelist)              // if unconditional restore then restore entire fileset
2242    {
2243        restore_this_fileset = TRUE;
2244    } else                      // If restoring selectively then get TOC from tarball
2245    {
2246        if (strstr(tarball_fname, ".star.")) {
2247            use_star = TRUE;
2248            sprintf(command, "star -t file=%s %s", afio_fname, executable);
2249        } else {
2250            use_star = FALSE;
2251            sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
2252                    executable, afio_fname);
2253        }
2254        sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
2255                MONDO_LOGFILE);
2256        log_msg(1, "command = %s", command);
2257        if (system(command)) {
2258            log_msg(4, "Warning - error occurred while retrieving TOC");
2259        }
2260        if ((matches =
2261             save_filelist_entries_in_common(filelist_fname, filelist,
2262                                             filelist_subset_fname,
2263                                             use_star))
2264            <= 0 || length_of_file(filelist_subset_fname) < 2) {
2265            if (length_of_file(filelist_subset_fname) < 2) {
2266                log_msg(1, "No matches found in fileset %ld",
2267                        current_tarball_number);
2268            }
2269            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
2270            log_msg(2, tmp);
2271            restore_this_fileset = FALSE;
2272        } else {
2273            log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
2274                    matches, current_tarball_number,
2275                    filelist_subset_fname);
2276            restore_this_fileset = TRUE;
2277        }
2278    }
2279
2280// Concoct the call to star/afio to restore files
2281    if (strstr(tarball_fname, ".star."))    // star
2282    {
2283        sprintf(command, "star -x file=%s %s", afio_fname, executable);
2284        if (filelist) {
2285            sprintf(command + strlen(command), " list=%s",
2286                    filelist_subset_fname);
2287        }
2288    } else                      // afio
2289    {
2290        sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
2291                executable);
2292        if (filelist) {
2293            sprintf(command + strlen(command), " -w %s",
2294                    filelist_subset_fname);
2295        }
2296        sprintf(command + strlen(command), " %s", afio_fname);
2297    }
2298    sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
2299
2300// Call if IF there are files to restore (selectively/unconditionally)
2301    if (restore_this_fileset) {
2302        log_msg(1, "Calling command='%s'", command);
2303        paranoid_system(command);
2304
2305        iamhere("Restoring xattr, acl stuff");
2306        res = set_fattr_list(filelist_subset_fname, xattr_fname);
2307        if (res) {
2308            log_msg(1, "Errors occurred while setting xattr");
2309        } else {
2310            log_msg(1, "I set xattr OK");
2311        }
2312        retval += res;
2313
2314        res = set_acl_list(filelist_subset_fname, acl_fname);
2315        if (res) {
2316            log_msg(1, "Errors occurred while setting ACL");
2317        } else {
2318            log_msg(1, "I set ACL OK");
2319        }
2320        retval += res;
2321
2322    } else {
2323        log_msg(1, "NOT CALLING '%s'", command);
2324    }
2325
2326    if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
2327        log_to_screen("Paused after set %ld", current_tarball_number);
2328        popup_and_OK("Pausing. Press ENTER to continue.");
2329    }
2330
2331    unlink(filelist_subset_fname);
2332    unlink(filelist_fname);
2333    unlink(afio_fname);
2334
2335    paranoid_free(filelist_subset_fname);
2336    paranoid_free(filelist_fname);
2337    paranoid_free(afio_fname);
2338    paranoid_free(command);
2339    paranoid_free(tmp);
2340    return (retval);
2341}
2342
2343/**************************************************************************
2344 *END_RESTORE_A_TARBALL_FROM_STREAM                                       *
2345 **************************************************************************/
2346
2347
2348
2349
2350/**
2351 * Restore all biggiefiles from all media in this CD backup.
2352 * The CD with the last afioball should be currently mounted.
2353 * @param bkpinfo The backup information structure. @c backup_media_type is the
2354 * only field used in this function.
2355 * @param filelist The node structure containing the list of files to be
2356 * restored. If a prospective biggiefile is not in this list, it will be ignored.
2357 * @return 0 for success, nonzero for failure.
2358 */
2359int
2360restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo,
2361                                struct s_node *filelist)
2362{
2363    int retval = 0;
2364    int res;
2365    long noof_biggiefiles, bigfileno = 0, total_slices;
2366  /** malloc **/
2367    char *tmp;
2368    bool just_changed_cds = FALSE, finished;
2369    char *xattr_fname;
2370    char *acl_fname;
2371    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
2372    char *pathname_of_last_biggie_restored;
2373    FILE *fbw = NULL;
2374
2375    malloc_string(xattr_fname);
2376    malloc_string(acl_fname);
2377    malloc_string(tmp);
2378    malloc_string(biggies_whose_EXATs_we_should_set);
2379    malloc_string(pathname_of_last_biggie_restored);
2380    assert(bkpinfo != NULL);
2381
2382    sprintf(biggies_whose_EXATs_we_should_set,
2383            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2384    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2385        log_msg(1, "Warning - cannot openout %s",
2386                biggies_whose_EXATs_we_should_set);
2387    }
2388
2389    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2390    total_slices = atol(tmp);
2391    sprintf(tmp, "Reassembling large files      ");
2392    mvaddstr_and_log_it(g_currentY, 0, tmp);
2393    if (length_of_file(BIGGIELIST) < 6) {
2394        log_msg(1, "OK, no biggielist; not restoring biggiefiles");
2395        return (0);
2396    }
2397    noof_biggiefiles = count_lines_in_file(BIGGIELIST);
2398    if (noof_biggiefiles <= 0) {
2399        log_msg(2,
2400                "OK, no biggiefiles in biggielist; not restoring biggiefiles");
2401        return (0);
2402    }
2403    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2404            noof_biggiefiles);
2405    log_msg(2, tmp);
2406
2407    open_progress_form("Reassembling large files",
2408                       "I am now reassembling all the large files.",
2409                       "Please wait. This may take some time.",
2410                       "", total_slices);
2411    for (bigfileno = 0, finished = FALSE; !finished;) {
2412        log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
2413        if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
2414            log_msg(3,
2415                    "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
2416            log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
2417                    bigfileno + 1,
2418                    media_descriptor_string(bkpinfo->backup_media_type),
2419                    g_current_media_number);
2420            log_msg(3, "Slicename would have been %s",
2421                    slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, ""));
2422            // I'm not positive 'just_changed_cds' is even necessary...
2423            if (just_changed_cds) {
2424                just_changed_cds = FALSE;
2425                log_msg(3,
2426                        "I'll continue to scan this CD for bigfiles to be restored.");
2427            } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
2428                insist_on_this_cd_number(bkpinfo,
2429                                         ++g_current_media_number);
2430                sprintf(tmp, "Restoring from %s #%d",
2431                        media_descriptor_string(bkpinfo->
2432                                                backup_media_type),
2433                        g_current_media_number);
2434                log_to_screen(tmp);
2435                just_changed_cds = TRUE;
2436            } else {
2437                log_msg(2, "There was no bigfile #%ld. That's OK.",
2438                        bigfileno + 1);
2439                log_msg(2, "I'm going to stop restoring bigfiles now.");
2440                finished = TRUE;
2441            }
2442        } else {
2443            just_changed_cds = FALSE;
2444            sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
2445            update_progress_form(tmp);
2446            res =
2447                restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist,
2448                                             pathname_of_last_biggie_restored);
2449            iamhere(pathname_of_last_biggie_restored);
2450            if (fbw && pathname_of_last_biggie_restored[0]) {
2451                fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2452            }
2453            retval += res;
2454            bigfileno++;
2455
2456        }
2457    }
2458
2459    if (fbw) {
2460        fclose(fbw);
2461        sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2462        sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2463        if (length_of_file(acl_fname) > 0) {
2464            set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2465        }
2466        if (length_of_file(xattr_fname) > 0) {
2467            set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2468        }
2469    }
2470    if (does_file_exist("/PAUSE")) {
2471        popup_and_OK
2472            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2473    }
2474    close_progress_form();
2475    if (retval) {
2476        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2477    } else {
2478        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2479    }
2480    paranoid_free(xattr_fname);
2481    paranoid_free(acl_fname);
2482    paranoid_free(tmp);
2483    paranoid_free(biggies_whose_EXATs_we_should_set);
2484    paranoid_free(pathname_of_last_biggie_restored);
2485    return (retval);
2486}
2487
2488/**************************************************************************
2489 *END_RESTORE_ALL_BIGGIFILES_FROM_CD                                      *
2490 **************************************************************************/
2491
2492
2493
2494/**
2495 * Restore all afioballs from all CDs in the backup.
2496 * The first CD should be inserted (if not, it will be asked for).
2497 * @param bkpinfo The backup information structure. @c backup_media_type is the
2498 * only field used in @e this function.
2499 * @param filelist The node structure containing the list of files to be
2500 * restored. If no file in some particular afioball is in this list, afio will
2501 * still be called for that fileset, but nothing will be written.
2502 * @return 0 for success, or the number of filesets that failed.
2503 */
2504int
2505restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo,
2506                             struct s_node *filelist)
2507{
2508    int retval = 0;
2509    int res;
2510    int attempts;
2511    long current_tarball_number = 0;
2512    long max_val;
2513  /**malloc ***/
2514    char *tmp;
2515    char *tarball_fname;
2516    char *progress_str;
2517    char *comment;
2518
2519    malloc_string(tmp);
2520    malloc_string(tarball_fname);
2521    malloc_string(progress_str);
2522    malloc_string(comment);
2523
2524    assert(bkpinfo != NULL);
2525
2526    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2527    log_msg(2,
2528            "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
2529    if (g_current_media_number != 1) {
2530        log_msg(3, "OK, that's jacked up.");
2531        g_current_media_number = 1;
2532    }
2533    insist_on_this_cd_number(bkpinfo, g_current_media_number);
2534    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2535    max_val = atol(tmp) + 1;
2536    sprintf(progress_str, "Restoring from %s #%d",
2537            media_descriptor_string(bkpinfo->backup_media_type),
2538            g_current_media_number);
2539    log_to_screen(progress_str);
2540    open_progress_form("Restoring from archives",
2541                       "Restoring data from the archives.",
2542                       "Please wait. This may take some time.",
2543                       progress_str, max_val);
2544    for (;;) {
2545        insist_on_this_cd_number(bkpinfo, g_current_media_number);
2546        update_progress_form(progress_str);
2547        sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
2548                current_tarball_number);
2549        if (!does_file_exist(tarball_fname)) {
2550            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
2551                    current_tarball_number);
2552        }
2553        if (!does_file_exist(tarball_fname)) {
2554            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
2555                    current_tarball_number);
2556        }
2557        if (!does_file_exist(tarball_fname)) {
2558            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
2559                    current_tarball_number);
2560        }
2561        if (!does_file_exist(tarball_fname)) {
2562            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
2563                    current_tarball_number);
2564        }
2565        if (!does_file_exist(tarball_fname)) {
2566            if (current_tarball_number == 0) {
2567                log_to_screen
2568                    ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
2569                return (0);
2570            }
2571            if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2572                || system("find " MNT_CDROM
2573                          "/archives/slice* > /dev/null 2> /dev/null") ==
2574                0) {
2575                break;
2576            }
2577            g_current_media_number++;
2578            sprintf(progress_str, "Restoring from %s #%d",
2579                    media_descriptor_string(bkpinfo->backup_media_type),
2580                    g_current_media_number);
2581            log_to_screen(progress_str);
2582        } else {
2583            sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
2584                    current_tarball_number,
2585                    media_descriptor_string(bkpinfo->backup_media_type),
2586                    g_current_media_number);
2587//    log_msg(3, "progress_str = %s", progress_str);
2588            for (res = 999, attempts = 0; attempts < 3 && res != 0;
2589                 attempts++) {
2590                res =
2591                    restore_a_tarball_from_CD(tarball_fname,
2592                                              current_tarball_number,
2593                                              filelist);
2594            }
2595            sprintf(tmp, "%s #%d, fileset #%ld - restore ",
2596                    media_descriptor_string(bkpinfo->backup_media_type),
2597                    g_current_media_number, current_tarball_number);
2598            if (res) {
2599                strcat(tmp, "reported errors");
2600            } else if (attempts > 1) {
2601                strcat(tmp, "succeeded");
2602            } else {
2603                strcat(tmp, "succeeded");
2604            }
2605            if (attempts > 1) {
2606                sprintf(tmp + strlen(tmp), " (%d attempts) - review logs",
2607                        attempts);
2608            }
2609            strcpy(comment, tmp);
2610            if (attempts > 1) {
2611                log_to_screen(comment);
2612            }
2613
2614            retval += res;
2615            current_tarball_number++;
2616            g_current_progress++;
2617        }
2618    }
2619    close_progress_form();
2620    if (retval) {
2621        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2622    } else {
2623        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2624    }
2625    paranoid_free(tmp);
2626    paranoid_free(tarball_fname);
2627    paranoid_free(progress_str);
2628    paranoid_free(comment);
2629
2630    return (retval);
2631}
2632
2633/**************************************************************************
2634 *END_RESTORE_ALL_TARBALLS_FROM_CD                                        *
2635 **************************************************************************/
2636
2637
2638
2639/**
2640 * Restore all biggiefiles from the currently opened stream.
2641 * @param bkpinfo The backup information structure. Passed to other functions.
2642 * @param filelist The node structure containing the list of files to be
2643 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2644 * @return 0 for success, or the number of biggiefiles that failed.
2645 */
2646int
2647restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo,
2648                                    struct s_node *filelist)
2649{
2650    long noof_biggiefiles;
2651    long current_bigfile_number = 0;
2652    long total_slices;
2653
2654    int retval = 0;
2655    int res = 0;
2656    int ctrl_chr;
2657
2658  /** malloc add ****/
2659    char *tmp;
2660    char *biggie_fname;
2661    char *biggie_cksum;
2662    char *xattr_fname;
2663    char *acl_fname;
2664    char *p;
2665    char *pathname_of_last_biggie_restored;
2666    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
2667    long long biggie_size;
2668    FILE *fbw = NULL;
2669
2670    malloc_string(tmp);
2671    malloc_string(biggie_fname);
2672    malloc_string(biggie_cksum);
2673    malloc_string(xattr_fname);
2674    malloc_string(acl_fname);
2675    malloc_string(biggies_whose_EXATs_we_should_set);
2676    malloc_string(pathname_of_last_biggie_restored);
2677    assert(bkpinfo != NULL);
2678
2679    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2680
2681    total_slices = atol(tmp);
2682    sprintf(tmp, "Reassembling large files      ");
2683    sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2684    sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2685    mvaddstr_and_log_it(g_currentY, 0, tmp);
2686    sprintf(biggies_whose_EXATs_we_should_set,
2687            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2688    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2689        log_msg(1, "Warning - cannot openout %s",
2690                biggies_whose_EXATs_we_should_set);
2691    }
2692// get xattr and acl files if they're there
2693    res =
2694        read_header_block_from_stream(&biggie_size, biggie_fname,
2695                                      &ctrl_chr);
2696    if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2697        res =
2698            read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname,
2699                                      &ctrl_chr, xattr_fname, acl_fname);
2700    }
2701
2702    noof_biggiefiles = atol(biggie_fname);
2703    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2704            noof_biggiefiles);
2705    log_msg(2, tmp);
2706    open_progress_form("Reassembling large files",
2707                       "I am now reassembling all the large files.",
2708                       "Please wait. This may take some time.",
2709                       "", total_slices);
2710
2711    for (res =
2712         read_header_block_from_stream(&biggie_size, biggie_fname,
2713                                       &ctrl_chr);
2714         ctrl_chr != BLK_STOP_BIGGIEFILES;
2715         res =
2716         read_header_block_from_stream(&biggie_size, biggie_fname,
2717                                       &ctrl_chr)) {
2718        if (ctrl_chr != BLK_START_A_NORMBIGGIE
2719            && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2720            wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2721        }
2722        p = strrchr(biggie_fname, '/');
2723        if (!p) {
2724            p = biggie_fname;
2725        } else {
2726            p++;
2727        }
2728        sprintf(tmp, "Restoring big file %ld (%lld K)",
2729                current_bigfile_number + 1, biggie_size / 1024);
2730        update_progress_form(tmp);
2731        res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
2732                                               current_bigfile_number,
2733                                               biggie_cksum,
2734                                               biggie_size,
2735                                               filelist, ctrl_chr,
2736                                               pathname_of_last_biggie_restored);
2737        log_msg(1, "I believe I have restored %s",
2738                pathname_of_last_biggie_restored);
2739        if (fbw && pathname_of_last_biggie_restored[0]) {
2740            fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2741        }
2742        retval += res;
2743        current_bigfile_number++;
2744
2745    }
2746    if (current_bigfile_number != noof_biggiefiles
2747        && noof_biggiefiles != 0) {
2748        sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
2749                current_bigfile_number, noof_biggiefiles);
2750    } else {
2751        sprintf(tmp,
2752                "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
2753                noof_biggiefiles, current_bigfile_number);
2754    }
2755    log_msg(1, tmp);
2756
2757    if (fbw) {
2758        fclose(fbw);
2759        if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
2760            iamhere("Setting biggie-EXATs");
2761            if (length_of_file(acl_fname) > 0) {
2762                log_msg(1, "set_acl_list(%s,%s)",
2763                        biggies_whose_EXATs_we_should_set, acl_fname);
2764                set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2765            }
2766            if (length_of_file(xattr_fname) > 0) {
2767                log_msg(1, "set_fattr_List(%s,%s)",
2768                        biggies_whose_EXATs_we_should_set, xattr_fname);
2769                set_fattr_list(biggies_whose_EXATs_we_should_set,
2770                               xattr_fname);
2771            }
2772        } else {
2773            iamhere
2774                ("No biggiefiles selected. So, no biggie-EXATs to set.");
2775        }
2776    }
2777    if (does_file_exist("/PAUSE")) {
2778        popup_and_OK
2779            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2780    }
2781
2782    close_progress_form();
2783    if (retval) {
2784        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2785    } else {
2786        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2787    }
2788    paranoid_free(biggies_whose_EXATs_we_should_set);
2789    paranoid_free(pathname_of_last_biggie_restored);
2790    paranoid_free(biggie_fname);
2791    paranoid_free(biggie_cksum);
2792    paranoid_free(xattr_fname);
2793    paranoid_free(acl_fname);
2794    paranoid_free(tmp);
2795    return (retval);
2796}
2797
2798/**************************************************************************
2799 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM                                 *
2800 **************************************************************************/
2801
2802
2803
2804
2805
2806
2807/**
2808 * Restore all afioballs from the currently opened tape stream.
2809 * @param bkpinfo The backup information structure. Fields used:
2810 * - @c bkpinfo->backup_media_type
2811 * - @c bkpinfo->restore_path
2812 * @param filelist The node structure containing the list of files to be
2813 * restored. If no file in an afioball is in this list, afio will still be
2814 * called for that fileset, but nothing will be written.
2815 * @return 0 for success, or the number of filesets that failed.
2816 */
2817int
2818restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo,
2819                                 struct s_node *filelist)
2820{
2821    int retval = 0;
2822    int res;
2823    long current_afioball_number = 0;
2824    int ctrl_chr;
2825    long max_val /*, total_noof_files */ ;
2826
2827  /** malloc **/
2828    char *tmp;
2829    char *progress_str;
2830    char *tmp_fname;
2831    char *xattr_fname;
2832    char *acl_fname;
2833
2834    long long tmp_size;
2835
2836    malloc_string(tmp);
2837    malloc_string(progress_str);
2838    malloc_string(tmp_fname);
2839    assert(bkpinfo != NULL);
2840    malloc_string(xattr_fname);
2841    malloc_string(acl_fname);
2842    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2843    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2844    max_val = atol(tmp) + 1;
2845
2846    chdir(bkpinfo->restore_path);   /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
2847
2848    run_program_and_log_output("pwd", 5);
2849
2850    sprintf(progress_str, "Restoring from media #%d",
2851            g_current_media_number);
2852    log_to_screen(progress_str);
2853    open_progress_form("Restoring from archives",
2854                       "Restoring data from the archives.",
2855                       "Please wait. This may take some time.",
2856                       progress_str, max_val);
2857
2858    log_msg(3, "hey");
2859
2860    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2861    if (res) {
2862        log_msg(2, "Warning - error reading afioball from tape");
2863    }
2864    retval += res;
2865    if (ctrl_chr != BLK_START_AFIOBALLS) {
2866        wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
2867    }
2868    log_msg(2, "ho");
2869    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2870    while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2871        update_progress_form(progress_str);
2872        sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
2873                current_afioball_number);
2874        sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
2875                current_afioball_number);
2876        unlink(xattr_fname);
2877        unlink(acl_fname);
2878        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2879            iamhere("Reading EXAT files from tape");
2880            res =
2881                read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname,
2882                                          &ctrl_chr, xattr_fname,
2883                                          acl_fname);
2884        }
2885        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2886            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2887        }
2888        sprintf(tmp,
2889                "Restoring from fileset #%ld (name=%s, size=%ld K)",
2890                current_afioball_number, tmp_fname, (long) tmp_size >> 10);
2891        res =
2892            restore_a_tarball_from_stream(bkpinfo, tmp_fname,
2893                                          current_afioball_number,
2894                                          filelist, tmp_size, xattr_fname,
2895                                          acl_fname);
2896        retval += res;
2897        if (res) {
2898            sprintf(tmp, "Fileset %ld - errors occurred",
2899                    current_afioball_number);
2900            log_to_screen(tmp);
2901        }
2902        res =
2903            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2904        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2905            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2906        }
2907
2908        current_afioball_number++;
2909        g_current_progress++;
2910        sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
2911                current_afioball_number,
2912                media_descriptor_string(bkpinfo->backup_media_type),
2913                g_current_media_number);
2914        res =
2915            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2916        unlink(xattr_fname);
2917        unlink(acl_fname);
2918    }                           // next
2919    log_msg(1, "All done with afioballs");
2920    close_progress_form();
2921    if (retval) {
2922        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2923    } else {
2924        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2925    }
2926    paranoid_free(tmp);
2927    paranoid_free(progress_str);
2928    paranoid_free(tmp_fname);
2929    paranoid_free(xattr_fname);
2930    paranoid_free(acl_fname);
2931    return (retval);
2932}
2933
2934/**************************************************************************
2935 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM                                   *
2936 **************************************************************************/
2937
2938/* @} - end of LLrestoreGroup */
2939
2940
2941/**
2942 * Restore all files in @p filelist.
2943 * @param bkpinfo The backup information structure. Most fields are used.
2944 * @param filelist The node structure containing the list of files to be
2945 * restored.
2946 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2947 * @ingroup restoreGroup
2948 */
2949int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
2950{
2951    int resA;
2952    int resB;
2953
2954  /** mallco ***/
2955    char *cwd;
2956    char *newpath;
2957    char *tmp;
2958    assert(bkpinfo != NULL);
2959
2960    malloc_string(cwd);
2961    malloc_string(newpath);
2962    malloc_string(tmp);
2963    log_msg(2, "restore_everything() --- starting");
2964    g_current_media_number = 1;
2965    getcwd(cwd, MAX_STR_LEN - 1);
2966    sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
2967    run_program_and_log_output(tmp, FALSE);
2968    log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
2969    chdir(bkpinfo->restore_path);
2970    getcwd(newpath, MAX_STR_LEN - 1);
2971    log_msg(1, "path is now %s", newpath);
2972    log_msg(1, "restoring everything");
2973    if (!find_home_of_exe("petris") && !g_text_mode) {
2974        newtDrawRootText(0, g_noof_rows - 2,
2975                         "Press ALT-<left cursor> twice to play Petris :-) ");
2976        newtRefresh();
2977    }
2978    mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
2979    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2980        mount_cdrom(bkpinfo);
2981        mvaddstr_and_log_it(g_currentY++, 0,
2982                            "Restoring OS and data from streaming media");
2983        if (bkpinfo->backup_media_type == cdstream) {
2984            openin_cdstream(bkpinfo);
2985        } else {
2986            assert_string_is_neither_NULL_nor_zerolength(bkpinfo->
2987                                                         media_device);
2988            openin_tape(bkpinfo);
2989        }
2990        resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
2991        resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
2992        if (bkpinfo->backup_media_type == cdstream) {
2993            closein_cdstream(bkpinfo);
2994        } else {
2995            closein_tape(bkpinfo);
2996        }
2997    } else {
2998        mvaddstr_and_log_it(g_currentY++, 0,
2999                            "Restoring OS and data from CD       ");
3000        mount_cdrom(bkpinfo);
3001        resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
3002        resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
3003    }
3004    chdir(cwd);
3005    if (resA + resB) {
3006        log_to_screen("Errors occurred while data was being restored.");
3007    }
3008    if (length_of_file("/etc/raidtab") > 0) {
3009        log_msg(2, "Copying local raidtab to restored filesystem");
3010        run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
3011                                   "/etc/raidtab", FALSE);
3012    }
3013    kill_petris();
3014    log_msg(2, "restore_everything() --- leaving");
3015    paranoid_free(cwd);
3016    paranoid_free(newpath);
3017    paranoid_free(tmp);
3018    return (resA + resB);
3019}
3020
3021/**************************************************************************
3022 *END_RESTORE_EVERYTHING                                                  *
3023 **************************************************************************/
3024
3025
3026
3027/**
3028 * @brief Haha. You wish! (This function is not implemented :-)
3029 */
3030int
3031restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,
3032                                 char *monitas_device,
3033                                 char *restore_this_directory,
3034                                 char *restore_here)
3035     /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
3036{
3037    FILE *fout;
3038    int retval = 0;
3039    int i;
3040    int j;
3041    struct mountlist_itself the_mountlist;
3042    static struct raidlist_itself the_raidlist;
3043  /** malloc **/
3044    char tmp[MAX_STR_LEN + 1];
3045    char command[MAX_STR_LEN + 1];
3046    char datablock[256 * 1024];
3047    char datadisks_fname[MAX_STR_LEN + 1];
3048    long k;
3049    long length;
3050    long long llt;
3051    struct s_node *filelist = NULL;
3052    assert(bkpinfo != NULL);
3053    assert_string_is_neither_NULL_nor_zerolength(monitas_device);
3054    assert(restore_this_directory != NULL);
3055    assert(restore_here != NULL);
3056
3057    sprintf(tmp, "restore_here = '%s'", restore_here);
3058
3059    log_msg(2, tmp);
3060
3061    log_msg(2, "restore_live_from_monitas_server() - starting");
3062    unlink("/tmp/mountlist.txt");
3063    unlink("/tmp/filelist.full");
3064    unlink("/tmp/biggielist.txt");
3065    if (restore_here[0] == '\0') {
3066        strcpy(bkpinfo->restore_path, MNT_RESTORING);
3067    } else {
3068        strcpy(bkpinfo->restore_path, restore_here);
3069    }
3070    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
3071    sprintf(tmp, "FYI - data will be restored to %s",
3072            bkpinfo->restore_path);
3073    log_msg(3, tmp);
3074    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
3075    sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
3076            (int) (random() % 32768));
3077    chdir(bkpinfo->tmpdir);
3078
3079    sprintf(command, "cat %s", monitas_device);
3080    g_tape_stream = popen(command, "r");    // for compatibility with openin_tape()
3081    if (!(fout = fopen(datadisks_fname, "w"))) {
3082        log_OS_error(datadisks_fname);
3083        return (1);
3084    }
3085    for (i = 0; i < 32; i++) {
3086        for (j = 0; j < 4; j++) {
3087            for (length = k = 0; length < 256 * 1024; length += k) {
3088                k = fread(datablock + length, 1, 256 * 1024 - length,
3089                          g_tape_stream);
3090            }
3091            fwrite(datablock, 1, length, fout);
3092            g_tape_posK += length;
3093        }
3094    }
3095    paranoid_fclose(fout);
3096    sprintf(command,
3097            "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
3098            datadisks_fname);
3099    run_program_and_log_output(command, 4);
3100    read_header_block_from_stream(&llt, tmp, &i);
3101    read_header_block_from_stream(&llt, tmp, &i);
3102
3103    unlink(datadisks_fname);
3104    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
3105    retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo   strcpy(bkpinfo->media_device, monitas_device);
3106
3107
3108    load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);
3109    iamhere("FIXME");
3110    fatal_error("This will fail");
3111    sprintf(command,
3112            "grep -E '^%s.*$' %s > %s",
3113            restore_this_directory, g_filelist_full, g_filelist_full);
3114    if (system(command)) {
3115        retval++;
3116        log_to_screen
3117            ("Error(s) occurred while processing filelist and wildcard");
3118    }
3119    iamhere("FIXME");
3120    fatal_error("This will fail");
3121    sprintf(command,
3122            "grep -E '^%s.*$' %s > %s",
3123            restore_this_directory, g_biggielist_txt, g_biggielist_txt);
3124    if (system(command)) {
3125        log_msg(1,
3126                "Error(s) occurred while processing biggielist and wildcard");
3127    }
3128    sprintf(command, "touch %s", g_biggielist_txt);
3129    run_program_and_log_output(command, FALSE);
3130//  filelist = load_filelist(g_filelist_restthese);  // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
3131    retval += restore_everything(bkpinfo, filelist);
3132    free_filelist(filelist);
3133    log_msg(2, "--------End of restore_live_from_monitas_server--------");
3134    return (retval);
3135}
3136
3137/**************************************************************************
3138 *END_RESTORE_LIVE_FROM_MONITAS_SERVER                                    *
3139 **************************************************************************/
3140
3141
3142
3143
3144extern void wait_until_software_raids_are_prepped(char *, int);
3145
3146
3147char which_restore_mode(void);
3148
3149
3150/**
3151 * Log a "don't panic" message to the logfile.
3152 */
3153void welcome_to_mondorestore()
3154{
3155    log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
3156    log_msg(0,
3157            "DON'T PANIC! Mondorestore logs almost everything, so please ");
3158    log_msg(0,
3159            "don't break out in a cold sweat just because you see a few  ");
3160    log_msg(0,
3161            "error messages in the log. Read them; analyze them; see if  ");
3162    log_msg(0,
3163            "they are significant; above all, verify your backups! Please");
3164    log_msg(0,
3165            "attach a compressed copy of this log to any e-mail you send ");
3166    log_msg(0,
3167            "to the Mondo mailing list when you are seeking technical    ");
3168    log_msg(0,
3169            "support. Without it, we can't help you.            - DevTeam");
3170    log_msg(0,
3171            "------------------------------------------------------------");
3172    log_msg(0,
3173            "BTW, despite (or perhaps because of) the wealth of messages,");
3174    log_msg(0,
3175            "some users are inclined to stop reading this log.  If Mondo ");
3176    log_msg(0,
3177            "stopped for some reason, chances are it's detailed here.    ");
3178    log_msg(0,
3179            "More than likely there's a message at the very end of this  ");
3180    log_msg(0,
3181            "log that will tell you what is wrong.  Please read it!      ");
3182    log_msg(0,
3183            "------------------------------------------------------------");
3184}
3185
3186
3187
3188/**
3189 * Restore the user's data.
3190 * What did you think it did, anyway? :-)
3191 */
3192int main(int argc, char *argv[])
3193{
3194    FILE *fin;
3195    FILE *fout;
3196    int retval = 0;
3197    int res;
3198//  int c;
3199    char *tmp;
3200
3201    struct mountlist_itself *mountlist;
3202    struct raidlist_itself *raidlist;
3203    struct s_bkpinfo *bkpinfo;
3204    struct s_node *filelist;
3205    char *a, *b;
3206    bool run_postnuke = FALSE;
3207
3208  /**************************************************************************
3209   * hugo-                                                                  *
3210   * busy stuff here - it needs some comments -stan                           *
3211   *                                                                        *
3212   **************************************************************************/
3213    if (getuid() != 0) {
3214        fprintf(stderr, "Please run as root.\r\n");
3215        exit(127);
3216    }
3217
3218    g_loglevel = DEFAULT_MR_LOGLEVEL;
3219    malloc_string(tmp);
3220
3221/* Configure global variables */
3222#ifdef __FreeBSD__
3223    if (strstr
3224        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
3225         "textonly"))
3226#else
3227    if (strstr
3228        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
3229         "textonly"))
3230#endif
3231    {
3232        g_text_mode = TRUE;
3233        log_msg(1, "TEXTONLY MODE");
3234    } else {
3235        g_text_mode = FALSE;
3236    }                           // newt :-)
3237    if (!
3238        (bkpinfo = g_bkpinfo_DONTUSETHIS =
3239         malloc(sizeof(struct s_bkpinfo)))) {
3240        fatal_error("Cannot malloc bkpinfo");
3241    }
3242    if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
3243        fatal_error("Cannot malloc mountlist");
3244    }
3245    if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
3246        fatal_error("Cannot malloc raidlist");
3247    }
3248
3249    malloc_libmondo_global_strings();
3250
3251    strcpy(g_mondo_home,
3252           call_program_and_get_last_line_of_output("which mondorestore"));
3253    sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
3254    make_hole_for_dir(g_tmpfs_mountpt);
3255    g_current_media_number = 1; // precaution
3256
3257    run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
3258    run_program_and_log_output("mkdir -p /mnt/floppy", FALSE);
3259
3260    malloc_string(tmp);
3261    malloc_string(a);
3262    malloc_string(b);
3263    setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc.
3264    reset_bkpinfo(bkpinfo);
3265    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
3266    bkpinfo->restore_data = TRUE;   // Well, yeah :-)
3267    if (am_I_in_disaster_recovery_mode()) {
3268        run_program_and_log_output("mount / -o remount,rw", 2);
3269    }                           // for b0rken distros
3270    g_main_pid = getpid();
3271    srandom((int) (time(NULL)));
3272    register_pid(getpid(), "mondo");
3273    set_signals(TRUE);
3274    g_kernel_version = get_kernel_version();
3275
3276    log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
3277    if (strlen(g_mountlist_fname) < 3) {
3278        fatal_error
3279            ("Serious error in malloc()'ing. Could be a bug in your glibc.");
3280    }
3281    mkdir(MNT_CDROM, 0x770);
3282
3283/* Backup original mountlist.txt */
3284    sprintf(tmp, "%s.orig", g_mountlist_fname);
3285    if (!does_file_exist(g_mountlist_fname)) {
3286        log_msg(2,
3287                "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
3288                __LINE__, g_mountlist_fname);
3289    } else if (!does_file_exist(tmp)) {
3290        sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
3291                g_mountlist_fname);
3292        run_program_and_log_output(tmp, FALSE);
3293    }
3294
3295/* Init directories */
3296    make_hole_for_dir(bkpinfo->tmpdir);
3297    sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir);
3298    run_program_and_log_output(tmp, FALSE);
3299    make_hole_for_dir("/var/log");
3300    make_hole_for_dir("/tmp/tmpfs");    /* just in case... */
3301    run_program_and_log_output("umount " MNT_CDROM, FALSE);
3302    run_program_and_log_output
3303        ("ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log",
3304         FALSE);
3305
3306    run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
3307
3308/* Init GUI */
3309    malloc_libmondo_global_strings();
3310    setup_newt_stuff();         /* call newtInit and setup screen log */
3311    welcome_to_mondorestore();
3312    if (bkpinfo->disaster_recovery) {
3313        log_msg(1, "I am in disaster recovery mode");
3314    } else {
3315        log_msg(1, "I am in normal, live mode");
3316    }
3317
3318    iamhere("what time is it");
3319
3320/* Process command-line parameters */
3321    if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
3322#ifdef __FreeBSD__
3323        system("mv -f /tmp/raidconf.txt /etc/raidtab");
3324        if (!does_file_exist("/etc/raidtab"))
3325            system("vinum printconfig > /etc/raidtab");
3326#endif
3327        load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3328        if (!does_file_exist(g_mountlist_fname)) {
3329            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3330        }
3331        res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
3332#ifdef __FreeBSD__
3333        system("mv -f /etc/raidtab /tmp/raidconf.txt");
3334#endif
3335        paranoid_MR_finish(res);
3336    }
3337
3338    g_loglevel = DEFAULT_MR_LOGLEVEL;
3339    if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
3340        fout = fopen("/tmp/out.txt", "w");
3341        fput_string_one_char_at_a_time(stderr, argv[2]);
3342        finish(0);
3343    }
3344
3345    if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
3346        make_grub_install_scriptlet(argv[2]);
3347        finish(0);
3348    }
3349
3350    if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
3351        if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
3352            system("mount " MNT_CDROM);
3353        }
3354        bkpinfo->compression_level = 1;
3355        g_current_media_number = 2;
3356        strcpy(bkpinfo->restore_path, "/tmp/TESTING");
3357        bkpinfo->backup_media_type = dvd;
3358        open_progress_form("Reassembling /dev/hda1",
3359                           "Shark is a bit of a silly person.",
3360                           "Please wait. This may take some time.",
3361                           "", 1999);
3362        system("rm -Rf /tmp/*pih*");
3363
3364        restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
3365    }
3366
3367    if (argc == 5 && strcmp(argv[1], "--common") == 0) {
3368        g_loglevel = 6;
3369        filelist = load_filelist(argv[2]);
3370        if (!filelist) {
3371            fatal_error("Failed to load filelist");
3372        }
3373        toggle_node_selection(filelist, FALSE);
3374        toggle_all_root_dirs_on(filelist);
3375        // BERLIOS: /usr/lib ???
3376        toggle_path_selection(filelist, "/usr/share", TRUE);
3377//      show_filelist(filelist);
3378        save_filelist(filelist, "/tmp/out.txt");
3379//      finish(0);
3380//      toggle_path_selection (filelist, "/root/stuff", TRUE);
3381        strcpy(a, argv[3]);
3382        strcpy(b, argv[4]);
3383
3384        res = save_filelist_entries_in_common(a, filelist, b, FALSE);
3385        free_filelist(filelist);
3386        printf("res = %d", res);
3387        finish(0);
3388    }
3389
3390    if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
3391        popup_changelist_from_file(argv[2]);
3392        paranoid_MR_finish(0);
3393    }
3394
3395    if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
3396        log_msg(1, "SCORE");
3397        g_loglevel = 10;
3398        if (strstr(argv[2], "save")) {
3399            log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
3400            fin = fopen(argv[3], "r");
3401            fout = fopen(argv[4], "w");
3402            copy_from_src_to_dest(fin, fout, 'w');
3403            fclose(fin);
3404            fin = fopen(argv[3], "r");
3405            copy_from_src_to_dest(fin, fout, 'w');
3406            fclose(fout);
3407            fclose(fin);
3408        } else if (strstr(argv[2], "restore")) {
3409            fout = fopen(argv[3], "w");
3410            fin = fopen(argv[4], "r");
3411            copy_from_src_to_dest(fout, fin, 'r');
3412            fclose(fin);
3413            fin = fopen(argv[4], "r");
3414            copy_from_src_to_dest(fout, fin, 'r');
3415            fclose(fout);
3416            fclose(fin);
3417        } else {
3418            fatal_error("Unknown additional param");
3419        }
3420        finish(0);
3421    }
3422
3423    if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
3424        wait_until_software_raids_are_prepped(argv[2], 100);
3425        finish(0);
3426    }
3427
3428    if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
3429        finish(create_raidtab_from_mdstat(argv[2]));
3430    }
3431
3432
3433    if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
3434        retval = run_grub(FALSE, "/dev/hda");
3435        if (retval) {
3436            log_to_screen("Failed to write Master Boot Record");
3437        }
3438        paranoid_MR_finish(0);
3439    }
3440    if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
3441        g_current_media_number = atoi(argv[2]);
3442        pause_and_ask_for_cdr(5, NULL);
3443        paranoid_MR_finish(0);
3444    } else if (!bkpinfo->disaster_recovery) {   // live!
3445        if (argc != 1) {
3446            popup_and_OK
3447                ("Live mode doesn't support command-line parameters yet.");
3448            paranoid_MR_finish(1);
3449//    return(1);
3450        }
3451        log_msg(1, "I am in normal, live mode.");
3452        log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
3453        mount_boot_if_necessary();  /* for Gentoo users */
3454        log_msg(2, "Still here.");
3455        if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) {
3456            g_restoring_live_from_cd = TRUE;
3457        }
3458        if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) {
3459            retval =
3460                restore_live_from_monitas_server(bkpinfo,
3461                                                 argv[2],
3462                                                 argv[3], argv[4]);
3463        } else {
3464            log_msg(2, "Calling restore_to_live_filesystem()");
3465            retval = restore_to_live_filesystem(bkpinfo);
3466        }
3467        log_msg(2, "Still here. Yay.");
3468        if (strlen(bkpinfo->tmpdir) > 0) {
3469            sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
3470            run_program_and_log_output(tmp, FALSE);
3471        }
3472        unmount_boot_if_necessary();    /* for Gentoo users */
3473        paranoid_MR_finish(retval);
3474    } else {
3475        /* Disaster recovery mode (must be) */
3476        log_msg(1, "I must be in disaster recovery mode.");
3477        log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
3478        if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) {
3479            log_to_screen("Uh, that hasn't been implemented yet.");
3480            paranoid_MR_finish(1);
3481        }
3482
3483        iamhere("About to call load_mountlist and load_raidtab");
3484        strcpy(bkpinfo->restore_path, MNT_RESTORING);
3485        read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
3486        retval = load_mountlist(mountlist, g_mountlist_fname);
3487        retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3488        iamhere
3489            ("Returned from calling load_mountlist and load_raidtab successfully");
3490
3491        if (argc > 1
3492            && (strcmp(argv[1], "--compare") == 0
3493                || strcmp(argv[1], "--nuke") == 0)) {
3494            if (bkpinfo->backup_media_type == nfs
3495                && !is_this_device_mounted(bkpinfo->nfs_mount)) {
3496                log_msg(1, "Mounting nfs dir");
3497                sprintf(bkpinfo->isodir, "/tmp/isodir");
3498                run_program_and_log_output("mkdir -p /tmp/isodir", 5);
3499                sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir",
3500                        bkpinfo->nfs_mount);
3501                run_program_and_log_output(tmp, 1);
3502            }
3503        }
3504
3505
3506        if (retval) {
3507            log_to_screen
3508                ("Warning - load_raidtab_into_raidlist returned an error");
3509        }
3510
3511
3512        log_msg(1, "Send in the clowns.");
3513
3514        if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) {
3515            log_msg(0, "Partitioning only.");
3516            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3517            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3518            load_mountlist(mountlist, g_mountlist_fname);
3519            res = partition_everything(mountlist);
3520            finish(res);
3521        }
3522
3523        if (argc == 2 && strcmp(argv[1], "--format-only") == 0) {
3524            log_msg(0, "Formatting only.");
3525            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3526            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3527            load_mountlist(mountlist, g_mountlist_fname);
3528            res = format_everything(mountlist, FALSE, raidlist);
3529            finish(res);
3530        }
3531
3532        if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) {
3533            log_msg(0, "Stopping LVM and RAID");
3534            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3535            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3536            load_mountlist(mountlist, g_mountlist_fname);
3537            res = do_my_funky_lvm_stuff(TRUE, FALSE);
3538            res += stop_all_raid_devices(mountlist);
3539            finish(res);
3540        }
3541
3542        if (argc == 2 && strcmp(argv[1], "--nuke") == 0) {
3543            iamhere("nuking");
3544            retval += nuke_mode(bkpinfo, mountlist, raidlist);
3545        } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) {
3546            iamhere("catchall");
3547            retval += catchall_mode(bkpinfo, mountlist, raidlist);
3548        } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) {
3549            iamhere("compare");
3550            retval += compare_mode(bkpinfo, mountlist, raidlist);
3551        } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) {
3552            iamhere("iso");
3553            retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE);
3554        } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) {
3555            iamhere("mbr");
3556            retval = mount_all_devices(mountlist, TRUE);
3557            if (!retval) {
3558                retval += run_boot_loader(FALSE);
3559                retval += unmount_all_devices(mountlist);
3560            }
3561            if (retval) {
3562                log_to_screen("Failed to write Master Boot Record");
3563            }
3564        } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) {
3565            iamhere("isonuke");
3566            retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE);
3567        } else if (argc != 1) {
3568            log_to_screen("Invalid paremeters");
3569            paranoid_MR_finish(1);
3570        } else {
3571            iamhere("catchall (no mode specified in command-line call");
3572            retval += catchall_mode(bkpinfo, mountlist, raidlist);
3573        }
3574    }
3575
3576    /* clean up at the end */
3577    if (retval) {
3578        if (does_file_exist("/tmp/changed.files")) {
3579            log_to_screen
3580                ("See /tmp/changed.files for list of files that have changed.");
3581        }
3582        mvaddstr_and_log_it(g_currentY++,
3583                            0,
3584                            "Run complete. Errors were reported. Please review the logfile.");
3585    } else {
3586        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3587            mvaddstr_and_log_it(g_currentY++,
3588                                0,
3589                                "Run complete. Please remove floppy/CD/media and reboot.");
3590        } else {
3591            run_program_and_log_output("sync", FALSE);
3592            if (is_this_device_mounted(MNT_CDROM)) {
3593                res =
3594                    run_program_and_log_output("umount " MNT_CDROM, FALSE);
3595            } else {
3596                res = 0;
3597            }
3598
3599            if (!bkpinfo->please_dont_eject) {
3600                res = eject_device("/dev/cdrom");
3601/*
3602              if (res)
3603        {
3604          log_to_screen( "WARNING - failed to eject CD-ROM disk" );
3605        }
3606*/
3607            }
3608            mvaddstr_and_log_it(g_currentY++,
3609                                0,
3610                                "Run complete. Please remove media and reboot.");
3611        }
3612    }
3613
3614// g_I_have_just_nuked is set true by nuke_mode() just before it returns
3615    if (!system("which post-nuke > /dev/null 2> /dev/null")) {
3616      log_msg(1, "post-nuke found; find out whether we should run it...");
3617      if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
3618        run_postnuke = TRUE;
3619        log_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
3620      } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
3621        run_postnuke = TRUE;
3622        log_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
3623      } else {
3624        run_postnuke = FALSE;
3625        log_msg(1, "No, will not run post-nuke.");
3626      }
3627    } else {
3628      log_msg(1, "No post-nuke found.");
3629    }
3630    if (run_postnuke) {
3631      log_to_screen("Running post-nuke...");
3632      if (mount_all_devices(mountlist, TRUE)) {
3633        log_to_screen
3634          ("Unable to re-mount partitions for post-nuke stuff");
3635      } else {
3636        log_msg(1, "Re-mounted partitions for post-nuke stuff");
3637        sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
3638            retval);
3639        log_msg(2, "Calling '%s'", tmp);
3640        if ((res = run_program_and_log_output(tmp, 0))) {
3641          log_OS_error(tmp);
3642        }
3643        log_msg(1, "post-nuke returned w/ res=%d", res);
3644      }
3645      unmount_all_devices(mountlist);
3646      log_to_screen("I've finished post-nuking.");
3647    }
3648
3649/* 
3650  log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
3651  log_to_screen("Otherwise, please wait until the RAID disks are done.");
3652  wait_until_software_raids_are_prepped("/proc/mdstat", 100);
3653  log_to_screen("Thank you.");
3654*/
3655    unlink("/tmp/mondo-run-prog.tmp");
3656    set_signals(FALSE);
3657    sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
3658    run_program_and_log_output(tmp, FALSE);
3659    log_to_screen
3660        ("Restore log copied to /tmp/mondo-restore.log on your hard disk");
3661    sprintf(tmp,
3662            "Mondo-restore is exiting (retval=%d)                                      ",
3663            retval);
3664    log_to_screen(tmp);
3665    sprintf(tmp, "umount %s", bkpinfo->isodir);
3666    run_program_and_log_output(tmp, 5);
3667    paranoid_free(mountlist);
3668    paranoid_free(raidlist);
3669    if (am_I_in_disaster_recovery_mode()) {
3670        run_program_and_log_output("mount / -o remount,rw", 2);
3671    }                           // for b0rken distros
3672    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
3673    free_libmondo_global_strings(); // it's fine to have this here :) really :)
3674    paranoid_free(a);
3675    paranoid_free(b);
3676    paranoid_free(tmp);
3677
3678    unlink("/tmp/filelist.full");
3679    unlink("/tmp/filelist.full.gz");
3680
3681    exit(retval);
3682}
3683
3684/**************************************************************************
3685 *END_MAIN                                                                *
3686 **************************************************************************/
3687
3688
3689
3690
3691
3692/**************************************************************************
3693 *END_MONDO-RESTORE.C                                                     *
3694 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.