Listing 1 backup
##########################################################################
# Listing 1:
# Shellscript: backup - backup (remote) system on local tape
# Author : Heiner Steven <heiner.steven@odn.de>
# Requires : cpio, find, {rsh | ssh}
# Category : System Administration
# SCCS-Id. : @(#) backup 1.1 03/05/29
##########################################################################
# Description
#
##########################################################################
PN=`basename "$0"` # Program name
VER='1.1'
# Variables written in UPPER CASE can be set in the environment before
# invoking this script. The following lines set default values if the
# variables were not set:
: ${TAPE:=/dev/rmt0} # Local tape device
# Program to run a command remotely. Should have the syntax
# $RCMD $RCMDFLAGS host command [...]
: ${RCMD:=rsh} # Remotely run command
: ${RCMDFLAGS="-l root"}
#: ${RCMD:=ssh} # Use "ssh"
#: ${RCMD:="-l root"} # Use "ssh"
usage () {
echo >&2 "$PN - backup (remote) system on local tape, $VER
usage: $PN rhost [directory ...]
The specified directories (default: all) on the host \"rhost\" are
combined into an \"cpio\" archive, which then is written to a local
tape device ($TAPE)."
exit 1
}
set -- `getopt :h "$@"` || usage
[ $# -lt 1 ] && usage # "getopt" detected an error
while [ $# -gt 0 ]
do
case "$1" in
# your flags here
--) shift; break;;
-h) usage;;
-*) usage;;
*) break;; # First host name
esac
shift
done
[ $# -gt 0 ] || set -- localhost # Default remote host
Rhost=$1; shift
[ $# -gt 0 ] || set -- '.[!.]* .' # Default remote directory pattern
if [ -c "$TAPE" -o -b "$TAPE" ] # Is $TAPE a valid device?
then
echo >&2 "Write directories from $Rhost to local device $TAPE (^d = no)? \c"
read dummy || { echo >&2; exit 0; }
else
echo >&2 "cannot access backup device TAPE=$TAPE"
exit 1
fi
if [ X`$RCMD $RCMDFLAGS "$Rhost" pwd` != X ] # Try rsh/ssh
then
# Create a remote "cpio" archive, and send it over the net to a
# local "dd" process, that writes it to the tape device.
set -x
"$RCMD" $RCMDFLAGS "$Rhost" 'cd /; find '"$*"' -xdev -print |
cpio -ov -H odc' |
dd of=$TAPE obs=10k
set +x
else
echo >&2 "$PN: cannot reach host $Rhost (.rhosts entry for root?)"
echo >&2 "$PN: Please verify that \"$RCMD $RCMDFLAGS $Rhost pwd\" works"
exit 1
fi
|