Cover V02, I05
Article
Listing 1
Listing 2
Listing 3

sep93.tar


Listing 1: cbackup

#!/bin/sh
#
# cbackup
#
# Backup files in a filesystem, simulating Berkeley-style
# dump levels but using find(1) and cpio(1).  Allow backup
# to be written to a tape drive on a remote host.
#
# usage:
#       cbackup level filesystem tape_device
#
# where:
#       level           incremental backup level (e.g.,
#                       0-9 where 0 is a full backup)
#       filesystem      name of the filesystem to be
#                       backed up (e.g., / or /usr)
#       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)

if [ $# -ne 3 ]; then
echo "usage: $0 level filesystem tape-device"
exit
fi

#
# get the name of the filesystem to backup
#
x=`echo $2 | cut -c1`
#
# if absolute path, make relative
#
if [ "$x" = "/" ]; then
FS=.$2
else
FS=$2
fi
#
# bookmark file, will have level number appeneded to it.
# We keep the bookmark file in the top of the filesystem
# being backed up so multiple filesystems can be backed
# up at different levels and different times.
#
BOOKMARK=$2/level

#
# get specified level and verify
#
LEVEL=$1
if [ $LEVEL -lt 0 ]; then
echo "level must be 0-9"
exit 1
elif [ $LEVEL -gt 9 ]; then
echo "level must be 0-9"
exit 1
fi
if [ $LEVEL = 0 ]; then
LEVELARGS=""
else
#
# get all files back to previous level
#
LOWERLEVEL=`expr $LEVEL - 1`
LEVELARGS="-newer $BOOKMARK.$LOWERLEVEL"
fi

if [ ! -f $BOOKMARK.$LOWERLEVEL ]; then
#
# no previous bookmark, so do a full backup
#
LEVELARGS=""
fi

#
# verify that specified directory exists
#
cd /
if [ ! -d $FS ]; then
echo "No such directory $2"
exit 1
fi

#
# find the tape device and hostname if remote
#
TAPE=`echo $3 | awk -F: '{print $2}'`
#
#
if [ "$TAPE" = "" ]; then
TAPE=$3
HOST=""
else
#
# get remote hostname
#
HOST=`echo $3 | awk -F: '{print $1}'`
fi

if [ "$HOST" = "" ]; then
#
# backup to local tape drive
#
echo "Local backup to $TAPE"
find $FS -xdev $LEVELARGS -print | cpio -ovB >$TAPE
else
#
# backup to remote tape drive
#
echo "Remote backup to $TAPE on $HOST"
find $FS -xdev $LEVELARGS -print | cpio -ov | \
rsh $HOST dd of=$TAPE obs=5120
fi

#
# update modification time of bookmark file
#
touch $BOOKMARK.$LEVEL