Listing 5: A simple backup script

#!/bin/sh
# Don't forget to set these!
#
# Host with tape drive. You can run this script on a
# different host than the one with the tape drive as
# long as you have rsh access to all systems without
# having to provide the password.
#
TAPEHOST=
#
# Change device to use if not st0. Also check alternate 
# (tape2); default is st1.
#
DEVICE=nrst0
#
# The following variables are set to correct parameters
# for a 8mm 5GB tape
# OPTIONS: dump options; BT: blocking factor;
# SIZE: length of tape; DENSITY: tape density
#
# For a 2BG tape drive use SIZE=6000
#
OPTIONS=ubsdf
BT=126
SIZE=12000
DENSITY=54000
#
# The following are for a 150MB 1/4" tape drive
# OPTIONS: dump options; BT: number of tracks;
# SIZE: length of tape; DENSITY: tape density
#
#OPTIONS=uctsdf
#BT=18
#SIZE=700
#DENSITY=6250
#
# Path to dump command on remote machine - location on
# your systems may be different.
#
DUMP=/etc/rdump
#
#check parameters
if [ $# -lt 2 ]; then
  echo "Usage: $0 <level> <Day> [tape2] [rew]
  Where <level> is the level of the dump that you want 
                (0-9).
        <Day>   is the type of dump, corresponding 
                to the day of the week for nightly
                incrementals. It may be one of:
                      Monday Tuesday Wednesday Thursday
                      Weekly Monthly
       [tape2]  is an optional parameter that directs
                the script to use the alternate tape  
                drive instead of the primary drive.
  and   [rew]   is an optional parameter that indicates 
                the tape should remain rewound. This 
                parameter is significant only on  
                incrementals, where the default is go
                to the end of the tape." 
  exit 1
fi 
LEVEL=$1
DAY=$2
#
# The following variable is used only on daily backups. 
# Override for new tapes and Monday, or change the 
# script so Monday's daily stays rewound by default.
#
EOM=yes
#
# Example setup and usage with a backup account.
# Uncomment the following line.
#USER=backup
#
# Replace the second line of the dump command with the 
# following 2 lines.
#$SIZE $DENSITY ${USER}@${TAPEHOST}:/dev/${DEVICE} $FS
#
# Parse command line looking for optional parameters
for i
do case $i in
    rew)
        EOM=no;;
    tape2)
        DEVICE=nrst1
# if the secondary drive is on a different system
# uncomment and set the following line.
#       TAPEHOST=
#
# if the secondary tape drive is a 1/4" tape uncomment
# the following lines
#       OPTIONS=uctsdf
#       BT=18
#       SIZE=700
#       DENSITY=6250
        ;;
   esac
done
date
echo Rewinding
/usr/ucb/rsh $TAPEHOST mt -f /dev/${DEVICE} rew
echo $DAY Backup on $TAPEHOST
#
if [ $DAY = Monthly ]; then
  echo Monthly backup
#
# List hosts to backup on next line. For example:
# for HOST in pegasus mikey
#
  for HOST in
    do
#
# List file systems to dump on the next line. For
# example: for FS in /dev/sd0a /home)
#
    for FS in
      do
       echo ${HOST}:${FS} to $DEVICE on $TAPEHOST
      /usr/ucb/rsh $HOST $DUMP ${LEVEL}${OPTIONS} $BT \
          $SIZE $DENSITY ${TAPEHOST}:/dev/${DEVICE} $FS
      done
    done
elif [ $DAY = Weekly ]; then
  echo Weekly backup
#
# Set name of host to backup, or convert to list of 
# hosts with "for HOST in" statement, but don't forget
# to add the "do..done".
#
  HOST=
#
# Set file system to back up, or convert to "for FS in" 
# statement, but don't forget to add the "do..done".
#
  FS=
  echo ${HOST}:${FS} to $DEVICE on $TAPEHOST
  /usr/ucb/rsh $HOST $DUMP ${LEVEL}${OPTIONS} $BT \
      $SIZE $DENSITY ${TAPEHOST}:/dev/${DEVICE} $FS
else
  echo Daily backup
  if [ $EOM = yes ] ; then
# Put this incremental at the end of the tape.
    echo Going to end of media
    /usr/ucb/rsh $TAPEHOST mt -f /dev/${DEVICE} eom
  fi
#
# Set name of host to backup, or convert to list of 
# hosts with "for HOST in" statement, but don't forget
# to add the"do..done".
#
  HOST=
#
# Set file system to back up, or convert to "for FS in" 
# statement, but don't forget to add the "do..done".
#
  FS=
#
  echo ${HOST}:${FS} to $DEVICE on $TAPEHOST
  /usr/ucb/rsh $HOST $DUMP ${LEVEL}${OPTIONS} $BT \
      $SIZE $DENSITY ${TAPEHOST}:/dev/${DEVICE} $FS
fi
#
# Multiple Dailys go on one tape, so rewind after the 
# dump but don't offline. This makes sure that the dump
# always starts at a known point (i.e. rewound). 
# Offline at end of week and on Weeklys and Monthlys to 
# prevent accidentally overwriting the dump.
#
if [ $DAY = Monday -o $DAY = Tuesday -o \
     $DAY = Wednesday ]; then
  echo Rewinding
  /usr/ucb/rsh $TAPEHOST mt -f /dev/${DEVICE} rew
else
  echo Rewinding and going offline
  /usr/ucb/rsh $TAPEHOST mt -f /dev/${DEVICE} offline
fi
#
date

