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