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

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

g_getfacl|attr extern in mondo-restore.c

  • Property svn:keywords set to Id
File size: 114.5 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 952 2006-11-19 10:42:27Z 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 952 2006-11-19 10:42:27Z 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
495extern char *g_getfacl;
496extern char *g_getfattr;
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        if (g_getfattr) {
2030            sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
2031                MNT_CDROM "/archives", current_tarball_number);
2032        }
2033        if (g_getfacl) {
2034            sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
2035                current_tarball_number);
2036        }
2037        if (strstr(tarball_fname, ".bz2")) {
2038            strcpy(executable, "bzip2");
2039        } else if (strstr(tarball_fname, ".lzo")) {
2040            strcpy(executable, "lzop");
2041        } else {
2042            executable[0] = '\0';
2043        }
2044        if (executable[0]) {
2045            sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
2046            if (run_program_and_log_output(tmp, FALSE)) {
2047                log_to_screen
2048                    ("(compare_a_tarball) Compression program not found - oh no!");
2049                paranoid_MR_finish(1);
2050            }
2051            strcpy(tmp, executable);
2052            sprintf(executable, "-P %s -Z", tmp);
2053        }
2054#ifdef __FreeBSD__
2055#define BUFSIZE 512
2056#else
2057#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
2058#endif
2059
2060//      if (strstr(tarball_fname, ".star."))
2061        if (use_star) {
2062            sprintf(command,
2063                    "star -x -force-remove -U " STAR_ACL_SZ
2064                    " errctl= file=%s", tarball_fname);
2065            if (strstr(tarball_fname, ".bz2")) {
2066                strcat(command, " -bz");
2067            }
2068        } else {
2069            if (filelist_subset_fname[0] != '\0') {
2070                sprintf(command,
2071                        "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
2072                        TAPE_BLOCK_SIZE,
2073                        BUFSIZE, executable, filelist_subset_fname,
2074//             files_to_restore_this_time_fname,
2075                        tarball_fname);
2076            } else {
2077                sprintf(command,
2078                        "afio -i -b %ld -c %ld -M 8m %s %s",
2079                        TAPE_BLOCK_SIZE,
2080                        BUFSIZE, executable, tarball_fname);
2081            }
2082        }
2083#undef BUFSIZE
2084        sprintf(command + strlen(command), " 2>> %s >> %s", temp_log,
2085                temp_log);
2086        log_msg(1, "command = '%s'", command);
2087        unlink(temp_log);
2088        res = system(command);
2089        if (res) {
2090            p = strstr(command, "-acl ");
2091            if (p) {
2092                p[0] = p[1] = p[2] = p[3] = ' ';
2093                log_msg(1, "new command = '%s'", command);
2094                res = system(command);
2095            }
2096        }
2097        if (res && length_of_file(temp_log) < 5) {
2098            res = 0;
2099        }
2100
2101        if (g_getfattr) {
2102            log_msg(1, "Setting fattr list %s", xattr_fname);
2103            if (length_of_file(xattr_fname) > 0) {
2104                res = set_fattr_list(filelist_subset_fname, xattr_fname);
2105                if (res) {
2106                    log_to_screen
2107                        ("Errors occurred while setting extended attributes");
2108                } else {
2109                    log_msg(1, "I set xattr OK");
2110                }
2111                retval += res;
2112            }
2113        }
2114        if (g_getfacl) {
2115            log_msg(1, "Setting acl list %s", acl_fname);
2116            if (length_of_file(acl_fname) > 0) {
2117                res = set_acl_list(filelist_subset_fname, acl_fname);
2118                if (res) {
2119                    log_to_screen
2120                        ("Errors occurred while setting access control lists");
2121                } else {
2122                    log_msg(1, "I set ACL OK");
2123                }
2124                retval += res;
2125            }
2126        }
2127        if (retval) {
2128            sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
2129            system(command);
2130            log_msg(2, "Errors occurred while processing fileset #%d",
2131                    current_tarball_number);
2132        } else {
2133            log_msg(2, "Fileset #%d processed OK", current_tarball_number);
2134        }
2135    }
2136    if (does_file_exist("/PAUSE")) {
2137        popup_and_OK
2138            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2139    }
2140    unlink(filelist_subset_fname);
2141    unlink(xattr_fname);
2142    unlink(acl_fname);
2143    unlink(temp_log);
2144
2145  leave_sub:
2146    paranoid_free(command);
2147    paranoid_free(tmp);
2148    paranoid_free(filelist_name);
2149    paranoid_free(filelist_subset_fname);
2150    paranoid_free(executable);
2151    paranoid_free(temp_log);
2152    paranoid_free(xattr_fname);
2153    paranoid_free(acl_fname);
2154    log_msg(5, "Leaving");
2155    return (retval);
2156}
2157
2158/**************************************************************************
2159 *END_RESTORE_A_TARBALL_FROM_CD                                           *
2160 **************************************************************************/
2161
2162
2163/**
2164 * Restore a tarball from the currently opened stream.
2165 * @param bkpinfo The backup information structure. Fields used:
2166 * - @c bkpinfo->backup_media_type
2167 * - @c bkpinfo->media_device
2168 * - @c bkpinfo->zip_exe
2169 * @param tarball_fname The filename of the afioball to restore.
2170 * @param current_tarball_number The number (starting from 0) of the fileset
2171 * we're restoring now.
2172 * @param filelist The node structure containing the list of files to be
2173 * restored. If no file in the afioball is in this list, afio will still be
2174 * called, but nothing will be written.
2175 * @param size The size (in @b bytes) of the afioball.
2176 * @return 0 for success, nonzero for failure.
2177 */
2178int
2179restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo,
2180                              char *tarball_fname,
2181                              long current_tarball_number,
2182                              struct s_node *filelist,
2183                              long long size, char *xattr_fname,
2184                              char *acl_fname)
2185{
2186    int retval = 0;
2187    int res = 0;
2188
2189  /** malloc add ***/
2190    char *tmp;
2191    char *command;
2192    char *afio_fname;
2193    char *filelist_fname;
2194    char *filelist_subset_fname;
2195    char *executable;
2196    long matches = 0;
2197    bool restore_this_fileset = FALSE;
2198    bool use_star;
2199
2200    assert(bkpinfo != NULL);
2201    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
2202    malloc_string(filelist_subset_fname);
2203    malloc_string(filelist_fname);
2204    malloc_string(afio_fname);
2205    malloc_string(executable);
2206    malloc_string(command);
2207    malloc_string(tmp);
2208    filelist_subset_fname[0] = '\0';
2209    /* to do it with a file... */
2210    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
2211    sprintf(tmp,
2212            "Restoring from fileset #%ld (%ld KB) on %s #%d",
2213            current_tarball_number, (long) size >> 10,
2214            media_descriptor_string(bkpinfo->backup_media_type),
2215            g_current_media_number);
2216    log_msg(2, tmp);
2217    run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
2218
2219  /****************************************************************************
2220   * Use RAMDISK's /tmp; saves time; oh wait, it's too small                  *
2221   * Well, pipe from tape to afio, then; oh wait, can't do that either: bug   *
2222   * in afio or someting; oh darn.. OK, use tmpfs :-)                         *
2223   ****************************************************************************/
2224    filelist_fname[0] = filelist_subset_fname[0] = '\0';
2225    sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
2226            current_tarball_number);
2227    sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
2228            current_tarball_number);
2229    sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
2230            bkpinfo->tmpdir, current_tarball_number);
2231//  sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
2232    res = read_file_from_stream_to_file(bkpinfo, afio_fname, size);
2233    if (strstr(tarball_fname, ".star")) {
2234        bkpinfo->use_star = TRUE;
2235    }
2236    if (res) {
2237        log_msg(1, "Warning - error reading afioball from tape");
2238    }
2239    if (bkpinfo->compression_level == 0) {
2240        executable[0] = '\0';
2241    } else {
2242        if (bkpinfo->use_star) {
2243            strcpy(executable, " -bz");
2244        } else {
2245            sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
2246        }
2247    }
2248
2249    if (!filelist)              // if unconditional restore then restore entire fileset
2250    {
2251        restore_this_fileset = TRUE;
2252    } else                      // If restoring selectively then get TOC from tarball
2253    {
2254        if (strstr(tarball_fname, ".star.")) {
2255            use_star = TRUE;
2256            sprintf(command, "star -t file=%s %s", afio_fname, executable);
2257        } else {
2258            use_star = FALSE;
2259            sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
2260                    executable, afio_fname);
2261        }
2262        sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
2263                MONDO_LOGFILE);
2264        log_msg(1, "command = %s", command);
2265        if (system(command)) {
2266            log_msg(4, "Warning - error occurred while retrieving TOC");
2267        }
2268        if ((matches =
2269             save_filelist_entries_in_common(filelist_fname, filelist,
2270                                             filelist_subset_fname,
2271                                             use_star))
2272            <= 0 || length_of_file(filelist_subset_fname) < 2) {
2273            if (length_of_file(filelist_subset_fname) < 2) {
2274                log_msg(1, "No matches found in fileset %ld",
2275                        current_tarball_number);
2276            }
2277            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
2278            log_msg(2, tmp);
2279            restore_this_fileset = FALSE;
2280        } else {
2281            log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
2282                    matches, current_tarball_number,
2283                    filelist_subset_fname);
2284            restore_this_fileset = TRUE;
2285        }
2286    }
2287
2288// Concoct the call to star/afio to restore files
2289    if (strstr(tarball_fname, ".star."))    // star
2290    {
2291        sprintf(command, "star -x file=%s %s", afio_fname, executable);
2292        if (filelist) {
2293            sprintf(command + strlen(command), " list=%s",
2294                    filelist_subset_fname);
2295        }
2296    } else                      // afio
2297    {
2298        sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
2299                executable);
2300        if (filelist) {
2301            sprintf(command + strlen(command), " -w %s",
2302                    filelist_subset_fname);
2303        }
2304        sprintf(command + strlen(command), " %s", afio_fname);
2305    }
2306    sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
2307
2308// Call if IF there are files to restore (selectively/unconditionally)
2309    if (restore_this_fileset) {
2310        log_msg(1, "Calling command='%s'", command);
2311        paranoid_system(command);
2312
2313        if (g_getfattr) {
2314            iamhere("Restoring xattr stuff");
2315            res = set_fattr_list(filelist_subset_fname, xattr_fname);
2316            if (res) {
2317                log_msg(1, "Errors occurred while setting xattr");
2318            } else {
2319                log_msg(1, "I set xattr OK");
2320            }
2321            retval += res;
2322        }
2323
2324        if (g_getfacl) {
2325            iamhere("Restoring acl stuff");
2326            res = set_acl_list(filelist_subset_fname, acl_fname);
2327            if (res) {
2328                log_msg(1, "Errors occurred while setting ACL");
2329            } else {
2330                log_msg(1, "I set ACL OK");
2331            }
2332            retval += res;
2333        }
2334
2335    } else {
2336        log_msg(1, "NOT CALLING '%s'", command);
2337    }
2338
2339    if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
2340        log_to_screen("Paused after set %ld", current_tarball_number);
2341        popup_and_OK("Pausing. Press ENTER to continue.");
2342    }
2343
2344    unlink(filelist_subset_fname);
2345    unlink(filelist_fname);
2346    unlink(afio_fname);
2347
2348    paranoid_free(filelist_subset_fname);
2349    paranoid_free(filelist_fname);
2350    paranoid_free(afio_fname);
2351    paranoid_free(command);
2352    paranoid_free(tmp);
2353    return (retval);
2354}
2355
2356/**************************************************************************
2357 *END_RESTORE_A_TARBALL_FROM_STREAM                                       *
2358 **************************************************************************/
2359
2360
2361
2362
2363/**
2364 * Restore all biggiefiles from all media in this CD backup.
2365 * The CD with the last afioball should be currently mounted.
2366 * @param bkpinfo The backup information structure. @c backup_media_type is the
2367 * only field used in this function.
2368 * @param filelist The node structure containing the list of files to be
2369 * restored. If a prospective biggiefile is not in this list, it will be ignored.
2370 * @return 0 for success, nonzero for failure.
2371 */
2372int
2373restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo,
2374                                struct s_node *filelist)
2375{
2376    int retval = 0;
2377    int res;
2378    long noof_biggiefiles, bigfileno = 0, total_slices;
2379  /** malloc **/
2380    char *tmp;
2381    bool just_changed_cds = FALSE, finished;
2382    char *xattr_fname;
2383    char *acl_fname;
2384    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
2385    char *pathname_of_last_biggie_restored;
2386    FILE *fbw = NULL;
2387
2388    malloc_string(xattr_fname);
2389    malloc_string(acl_fname);
2390    malloc_string(tmp);
2391    malloc_string(biggies_whose_EXATs_we_should_set);
2392    malloc_string(pathname_of_last_biggie_restored);
2393    assert(bkpinfo != NULL);
2394
2395    sprintf(biggies_whose_EXATs_we_should_set,
2396            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2397    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2398        log_msg(1, "Warning - cannot openout %s",
2399                biggies_whose_EXATs_we_should_set);
2400    }
2401
2402    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2403    total_slices = atol(tmp);
2404    sprintf(tmp, "Reassembling large files      ");
2405    mvaddstr_and_log_it(g_currentY, 0, tmp);
2406    if (length_of_file(BIGGIELIST) < 6) {
2407        log_msg(1, "OK, no biggielist; not restoring biggiefiles");
2408        return (0);
2409    }
2410    noof_biggiefiles = count_lines_in_file(BIGGIELIST);
2411    if (noof_biggiefiles <= 0) {
2412        log_msg(2,
2413                "OK, no biggiefiles in biggielist; not restoring biggiefiles");
2414        return (0);
2415    }
2416    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2417            noof_biggiefiles);
2418    log_msg(2, tmp);
2419
2420    open_progress_form("Reassembling large files",
2421                       "I am now reassembling all the large files.",
2422                       "Please wait. This may take some time.",
2423                       "", total_slices);
2424    for (bigfileno = 0, finished = FALSE; !finished;) {
2425        log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
2426        if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
2427            log_msg(3,
2428                    "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
2429            log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
2430                    bigfileno + 1,
2431                    media_descriptor_string(bkpinfo->backup_media_type),
2432                    g_current_media_number);
2433            log_msg(3, "Slicename would have been %s",
2434                    slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, ""));
2435            // I'm not positive 'just_changed_cds' is even necessary...
2436            if (just_changed_cds) {
2437                just_changed_cds = FALSE;
2438                log_msg(3,
2439                        "I'll continue to scan this CD for bigfiles to be restored.");
2440            } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
2441                insist_on_this_cd_number(bkpinfo,
2442                                         ++g_current_media_number);
2443                sprintf(tmp, "Restoring from %s #%d",
2444                        media_descriptor_string(bkpinfo->
2445                                                backup_media_type),
2446                        g_current_media_number);
2447                log_to_screen(tmp);
2448                just_changed_cds = TRUE;
2449            } else {
2450                log_msg(2, "There was no bigfile #%ld. That's OK.",
2451                        bigfileno + 1);
2452                log_msg(2, "I'm going to stop restoring bigfiles now.");
2453                finished = TRUE;
2454            }
2455        } else {
2456            just_changed_cds = FALSE;
2457            sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
2458            update_progress_form(tmp);
2459            res =
2460                restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist,
2461                                             pathname_of_last_biggie_restored);
2462            iamhere(pathname_of_last_biggie_restored);
2463            if (fbw && pathname_of_last_biggie_restored[0]) {
2464                fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2465            }
2466            retval += res;
2467            bigfileno++;
2468
2469        }
2470    }
2471
2472    if (fbw) {
2473        fclose(fbw);
2474        if (g_getfattr) {
2475            sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2476            if (length_of_file(xattr_fname) > 0) {
2477                set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2478            }
2479        }
2480        if (g_getfacl) {
2481            sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2482            if (length_of_file(acl_fname) > 0) {
2483                set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2484            }
2485        }
2486    }
2487    if (does_file_exist("/PAUSE")) {
2488        popup_and_OK
2489            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2490    }
2491    close_progress_form();
2492    if (retval) {
2493        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2494    } else {
2495        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2496    }
2497    paranoid_free(xattr_fname);
2498    paranoid_free(acl_fname);
2499    paranoid_free(tmp);
2500    paranoid_free(biggies_whose_EXATs_we_should_set);
2501    paranoid_free(pathname_of_last_biggie_restored);
2502    return (retval);
2503}
2504
2505/**************************************************************************
2506 *END_RESTORE_ALL_BIGGIFILES_FROM_CD                                      *
2507 **************************************************************************/
2508
2509
2510
2511/**
2512 * Restore all afioballs from all CDs in the backup.
2513 * The first CD should be inserted (if not, it will be asked for).
2514 * @param bkpinfo The backup information structure. @c backup_media_type is the
2515 * only field used in @e this function.
2516 * @param filelist The node structure containing the list of files to be
2517 * restored. If no file in some particular afioball is in this list, afio will
2518 * still be called for that fileset, but nothing will be written.
2519 * @return 0 for success, or the number of filesets that failed.
2520 */
2521int
2522restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo,
2523                             struct s_node *filelist)
2524{
2525    int retval = 0;
2526    int res;
2527    int attempts;
2528    long current_tarball_number = 0;
2529    long max_val;
2530  /**malloc ***/
2531    char *tmp;
2532    char *tarball_fname;
2533    char *progress_str;
2534    char *comment;
2535
2536    malloc_string(tmp);
2537    malloc_string(tarball_fname);
2538    malloc_string(progress_str);
2539    malloc_string(comment);
2540
2541    assert(bkpinfo != NULL);
2542
2543    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2544    log_msg(2,
2545            "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
2546    if (g_current_media_number != 1) {
2547        log_msg(3, "OK, that's jacked up.");
2548        g_current_media_number = 1;
2549    }
2550    insist_on_this_cd_number(bkpinfo, g_current_media_number);
2551    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2552    max_val = atol(tmp) + 1;
2553    sprintf(progress_str, "Restoring from %s #%d",
2554            media_descriptor_string(bkpinfo->backup_media_type),
2555            g_current_media_number);
2556    log_to_screen(progress_str);
2557    open_progress_form("Restoring from archives",
2558                       "Restoring data from the archives.",
2559                       "Please wait. This may take some time.",
2560                       progress_str, max_val);
2561    for (;;) {
2562        insist_on_this_cd_number(bkpinfo, g_current_media_number);
2563        update_progress_form(progress_str);
2564        sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
2565                current_tarball_number);
2566        if (!does_file_exist(tarball_fname)) {
2567            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
2568                    current_tarball_number);
2569        }
2570        if (!does_file_exist(tarball_fname)) {
2571            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
2572                    current_tarball_number);
2573        }
2574        if (!does_file_exist(tarball_fname)) {
2575            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
2576                    current_tarball_number);
2577        }
2578        if (!does_file_exist(tarball_fname)) {
2579            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
2580                    current_tarball_number);
2581        }
2582        if (!does_file_exist(tarball_fname)) {
2583            if (current_tarball_number == 0) {
2584                log_to_screen
2585                    ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
2586                return (0);
2587            }
2588            if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2589                || system("find " MNT_CDROM
2590                          "/archives/slice* > /dev/null 2> /dev/null") ==
2591                0) {
2592                break;
2593            }
2594            g_current_media_number++;
2595            sprintf(progress_str, "Restoring from %s #%d",
2596                    media_descriptor_string(bkpinfo->backup_media_type),
2597                    g_current_media_number);
2598            log_to_screen(progress_str);
2599        } else {
2600            sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
2601                    current_tarball_number,
2602                    media_descriptor_string(bkpinfo->backup_media_type),
2603                    g_current_media_number);
2604//    log_msg(3, "progress_str = %s", progress_str);
2605            for (res = 999, attempts = 0; attempts < 3 && res != 0;
2606                 attempts++) {
2607                res =
2608                    restore_a_tarball_from_CD(tarball_fname,
2609                                              current_tarball_number,
2610                                              filelist);
2611            }
2612            sprintf(tmp, "%s #%d, fileset #%ld - restore ",
2613                    media_descriptor_string(bkpinfo->backup_media_type),
2614                    g_current_media_number, current_tarball_number);
2615            if (res) {
2616                strcat(tmp, "reported errors");
2617            } else if (attempts > 1) {
2618                strcat(tmp, "succeeded");
2619            } else {
2620                strcat(tmp, "succeeded");
2621            }
2622            if (attempts > 1) {
2623                sprintf(tmp + strlen(tmp), " (%d attempts) - review logs",
2624                        attempts);
2625            }
2626            strcpy(comment, tmp);
2627            if (attempts > 1) {
2628                log_to_screen(comment);
2629            }
2630
2631            retval += res;
2632            current_tarball_number++;
2633            g_current_progress++;
2634        }
2635    }
2636    close_progress_form();
2637    if (retval) {
2638        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2639    } else {
2640        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2641    }
2642    paranoid_free(tmp);
2643    paranoid_free(tarball_fname);
2644    paranoid_free(progress_str);
2645    paranoid_free(comment);
2646
2647    return (retval);
2648}
2649
2650/**************************************************************************
2651 *END_RESTORE_ALL_TARBALLS_FROM_CD                                        *
2652 **************************************************************************/
2653
2654
2655
2656/**
2657 * Restore all biggiefiles from the currently opened stream.
2658 * @param bkpinfo The backup information structure. Passed to other functions.
2659 * @param filelist The node structure containing the list of files to be
2660 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2661 * @return 0 for success, or the number of biggiefiles that failed.
2662 */
2663int
2664restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo,
2665                                    struct s_node *filelist)
2666{
2667    long noof_biggiefiles;
2668    long current_bigfile_number = 0;
2669    long total_slices;
2670
2671    int retval = 0;
2672    int res = 0;
2673    int ctrl_chr;
2674
2675  /** malloc add ****/
2676    char *tmp;
2677    char *biggie_fname;
2678    char *biggie_cksum;
2679    char *xattr_fname;
2680    char *acl_fname;
2681    char *p;
2682    char *pathname_of_last_biggie_restored;
2683    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
2684    long long biggie_size;
2685    FILE *fbw = NULL;
2686
2687    malloc_string(tmp);
2688    malloc_string(biggie_fname);
2689    malloc_string(biggie_cksum);
2690    malloc_string(xattr_fname);
2691    malloc_string(acl_fname);
2692    malloc_string(biggies_whose_EXATs_we_should_set);
2693    malloc_string(pathname_of_last_biggie_restored);
2694    assert(bkpinfo != NULL);
2695
2696    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2697
2698    total_slices = atol(tmp);
2699    sprintf(tmp, "Reassembling large files      ");
2700    if (g_getfattr) {
2701        sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2702    }
2703    if (g_getfacl) {
2704        sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2705    }
2706    mvaddstr_and_log_it(g_currentY, 0, tmp);
2707    sprintf(biggies_whose_EXATs_we_should_set,
2708            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2709    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2710        log_msg(1, "Warning - cannot openout %s",
2711                biggies_whose_EXATs_we_should_set);
2712    }
2713// get xattr and acl files if they're there
2714    res =
2715        read_header_block_from_stream(&biggie_size, biggie_fname,
2716                                      &ctrl_chr);
2717    if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2718        res =
2719            read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname,
2720                                      &ctrl_chr, xattr_fname, acl_fname);
2721    }
2722
2723    noof_biggiefiles = atol(biggie_fname);
2724    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2725            noof_biggiefiles);
2726    log_msg(2, tmp);
2727    open_progress_form("Reassembling large files",
2728                       "I am now reassembling all the large files.",
2729                       "Please wait. This may take some time.",
2730                       "", total_slices);
2731
2732    for (res =
2733         read_header_block_from_stream(&biggie_size, biggie_fname,
2734                                       &ctrl_chr);
2735         ctrl_chr != BLK_STOP_BIGGIEFILES;
2736         res =
2737         read_header_block_from_stream(&biggie_size, biggie_fname,
2738                                       &ctrl_chr)) {
2739        if (ctrl_chr != BLK_START_A_NORMBIGGIE
2740            && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2741            wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2742        }
2743        p = strrchr(biggie_fname, '/');
2744        if (!p) {
2745            p = biggie_fname;
2746        } else {
2747            p++;
2748        }
2749        sprintf(tmp, "Restoring big file %ld (%lld K)",
2750                current_bigfile_number + 1, biggie_size / 1024);
2751        update_progress_form(tmp);
2752        res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
2753                                               current_bigfile_number,
2754                                               biggie_cksum,
2755                                               biggie_size,
2756                                               filelist, ctrl_chr,
2757                                               pathname_of_last_biggie_restored);
2758        log_msg(1, "I believe I have restored %s",
2759                pathname_of_last_biggie_restored);
2760        if (fbw && pathname_of_last_biggie_restored[0]) {
2761            fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2762        }
2763        retval += res;
2764        current_bigfile_number++;
2765
2766    }
2767    if (current_bigfile_number != noof_biggiefiles
2768        && noof_biggiefiles != 0) {
2769        sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
2770                current_bigfile_number, noof_biggiefiles);
2771    } else {
2772        sprintf(tmp,
2773                "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
2774                noof_biggiefiles, current_bigfile_number);
2775    }
2776    log_msg(1, tmp);
2777
2778    if (fbw) {
2779        fclose(fbw);
2780        if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
2781            iamhere("Setting biggie-EXATs");
2782            if (g_getfattr) {
2783                if (length_of_file(xattr_fname) > 0) {
2784                    log_msg(1, "set_fattr_List(%s,%s)",
2785                        biggies_whose_EXATs_we_should_set, xattr_fname);
2786                    set_fattr_list(biggies_whose_EXATs_we_should_set,
2787                               xattr_fname);
2788                }
2789            }
2790            if (g_getfacl) {
2791                if (length_of_file(acl_fname) > 0) {
2792                    log_msg(1, "set_acl_list(%s,%s)",
2793                            biggies_whose_EXATs_we_should_set, acl_fname);
2794                    set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2795                }
2796            }
2797        } else {
2798            iamhere
2799                ("No biggiefiles selected. So, no biggie-EXATs to set.");
2800        }
2801    }
2802    if (does_file_exist("/PAUSE")) {
2803        popup_and_OK
2804            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2805    }
2806
2807    close_progress_form();
2808    if (retval) {
2809        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2810    } else {
2811        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2812    }
2813    paranoid_free(biggies_whose_EXATs_we_should_set);
2814    paranoid_free(pathname_of_last_biggie_restored);
2815    paranoid_free(biggie_fname);
2816    paranoid_free(biggie_cksum);
2817    paranoid_free(xattr_fname);
2818    paranoid_free(acl_fname);
2819    paranoid_free(tmp);
2820    return (retval);
2821}
2822
2823/**************************************************************************
2824 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM                                 *
2825 **************************************************************************/
2826
2827
2828
2829
2830
2831
2832/**
2833 * Restore all afioballs from the currently opened tape stream.
2834 * @param bkpinfo The backup information structure. Fields used:
2835 * - @c bkpinfo->backup_media_type
2836 * - @c bkpinfo->restore_path
2837 * @param filelist The node structure containing the list of files to be
2838 * restored. If no file in an afioball is in this list, afio will still be
2839 * called for that fileset, but nothing will be written.
2840 * @return 0 for success, or the number of filesets that failed.
2841 */
2842int
2843restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo,
2844                                 struct s_node *filelist)
2845{
2846    int retval = 0;
2847    int res;
2848    long current_afioball_number = 0;
2849    int ctrl_chr;
2850    long max_val /*, total_noof_files */ ;
2851
2852  /** malloc **/
2853    char *tmp;
2854    char *progress_str;
2855    char *tmp_fname;
2856    char *xattr_fname;
2857    char *acl_fname;
2858
2859    long long tmp_size;
2860
2861    malloc_string(tmp);
2862    malloc_string(progress_str);
2863    malloc_string(tmp_fname);
2864    assert(bkpinfo != NULL);
2865    malloc_string(xattr_fname);
2866    malloc_string(acl_fname);
2867    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2868    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2869    max_val = atol(tmp) + 1;
2870
2871    chdir(bkpinfo->restore_path);   /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
2872
2873    run_program_and_log_output("pwd", 5);
2874
2875    sprintf(progress_str, "Restoring from media #%d",
2876            g_current_media_number);
2877    log_to_screen(progress_str);
2878    open_progress_form("Restoring from archives",
2879                       "Restoring data from the archives.",
2880                       "Please wait. This may take some time.",
2881                       progress_str, max_val);
2882
2883    log_msg(3, "hey");
2884
2885    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2886    if (res) {
2887        log_msg(2, "Warning - error reading afioball from tape");
2888    }
2889    retval += res;
2890    if (ctrl_chr != BLK_START_AFIOBALLS) {
2891        wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
2892    }
2893    log_msg(2, "ho");
2894    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2895    while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2896        update_progress_form(progress_str);
2897        if (g_getfattr) {
2898            sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
2899                current_afioball_number);
2900            unlink(xattr_fname);
2901        }
2902        if (g_getfacl) {
2903            sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
2904                current_afioball_number);
2905            unlink(acl_fname);
2906        }
2907        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2908            iamhere("Reading EXAT files from tape");
2909            res =
2910                read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname,
2911                                          &ctrl_chr, xattr_fname,
2912                                          acl_fname);
2913        }
2914        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2915            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2916        }
2917        sprintf(tmp,
2918                "Restoring from fileset #%ld (name=%s, size=%ld K)",
2919                current_afioball_number, tmp_fname, (long) tmp_size >> 10);
2920        res =
2921            restore_a_tarball_from_stream(bkpinfo, tmp_fname,
2922                                          current_afioball_number,
2923                                          filelist, tmp_size, xattr_fname,
2924                                          acl_fname);
2925        retval += res;
2926        if (res) {
2927            sprintf(tmp, "Fileset %ld - errors occurred",
2928                    current_afioball_number);
2929            log_to_screen(tmp);
2930        }
2931        res =
2932            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2933        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2934            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2935        }
2936
2937        current_afioball_number++;
2938        g_current_progress++;
2939        sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
2940                current_afioball_number,
2941                media_descriptor_string(bkpinfo->backup_media_type),
2942                g_current_media_number);
2943        res =
2944            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2945        if (g_getfattr) {
2946            unlink(xattr_fname);
2947        }
2948        if (g_getfacl) {
2949            unlink(acl_fname);
2950        }
2951    }                           // next
2952    log_msg(1, "All done with afioballs");
2953    close_progress_form();
2954    if (retval) {
2955        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2956    } else {
2957        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2958    }
2959    paranoid_free(tmp);
2960    paranoid_free(progress_str);
2961    paranoid_free(tmp_fname);
2962    paranoid_free(xattr_fname);
2963    paranoid_free(acl_fname);
2964    return (retval);
2965}
2966
2967/**************************************************************************
2968 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM                                   *
2969 **************************************************************************/
2970
2971/* @} - end of LLrestoreGroup */
2972
2973
2974/**
2975 * Restore all files in @p filelist.
2976 * @param bkpinfo The backup information structure. Most fields are used.
2977 * @param filelist The node structure containing the list of files to be
2978 * restored.
2979 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2980 * @ingroup restoreGroup
2981 */
2982int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
2983{
2984    int resA;
2985    int resB;
2986
2987  /** mallco ***/
2988    char *cwd;
2989    char *newpath;
2990    char *tmp;
2991    assert(bkpinfo != NULL);
2992
2993    malloc_string(cwd);
2994    malloc_string(newpath);
2995    malloc_string(tmp);
2996    log_msg(2, "restore_everything() --- starting");
2997    g_current_media_number = 1;
2998    getcwd(cwd, MAX_STR_LEN - 1);
2999    sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
3000    run_program_and_log_output(tmp, FALSE);
3001    log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
3002    chdir(bkpinfo->restore_path);
3003    getcwd(newpath, MAX_STR_LEN - 1);
3004    log_msg(1, "path is now %s", newpath);
3005    log_msg(1, "restoring everything");
3006    if (!find_home_of_exe("petris") && !g_text_mode) {
3007        newtDrawRootText(0, g_noof_rows - 2,
3008                         "Press ALT-<left cursor> twice to play Petris :-) ");
3009        newtRefresh();
3010    }
3011    mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
3012    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3013        mount_cdrom(bkpinfo);
3014        mvaddstr_and_log_it(g_currentY++, 0,
3015                            "Restoring OS and data from streaming media");
3016        if (bkpinfo->backup_media_type == cdstream) {
3017            openin_cdstream(bkpinfo);
3018        } else {
3019            assert_string_is_neither_NULL_nor_zerolength(bkpinfo->
3020                                                         media_device);
3021            openin_tape(bkpinfo);
3022        }
3023        resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
3024        resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
3025        if (bkpinfo->backup_media_type == cdstream) {
3026            closein_cdstream(bkpinfo);
3027        } else {
3028            closein_tape(bkpinfo);
3029        }
3030    } else {
3031        mvaddstr_and_log_it(g_currentY++, 0,
3032                            "Restoring OS and data from CD       ");
3033        mount_cdrom(bkpinfo);
3034        resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
3035        resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
3036    }
3037    chdir(cwd);
3038    if (resA + resB) {
3039        log_to_screen("Errors occurred while data was being restored.");
3040    }
3041    if (length_of_file("/etc/raidtab") > 0) {
3042        log_msg(2, "Copying local raidtab to restored filesystem");
3043        run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
3044                                   "/etc/raidtab", FALSE);
3045    }
3046    kill_petris();
3047    log_msg(2, "restore_everything() --- leaving");
3048    paranoid_free(cwd);
3049    paranoid_free(newpath);
3050    paranoid_free(tmp);
3051    return (resA + resB);
3052}
3053
3054/**************************************************************************
3055 *END_RESTORE_EVERYTHING                                                  *
3056 **************************************************************************/
3057
3058
3059
3060/**
3061 * @brief Haha. You wish! (This function is not implemented :-)
3062 */
3063int
3064restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,
3065                                 char *monitas_device,
3066                                 char *restore_this_directory,
3067                                 char *restore_here)
3068     /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
3069{
3070    FILE *fout;
3071    int retval = 0;
3072    int i;
3073    int j;
3074    struct mountlist_itself the_mountlist;
3075    static struct raidlist_itself the_raidlist;
3076  /** malloc **/
3077    char tmp[MAX_STR_LEN + 1];
3078    char command[MAX_STR_LEN + 1];
3079    char datablock[256 * 1024];
3080    char datadisks_fname[MAX_STR_LEN + 1];
3081    long k;
3082    long length;
3083    long long llt;
3084    struct s_node *filelist = NULL;
3085    assert(bkpinfo != NULL);
3086    assert_string_is_neither_NULL_nor_zerolength(monitas_device);
3087    assert(restore_this_directory != NULL);
3088    assert(restore_here != NULL);
3089
3090    sprintf(tmp, "restore_here = '%s'", restore_here);
3091
3092    log_msg(2, tmp);
3093
3094    log_msg(2, "restore_live_from_monitas_server() - starting");
3095    unlink("/tmp/mountlist.txt");
3096    unlink("/tmp/filelist.full");
3097    unlink("/tmp/biggielist.txt");
3098    if (restore_here[0] == '\0') {
3099        strcpy(bkpinfo->restore_path, MNT_RESTORING);
3100    } else {
3101        strcpy(bkpinfo->restore_path, restore_here);
3102    }
3103    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
3104    sprintf(tmp, "FYI - data will be restored to %s",
3105            bkpinfo->restore_path);
3106    log_msg(3, tmp);
3107    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
3108    sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
3109            (int) (random() % 32768));
3110    chdir(bkpinfo->tmpdir);
3111
3112    sprintf(command, "cat %s", monitas_device);
3113    g_tape_stream = popen(command, "r");    // for compatibility with openin_tape()
3114    if (!(fout = fopen(datadisks_fname, "w"))) {
3115        log_OS_error(datadisks_fname);
3116        return (1);
3117    }
3118    for (i = 0; i < 32; i++) {
3119        for (j = 0; j < 4; j++) {
3120            for (length = k = 0; length < 256 * 1024; length += k) {
3121                k = fread(datablock + length, 1, 256 * 1024 - length,
3122                          g_tape_stream);
3123            }
3124            fwrite(datablock, 1, length, fout);
3125            g_tape_posK += length;
3126        }
3127    }
3128    paranoid_fclose(fout);
3129    sprintf(command,
3130            "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
3131            datadisks_fname);
3132    run_program_and_log_output(command, 4);
3133    read_header_block_from_stream(&llt, tmp, &i);
3134    read_header_block_from_stream(&llt, tmp, &i);
3135
3136    unlink(datadisks_fname);
3137    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
3138    retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo   strcpy(bkpinfo->media_device, monitas_device);
3139
3140
3141    load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);
3142    iamhere("FIXME");
3143    fatal_error("This will fail");
3144    sprintf(command,
3145            "grep -E '^%s.*$' %s > %s",
3146            restore_this_directory, g_filelist_full, g_filelist_full);
3147    if (system(command)) {
3148        retval++;
3149        log_to_screen
3150            ("Error(s) occurred while processing filelist and wildcard");
3151    }
3152    iamhere("FIXME");
3153    fatal_error("This will fail");
3154    sprintf(command,
3155            "grep -E '^%s.*$' %s > %s",
3156            restore_this_directory, g_biggielist_txt, g_biggielist_txt);
3157    if (system(command)) {
3158        log_msg(1,
3159                "Error(s) occurred while processing biggielist and wildcard");
3160    }
3161    sprintf(command, "touch %s", g_biggielist_txt);
3162    run_program_and_log_output(command, FALSE);
3163//  filelist = load_filelist(g_filelist_restthese);  // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
3164    retval += restore_everything(bkpinfo, filelist);
3165    free_filelist(filelist);
3166    log_msg(2, "--------End of restore_live_from_monitas_server--------");
3167    return (retval);
3168}
3169
3170/**************************************************************************
3171 *END_RESTORE_LIVE_FROM_MONITAS_SERVER                                    *
3172 **************************************************************************/
3173
3174
3175
3176
3177extern void wait_until_software_raids_are_prepped(char *, int);
3178
3179
3180char which_restore_mode(void);
3181
3182
3183/**
3184 * Log a "don't panic" message to the logfile.
3185 */
3186void welcome_to_mondorestore()
3187{
3188    log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
3189    log_msg(0,
3190            "DON'T PANIC! Mondorestore logs almost everything, so please ");
3191    log_msg(0,
3192            "don't break out in a cold sweat just because you see a few  ");
3193    log_msg(0,
3194            "error messages in the log. Read them; analyze them; see if  ");
3195    log_msg(0,
3196            "they are significant; above all, verify your backups! Please");
3197    log_msg(0,
3198            "attach a compressed copy of this log to any e-mail you send ");
3199    log_msg(0,
3200            "to the Mondo mailing list when you are seeking technical    ");
3201    log_msg(0,
3202            "support. Without it, we can't help you.            - DevTeam");
3203    log_msg(0,
3204            "------------------------------------------------------------");
3205    log_msg(0,
3206            "BTW, despite (or perhaps because of) the wealth of messages,");
3207    log_msg(0,
3208            "some users are inclined to stop reading this log.  If Mondo ");
3209    log_msg(0,
3210            "stopped for some reason, chances are it's detailed here.    ");
3211    log_msg(0,
3212            "More than likely there's a message at the very end of this  ");
3213    log_msg(0,
3214            "log that will tell you what is wrong.  Please read it!      ");
3215    log_msg(0,
3216            "------------------------------------------------------------");
3217}
3218
3219
3220
3221/**
3222 * Restore the user's data.
3223 * What did you think it did, anyway? :-)
3224 */
3225int main(int argc, char *argv[])
3226{
3227    FILE *fin;
3228    FILE *fout;
3229    int retval = 0;
3230    int res;
3231//  int c;
3232    char *tmp;
3233
3234    struct mountlist_itself *mountlist;
3235    struct raidlist_itself *raidlist;
3236    struct s_bkpinfo *bkpinfo;
3237    struct s_node *filelist;
3238    char *a, *b;
3239    bool run_postnuke = FALSE;
3240
3241  /**************************************************************************
3242   * hugo-                                                                  *
3243   * busy stuff here - it needs some comments -stan                           *
3244   *                                                                        *
3245   **************************************************************************/
3246    if (getuid() != 0) {
3247        fprintf(stderr, "Please run as root.\r\n");
3248        exit(127);
3249    }
3250
3251    g_loglevel = DEFAULT_MR_LOGLEVEL;
3252    malloc_string(tmp);
3253
3254/* Configure global variables */
3255#ifdef __FreeBSD__
3256    if (strstr
3257        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
3258         "textonly"))
3259#else
3260    if (strstr
3261        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
3262         "textonly"))
3263#endif
3264    {
3265        g_text_mode = TRUE;
3266        log_msg(1, "TEXTONLY MODE");
3267    } else {
3268        g_text_mode = FALSE;
3269    }                           // newt :-)
3270    if (!
3271        (bkpinfo = g_bkpinfo_DONTUSETHIS =
3272         malloc(sizeof(struct s_bkpinfo)))) {
3273        fatal_error("Cannot malloc bkpinfo");
3274    }
3275    if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
3276        fatal_error("Cannot malloc mountlist");
3277    }
3278    if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
3279        fatal_error("Cannot malloc raidlist");
3280    }
3281
3282    malloc_libmondo_global_strings();
3283
3284    strcpy(g_mondo_home,
3285           call_program_and_get_last_line_of_output("which mondorestore"));
3286    sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
3287    make_hole_for_dir(g_tmpfs_mountpt);
3288    g_current_media_number = 1; // precaution
3289
3290    run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
3291    run_program_and_log_output("mkdir -p /mnt/floppy", FALSE);
3292
3293    malloc_string(tmp);
3294    malloc_string(a);
3295    malloc_string(b);
3296    setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc.
3297    reset_bkpinfo(bkpinfo);
3298    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
3299    bkpinfo->restore_data = TRUE;   // Well, yeah :-)
3300    if (am_I_in_disaster_recovery_mode()) {
3301        run_program_and_log_output("mount / -o remount,rw", 2);
3302    }                           // for b0rken distros
3303    g_main_pid = getpid();
3304    srandom((int) (time(NULL)));
3305    register_pid(getpid(), "mondo");
3306    set_signals(TRUE);
3307    g_kernel_version = get_kernel_version();
3308
3309    log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
3310    if (strlen(g_mountlist_fname) < 3) {
3311        fatal_error
3312            ("Serious error in malloc()'ing. Could be a bug in your glibc.");
3313    }
3314    mkdir(MNT_CDROM, 0x770);
3315
3316/* Backup original mountlist.txt */
3317    sprintf(tmp, "%s.orig", g_mountlist_fname);
3318    if (!does_file_exist(g_mountlist_fname)) {
3319        log_msg(2,
3320                "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
3321                __LINE__, g_mountlist_fname);
3322    } else if (!does_file_exist(tmp)) {
3323        sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
3324                g_mountlist_fname);
3325        run_program_and_log_output(tmp, FALSE);
3326    }
3327
3328/* Init directories */
3329    make_hole_for_dir(bkpinfo->tmpdir);
3330    sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir);
3331    run_program_and_log_output(tmp, FALSE);
3332    make_hole_for_dir("/var/log");
3333    make_hole_for_dir("/tmp/tmpfs");    /* just in case... */
3334    run_program_and_log_output("umount " MNT_CDROM, FALSE);
3335    run_program_and_log_output
3336        ("ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log",
3337         FALSE);
3338
3339    run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
3340
3341/* Init GUI */
3342    malloc_libmondo_global_strings();
3343    setup_newt_stuff();         /* call newtInit and setup screen log */
3344    welcome_to_mondorestore();
3345    if (bkpinfo->disaster_recovery) {
3346        log_msg(1, "I am in disaster recovery mode");
3347    } else {
3348        log_msg(1, "I am in normal, live mode");
3349    }
3350
3351    iamhere("what time is it");
3352
3353/* Process command-line parameters */
3354    if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
3355#ifdef __FreeBSD__
3356        system("mv -f /tmp/raidconf.txt /etc/raidtab");
3357        if (!does_file_exist("/etc/raidtab"))
3358            system("vinum printconfig > /etc/raidtab");
3359#endif
3360        load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3361        if (!does_file_exist(g_mountlist_fname)) {
3362            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3363        }
3364        res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
3365#ifdef __FreeBSD__
3366        system("mv -f /etc/raidtab /tmp/raidconf.txt");
3367#endif
3368        paranoid_MR_finish(res);
3369    }
3370
3371    g_loglevel = DEFAULT_MR_LOGLEVEL;
3372    if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
3373        fout = fopen("/tmp/out.txt", "w");
3374        fput_string_one_char_at_a_time(stderr, argv[2]);
3375        finish(0);
3376    }
3377
3378    if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
3379        make_grub_install_scriptlet(argv[2]);
3380        finish(0);
3381    }
3382
3383    if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
3384        if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
3385            system("mount " MNT_CDROM);
3386        }
3387        bkpinfo->compression_level = 1;
3388        g_current_media_number = 2;
3389        strcpy(bkpinfo->restore_path, "/tmp/TESTING");
3390        bkpinfo->backup_media_type = dvd;
3391        open_progress_form("Reassembling /dev/hda1",
3392                           "Shark is a bit of a silly person.",
3393                           "Please wait. This may take some time.",
3394                           "", 1999);
3395        system("rm -Rf /tmp/*pih*");
3396
3397        restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
3398    }
3399
3400    if (argc == 5 && strcmp(argv[1], "--common") == 0) {
3401        g_loglevel = 6;
3402        filelist = load_filelist(argv[2]);
3403        if (!filelist) {
3404            fatal_error("Failed to load filelist");
3405        }
3406        toggle_node_selection(filelist, FALSE);
3407        toggle_all_root_dirs_on(filelist);
3408        // BERLIOS: /usr/lib ???
3409        toggle_path_selection(filelist, "/usr/share", TRUE);
3410//      show_filelist(filelist);
3411        save_filelist(filelist, "/tmp/out.txt");
3412//      finish(0);
3413//      toggle_path_selection (filelist, "/root/stuff", TRUE);
3414        strcpy(a, argv[3]);
3415        strcpy(b, argv[4]);
3416
3417        res = save_filelist_entries_in_common(a, filelist, b, FALSE);
3418        free_filelist(filelist);
3419        printf("res = %d", res);
3420        finish(0);
3421    }
3422
3423    if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
3424        popup_changelist_from_file(argv[2]);
3425        paranoid_MR_finish(0);
3426    }
3427
3428    if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
3429        log_msg(1, "SCORE");
3430        g_loglevel = 10;
3431        if (strstr(argv[2], "save")) {
3432            log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
3433            fin = fopen(argv[3], "r");
3434            fout = fopen(argv[4], "w");
3435            copy_from_src_to_dest(fin, fout, 'w');
3436            fclose(fin);
3437            fin = fopen(argv[3], "r");
3438            copy_from_src_to_dest(fin, fout, 'w');
3439            fclose(fout);
3440            fclose(fin);
3441        } else if (strstr(argv[2], "restore")) {
3442            fout = fopen(argv[3], "w");
3443            fin = fopen(argv[4], "r");
3444            copy_from_src_to_dest(fout, fin, 'r');
3445            fclose(fin);
3446            fin = fopen(argv[4], "r");
3447            copy_from_src_to_dest(fout, fin, 'r');
3448            fclose(fout);
3449            fclose(fin);
3450        } else {
3451            fatal_error("Unknown additional param");
3452        }
3453        finish(0);
3454    }
3455
3456    if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
3457        wait_until_software_raids_are_prepped(argv[2], 100);
3458        finish(0);
3459    }
3460
3461    if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
3462        finish(create_raidtab_from_mdstat(argv[2]));
3463    }
3464
3465
3466    if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
3467        retval = run_grub(FALSE, "/dev/hda");
3468        if (retval) {
3469            log_to_screen("Failed to write Master Boot Record");
3470        }
3471        paranoid_MR_finish(0);
3472    }
3473    if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
3474        g_current_media_number = atoi(argv[2]);
3475        pause_and_ask_for_cdr(5, NULL);
3476        paranoid_MR_finish(0);
3477    } else if (!bkpinfo->disaster_recovery) {   // live!
3478        if (argc != 1) {
3479            popup_and_OK
3480                ("Live mode doesn't support command-line parameters yet.");
3481            paranoid_MR_finish(1);
3482//    return(1);
3483        }
3484        log_msg(1, "I am in normal, live mode.");
3485        log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
3486        mount_boot_if_necessary();  /* for Gentoo users */
3487        log_msg(2, "Still here.");
3488        if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) {
3489            g_restoring_live_from_cd = TRUE;
3490        }
3491        if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) {
3492            retval =
3493                restore_live_from_monitas_server(bkpinfo,
3494                                                 argv[2],
3495                                                 argv[3], argv[4]);
3496        } else {
3497            log_msg(2, "Calling restore_to_live_filesystem()");
3498            retval = restore_to_live_filesystem(bkpinfo);
3499        }
3500        log_msg(2, "Still here. Yay.");
3501        if (strlen(bkpinfo->tmpdir) > 0) {
3502            sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
3503            run_program_and_log_output(tmp, FALSE);
3504        }
3505        unmount_boot_if_necessary();    /* for Gentoo users */
3506        paranoid_MR_finish(retval);
3507    } else {
3508        /* Disaster recovery mode (must be) */
3509        log_msg(1, "I must be in disaster recovery mode.");
3510        log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
3511        if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) {
3512            log_to_screen("Uh, that hasn't been implemented yet.");
3513            paranoid_MR_finish(1);
3514        }
3515
3516        iamhere("About to call load_mountlist and load_raidtab");
3517        strcpy(bkpinfo->restore_path, MNT_RESTORING);
3518        read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
3519        retval = load_mountlist(mountlist, g_mountlist_fname);
3520        retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3521        iamhere
3522            ("Returned from calling load_mountlist and load_raidtab successfully");
3523
3524        if (argc > 1
3525            && (strcmp(argv[1], "--compare") == 0
3526                || strcmp(argv[1], "--nuke") == 0)) {
3527            if (bkpinfo->backup_media_type == nfs
3528                && !is_this_device_mounted(bkpinfo->nfs_mount)) {
3529                log_msg(1, "Mounting nfs dir");
3530                sprintf(bkpinfo->isodir, "/tmp/isodir");
3531                run_program_and_log_output("mkdir -p /tmp/isodir", 5);
3532                sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir",
3533                        bkpinfo->nfs_mount);
3534                run_program_and_log_output(tmp, 1);
3535            }
3536        }
3537
3538
3539        if (retval) {
3540            log_to_screen
3541                ("Warning - load_raidtab_into_raidlist returned an error");
3542        }
3543
3544
3545        log_msg(1, "Send in the clowns.");
3546
3547        if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) {
3548            log_msg(0, "Partitioning only.");
3549            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3550            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3551            load_mountlist(mountlist, g_mountlist_fname);
3552            res = partition_everything(mountlist);
3553            finish(res);
3554        }
3555
3556        if (argc == 2 && strcmp(argv[1], "--format-only") == 0) {
3557            log_msg(0, "Formatting only.");
3558            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3559            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3560            load_mountlist(mountlist, g_mountlist_fname);
3561            res = format_everything(mountlist, FALSE, raidlist);
3562            finish(res);
3563        }
3564
3565        if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) {
3566            log_msg(0, "Stopping LVM and RAID");
3567            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3568            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3569            load_mountlist(mountlist, g_mountlist_fname);
3570            res = do_my_funky_lvm_stuff(TRUE, FALSE);
3571            res += stop_all_raid_devices(mountlist);
3572            finish(res);
3573        }
3574
3575        if (argc == 2 && strcmp(argv[1], "--nuke") == 0) {
3576            iamhere("nuking");
3577            retval += nuke_mode(bkpinfo, mountlist, raidlist);
3578        } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) {
3579            iamhere("catchall");
3580            retval += catchall_mode(bkpinfo, mountlist, raidlist);
3581        } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) {
3582            iamhere("compare");
3583            retval += compare_mode(bkpinfo, mountlist, raidlist);
3584        } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) {
3585            iamhere("iso");
3586            retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE);
3587        } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) {
3588            iamhere("mbr");
3589            retval = mount_all_devices(mountlist, TRUE);
3590            if (!retval) {
3591                retval += run_boot_loader(FALSE);
3592                retval += unmount_all_devices(mountlist);
3593            }
3594            if (retval) {
3595                log_to_screen("Failed to write Master Boot Record");
3596            }
3597        } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) {
3598            iamhere("isonuke");
3599            retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE);
3600        } else if (argc != 1) {
3601            log_to_screen("Invalid paremeters");
3602            paranoid_MR_finish(1);
3603        } else {
3604            iamhere("catchall (no mode specified in command-line call");
3605            retval += catchall_mode(bkpinfo, mountlist, raidlist);
3606        }
3607    }
3608
3609    /* clean up at the end */
3610    if (retval) {
3611        if (does_file_exist("/tmp/changed.files")) {
3612            log_to_screen
3613                ("See /tmp/changed.files for list of files that have changed.");
3614        }
3615        mvaddstr_and_log_it(g_currentY++,
3616                            0,
3617                            "Run complete. Errors were reported. Please review the logfile.");
3618    } else {
3619        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3620            mvaddstr_and_log_it(g_currentY++,
3621                                0,
3622                                "Run complete. Please remove floppy/CD/media and reboot.");
3623        } else {
3624            run_program_and_log_output("sync", FALSE);
3625            if (is_this_device_mounted(MNT_CDROM)) {
3626                res =
3627                    run_program_and_log_output("umount " MNT_CDROM, FALSE);
3628            } else {
3629                res = 0;
3630            }
3631
3632            if (!bkpinfo->please_dont_eject) {
3633                res = eject_device("/dev/cdrom");
3634/*
3635              if (res)
3636        {
3637          log_to_screen( "WARNING - failed to eject CD-ROM disk" );
3638        }
3639*/
3640            }
3641            mvaddstr_and_log_it(g_currentY++,
3642                                0,
3643                                "Run complete. Please remove media and reboot.");
3644        }
3645    }
3646
3647// g_I_have_just_nuked is set true by nuke_mode() just before it returns
3648    if (!system("which post-nuke > /dev/null 2> /dev/null")) {
3649      log_msg(1, "post-nuke found; find out whether we should run it...");
3650      if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
3651        run_postnuke = TRUE;
3652        log_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
3653      } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
3654        run_postnuke = TRUE;
3655        log_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
3656      } else {
3657        run_postnuke = FALSE;
3658        log_msg(1, "No, will not run post-nuke.");
3659      }
3660    } else {
3661      log_msg(1, "No post-nuke found.");
3662    }
3663    if (run_postnuke) {
3664      log_to_screen("Running post-nuke...");
3665      if (mount_all_devices(mountlist, TRUE)) {
3666        log_to_screen
3667          ("Unable to re-mount partitions for post-nuke stuff");
3668      } else {
3669        log_msg(1, "Re-mounted partitions for post-nuke stuff");
3670        sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
3671            retval);
3672        log_msg(2, "Calling '%s'", tmp);
3673        if ((res = run_program_and_log_output(tmp, 0))) {
3674          log_OS_error(tmp);
3675        }
3676        log_msg(1, "post-nuke returned w/ res=%d", res);
3677      }
3678      unmount_all_devices(mountlist);
3679      log_to_screen("I've finished post-nuking.");
3680    }
3681
3682/* 
3683  log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
3684  log_to_screen("Otherwise, please wait until the RAID disks are done.");
3685  wait_until_software_raids_are_prepped("/proc/mdstat", 100);
3686  log_to_screen("Thank you.");
3687*/
3688    unlink("/tmp/mondo-run-prog.tmp");
3689    set_signals(FALSE);
3690    sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
3691    run_program_and_log_output(tmp, FALSE);
3692    log_to_screen
3693        ("Restore log copied to /tmp/mondo-restore.log on your hard disk");
3694    sprintf(tmp,
3695            "Mondo-restore is exiting (retval=%d)                                      ",
3696            retval);
3697    log_to_screen(tmp);
3698    sprintf(tmp, "umount %s", bkpinfo->isodir);
3699    run_program_and_log_output(tmp, 5);
3700    paranoid_free(mountlist);
3701    paranoid_free(raidlist);
3702    if (am_I_in_disaster_recovery_mode()) {
3703        run_program_and_log_output("mount / -o remount,rw", 2);
3704    }                           // for b0rken distros
3705    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
3706    free_libmondo_global_strings(); // it's fine to have this here :) really :)
3707    paranoid_free(a);
3708    paranoid_free(b);
3709    paranoid_free(tmp);
3710
3711    unlink("/tmp/filelist.full");
3712    unlink("/tmp/filelist.full.gz");
3713
3714    exit(retval);
3715}
3716
3717/**************************************************************************
3718 *END_MAIN                                                                *
3719 **************************************************************************/
3720
3721
3722
3723
3724
3725/**************************************************************************
3726 *END_MONDO-RESTORE.C                                                     *
3727 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.