1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
|
#!/bin/sh
#
# $Header: /home/kbackup/CVSROOT/KBackup/src/restore_src,v 1.24 1997/09/19 19:49:25 kbackup Exp $
#
# This file is Copyright (C) 1995-1997 by Karsten Ballder (Ballueder@usa.net)
#
# It is part of the KBackup package, see the file COPYING for details.
# KBackup and all files included in this package are licensed and protected
# under the terms and conditions of the GNU General Public License Version 2.
#
# If you want to contact the current maintainer of this software, please
# send e-mail to: KBackup@usa.net
#
#
# subroutines doing all restore operation,
# get loaded by Restore() on demand
#
Restore_src_loaded=YES
if [ "$ReadData_src_loaded" != "YES" ]
then
. $SRCDIR/$READDATA_SRC
fi
if [ "$Blockdev_src_loaded" != "YES" ]
then
. $SRCDIR/$BLOCKDEV_SRC
fi
Restore_II()
{
save_options
if [ "$restore_write_log" = "YES" ]
then
rest_logfile="$TMP/$TARLOGFILE"
else
rest_logfile=/dev/null
fi
if [ "$scheduled" != "YES" ]
then
insert_media
if [ $? != 0 ]
then
return
fi
fi
auto_rewind
if [ "$device_type" = "BLOCKDEV" ]
then
if [ -f "$MOUNTPOINT/$BLOCKDEV_HEADER" ]
then
dirfile="$MOUNTPOINT/$BLOCKDEV_DIRECTORY"
header="$MOUNTPOINT/$BLOCKDEV_HEADER"
archive="$MOUNTPOINT/$BLOCKDEV_ARCHIVE"
else
dirfile="$MOUNTPOINT/$arch_filename.dir"
header="$MOUNTPOINT/$arch_filename.hdr"
archive="$MOUNTPOINT/$arch_filename.arc"
fi
get_blockdev READ
else if [ "$device_type" = "FILE" ]
then
dirfile="$arch_filename.dir"
header="$arch_filename.hdr"
archive="$arch_filename.arc"
else
dirfile="$device"
header="$device"
archive="$device"
fi
fi
if [ "$scheduled" = "YES" ]
then
echo "Starting scheduled restore at `date`:" >$TMP/$MSGFILE
else
Restore_part_I
if [ $? != 0 ]
then
restore_options
return
fi
fi
InfoBox "Filtering list..."
# - remove all afio specific information from logfile:
# - remove one possible remark from tar:
# - remove leading slashes:
#
# extract filename from:
# ^file size uid gid wday month day hh:mm:ss year perm$
# this should handle filenames with ANY characters properly
$SED "\
1,$ s/ -- okay$//g
1,$ s/\.z -- ([0-9][0-9]*\%)$//g
1,$ s/^tar: .* is the archive; not dumped$//g
1,1 s/^Generating logfile...$//g
1,$ s/^Archive size: .*$//g
1,$ s/^[0-9+]* records in$//g
1,$ s/^[0-9+]* records out$//g
1,$ s/^\/\(.*\)$/\1/g
1,$ s/^\\(.*\) [0-9][0-9]* [^ ][^ ]* [^ ][^ ]* [^ ][^ ]* [^ ][^ ]* [^ ][^ ]* ..:..:.. [^ ][^ ]* [^ ][^ ]*$/\1/g
1,$ s/^\.\///g
" <$TMP/$DIRLISTFILE >$TMP/$TARLISTFILE
check_error
InfoBox "Restoring files..."
if [ $compression = PGP ]
then
GetPGPPASS
fi
cd "$restore_dir"
if [ "$backup_archive_format" = "TAR" ]
then
Tar_Restore
else # AFIO
Afio_Restore
fi
clear_PGP
if [ "$restore_write_log" = "YES" ]
then
logfile="$TMP/RESTORED-`date +'%y-%m-%d--%X'`"
if [ $scheduled = NO ]
then
cat $rest_logfile | $compress >$logfile
beep
$DIALOG --title $logfile --textbox $rest_logfile 23 75
else
cat $TMP/$MSGFILE $rest_logfile | $compress >$logfile
rm -rf $datadir/$schedulename
rm -f $TMP/$MSGFILE
fi
fi
restore_options
release_blockdev
}
Restore_part_I()
{
old_compression="$compression"
backup_numversion=0
if [ "$device_type" != "FLOPPY" ]
then
InfoBox "Reading header..."
read_data -raw $header >$TMP/$TMPFILE 2>$STDERR
check_error -dev
if [ $? != 0 ]
then
return 1
else
if read firstline < $TMP/$TMPFILE && test "$firstline" = "#KBackup"
then
backup_use_multibuf="???"
. $TMP/$TMPFILE
compression="$backup_compression"
if [ "$backup_use_multibuf" = "YES" ]
then
use_multibuf="$backup_use_multibuf"
multibuf_blksize="$backup_multibuf_blksize"
multibuf_nblocks="$backup_multibuf_nblocks"
multibuf_seq_info="$backup_multibuf_seq_info"
else
use_multibuf=NO
fi
$DIALOG --title "Archive header information" --msgbox "\n\
Archive created by KBackup Version: $backup_version\n\
files per archive: .............. $backup_filesperarchive\n\
Creation date: .................... $backup_date\n\
Backup type: ...................... $backup_type\n\
Archive format: ................... $backup_archive_format\n\
Compression method: ............... $backup_compression\n\
Directories-only flag: ............ $backup_donly\n\
using \"old\" MultiBuf: ........... $backup_use_multibuf\n\
blocksize: ...................... $backup_multibuf_blksize\n\
number of blocks: ............... $backup_multibuf_nblocks\n\
using sequence information: ..... $backup_multibuf_seq_info\n\
Parent directory of backup: ....... $backup_parent\n" 19 75
else
ErrorBox "Cannot find a KBackup archive header!"
return 1
fi
fi
fi
MsgBox \
"You are now prompted to choose
the relative root directory."
if [ "$backup_parent" = "" ]
then
backup_parent=/
fi
choose_dir "$backup_parent"
restore_dir="$choose_dir_result"
set_compress
restore_all=NO
while :
do
$DIALOG --menu "Please choose:" 11 75 4\
A "Restore all files from archive" \
C "Initialise editable list of files from contents directory"\
L "Initialise editable list of files from logfile"\
"<" "Return to main menu" 2>$TMP/$DIALOGFILE
if [ $? = 0 ]
then
case `cat $TMP/$DIALOGFILE` in
A) InfoBox "Reading directory..."
if [ "$device_type" != "FLOPPY" ]
then
read_data $dirfile >$TMP/$TMPFILE 2>$STDERR
$uncompress <$TMP/$TMPFILE >$TMP/$DIRLISTFILE 2>$STDERR 3<$TMP/$PHRASEFILE
check_compress_success
if [ $? != 0 ]
then
beep
$DIALOG --title "Error" --msgbox "
Reading/Decompressing contents
directory failed.
Error message:
`cat $STDERR`
" 12 40
return 1
fi
fi
restore_all=YES
return 0
;;
C) if [ "$device_type" = "FLOPPY" ]
then
ErrorBox "Floppy archives do not have a contents directory!"
return 1
fi
InfoBox "Reading contents directory..."
read_data $dirfile >$TMP/$TMPFILE 2>$STDERR
check_error
if [ $? != 0 ] ; then return 1; fi
$uncompress <$TMP/$TMPFILE >$TMP/$DIRLISTFILE 2>$STDERR 3<$TMP/$PHRASEFILE
check_compress_success
if [ $? != 0 ]
then
beep
$DIALOG --title "Error" --msgbox "
Reading/Decompressing contents
directory failed.
Error message:
`cat $STDERR`
" 12 40
return 1
fi
check_error
if [ $? != 0 ] ; then return 1; fi
clear
reset
$EDITOR $TMP/$DIRLISTFILE 2>$STDERR
check_error
if [ $? != 0 ] ; then return 1; fi
$DIALOG --title " Restore " --yesno "Continue with restore?" 7 32
if [ $? = 0 ]
then
return 0
else
return 1
fi
;;
L) find $datadir/$configname -name "*Log*" -printf "%f %Tx\n" | sort >$TMP/$TMPFILE
lines=`wc -l <$TMP/$TMPFILE`
if [ "$lines" = "" -o "$lines" = "0" ]
then
MsgBox "Could not find any logfiles."
return 1 # error
fi
if [ "$lines" -gt 15 ] ; then lines=15 ; fi
$DIALOG --menu "Choose a logfile:" 22 60 $lines \
`cat $TMP/$TMPFILE` 2>$TMP/$DIALOGFILE
check_error
( uncompress_logfile $datadir/$configname/`cat $TMP/$DIALOGFILE` && cat $TMP/$TMPFILE >$TMP/$DIRLISTFILE ) 2>$STDERR 3<$TMP/$PHRASEFILE
check_error
if [ $? != 0 ] ; then return 1; fi
clear
reset
$EDITOR $TMP/$DIRLISTFILE 2>$STDERR
check_error
if [ $? != 0 ] ; then return 1; fi
$DIALOG --title " Restore " --yesno "Continue with restore?" 7 32
if [ $? != 0 ]
then
return 1
fi
if [ "$device_type" != "FLOPPY" ]
then
InfoBox "Skipping contents directory..."
read_data $dirfile >/dev/null 2>$STDERR
check_error
fi
return 0
;;
"<") compression="$old_compression"
return 1
;;
esac
else
compression="$old_compression"
return 1
fi
done
return 0
}
Tar_Restore()
{
xopt="$STD_TAROPT_REST"
if [ $restore_all = NO ]
then
xopt="$xopt --files-from $TMP/$TARLISTFILE"
else
files=
fi
if [ $followtarops = YES ]
then
clear
reset
xopt="$xopt -v -v"
echo "( read_data $archive \
| $TAR $tar_user_opts $xopt --extract $tarcompress -f - )" >$TMP/$TMPFILE
. $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE | tee $rest_logfile
echo -e "\nPress ENTER to continue..."
read
else
echo "( read_data $archive | $TAR $tar_user_opts $xopt --extract \
$tarcompress -f - )" >$TMP/$TMPFILE
. $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE >$rest_logfile
fi
}
Afio_Restore()
{
xopt="$STD_AFIOOPT_REST"
afio_bug_save_programs
if [ "$device_type" = "FLOPPY" ]
then
blocks=`echo $floppy_format|$SED '1,$ s/\(.*\)\/.*/\1k/g' `
xopt="$xopt -F -s $blocks "
fi
if [ "$protect_newer" = "YES" ]
then
xopt="$xopt -n "
fi
if [ $compression != NONE ]
then
xopt="$xopt -Z"
if [ "$HasAFIO242" != "YES" ]
then
if [ $compression != GZIP ]
then
mkdir $TMP/$BINDIR
cp $TMP/$COMPRESSFILE $TMP/$BINDIR/gzip
oldpath="$PATH"
export PATH="$TMP/$BINDIR:$PATH"
fi
else # new afio
xopt="$xopt -P \"$compress_program\""
if [ -n "$decompress_options" ]
then
for i in $decompress_options
do
xopt="$xopt -Q \"$i\" "
done
if [ "$compression" = PGP ]
then
xopt="$xopt -Q -f "
fi
else
xopt="$xopt -Q -d -Q -c "
fi
fi
fi
if [ $restore_all = YES ]
then
if [ $followtarops = YES ]
then
clear
reset
echo "( read_data $archive | $AFIO -i $afio_user_opts $xopt -vz - )" >$TMP/$TMPFILE
. $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE | tee $rest_logfile
echo -en "\nPress RETURN key to continue..."
read
else
echo "( read_data $archive | $AFIO -i $afio_user_opts $xopt -vz - ) ">$TMP/$TMPFILE
. $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE >$rest_logfile
fi
else
if [ $followtarops = YES ]
then
clear
reset
echo "( read_data $archive | $AFIO -i $afio_user_opts $xopt -vz -w $TMP/$TARLISTFILE - )" >$TMP/$TMPFILE
. $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE | tee $rest_logfile
echo -en "\nPress RETURN key to continue..."
read
else
echo "( read_data $archive | $AFIO -i $afio_user_opts $xopt -w $TMP/$TARLISTFILE -vz - )" >$TMP/$TMPFILE
. $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE >$rest_logfile
fi
fi
if [ $compression != GZIP -a $compression != NONE ]
then
rm -rf $TMP/$BINDIR
export PATH="$oldpath"
fi
afio_bug_restore_path
}
|