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

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

my-stuff.h is referred to in include now

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