Cover V02, I05
Article
Listing 1
Listing 2
Listing 3

sep93.tar


Listing 2: crestore

#!/bin/sh
#
# crestore
#
# Restore files or entire filesystem from backup tape created by cbackup.
#
# usage:
#       crestore tape_device destination [files]
#
# where:
#       tape_device     name of tape drive, prepended by hostname
#                       and a colon if on a remote host
#                       (e.g., /dev/rst0 or batman:/dev/rst0)
#       destination     directory in which to restore the tape, to
#                       restore to original location, use / here
#                       (e.g., / or /tmp)
#       files           one or more files to restore from tape.  If
#                       no filenames are given, all the files on the
#                       tape are restored.

if [ $# -lt 2 ]; then
echo "usage: $0 tape-device destination [files]"
exit
fi

#
# find tape device name and hostname if backup
# tape is mounted on a remote host
#
TAPE=`echo $1 | awk -F: '{print $2}'`
if [ "$TAPE" = "" ]; then
TAPE=$1
HOST=""
else
HOST=`echo $1 | awk -F: '{print $1}'`
fi

DEST=$2
if [ ! -d $DEST ]; then
echo "Cannot cd to directory ${DEST}."
exit 1
fi

shift
shift
FILES="$*"

#
# cd to the destination and read the files
#
cd $DEST

if [ "$HOST" = "" ]; then
# local tape
cpio -idvB $FILES <<$TAPE
else                            # remote tape
rsh $HOST dd if=$TAPE ibs=5120 | cpio -idv $FILES
fi