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

Last change on this file since 998 was 998, checked in by Bruno Cornec, 17 years ago

Attempt to solve #113

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