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

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

g_getfacl|attr extern in mondo-restore.c

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