ArGest Backup User Guide

  1. Home
  2. Docs
  3. ArGest Backup User Guide
  4. Appendix
  5. Appendix G – The Shell Scripts: fullbru and incbru

Appendix G – The Shell Scripts: fullbru and incbru

Two commands, fullbru and incbru, allow you to do full and incremental backups. These commands are shell scripts that can be run from the command line, or from cron for unattended backups (see Chapter 9, “Advanced Uses,” “Running BRU from cron”). The standard fullbru command will back up all the files on your system. incbru will back up all the files that have changed since the last time fullbru was run. fullbru actually calls the incbru command with an argument of 0 (zero). The incbru script does all the work. The incbru script will perform incremental backups at levels from 0 through 9. The backup level is determined by an optional argument (a digit from 0 through 9) included on the incbru command line. If no argument is given, a level 1 backup will be performed. A level 1 backup will contain all files modified since the last full backup. A level 2 backup will contain all files modified since the last level 1 backup, and so on.
Here’s how to do an incremental backup. Either command will back up all the files that have changed since the last full backup was run:

# incbru
or
# incbru 1

The following is a copy of the default incbru script. It was written to be as simple as possible and may not work correctly on your system. Feel free to modify it to suit your needs.

# This script will perform different levels of
# incremental backups using bru.
#
# It will back up all files that have changed
# since doing a lower level backup.
#
# If no argument is specified, the script will do a
# level 1 backup and will back up all files since
# the last full (level 0) backup. If the
# level 0 backup does not exist, it will do
# a level 0 backup instead.
#
# Feel free to customize this script to handle
# your specific backup requirements. This script
# is designed to do basic backups of the entire
# system from the root directory.
#
BRUDEV=”” # name of backup device. use default
# if none is specified
BRUOPTS=”-vvvv” # bru options
DIRS=”./” # directories or filesystems to
# back up
LOGFILE=”” # log file
MAILTO=root # where to mail the results
case “$#” in
0)
LVL=1 # no argument, so do a level 1 backup
;;
1)
LVL=$1
;;
*)
echo “usage: incbru [level]”
exit 1
;;
esac
#
# check for legal backup level
#
case $LVL in
0|1|2|3|4|5|6|7|8|9)
;;
*)
echo “incbru: $LVL is an illegal backup level”
exit 1
;;
esac
#
# if level 0, do a full backup
#
DATEFILE=””
if [ “$LVL” -eq 0 ]
then
DATEFILE=””
else
PREVLVL=`expr $LVL - 1` # previous backup level
echo “PREVLVL = $PREVLVL”
#
# find date marker file for previous level backup
#
i=0
while [ “$i” -le “$PREVLVL” ]
do
FILE=/etc/BRULEVEL$i
if [ -f “$FILE” ]
then
DATEFILE=$FILE
if [ “/etc/BRULEVEL${PREVLVL}” = “$FILE” ]
then
break # found previous date marker file
fi
fi
i=`expr $i 1`
done
fi
if [ “$DATEFILE” = “” ]
then
if [ “$LVL” -ne 0 ]
then
echo “incbru: No previous backup less than Level $LVL”
LVL=0
fi
echo “Performing Full Backup (Level 0)”
else
echo “Performing Level $LVL Backup”
BRUOPTS=”$BRUOPTS -n $DATEFILE”
fi
#
# set up bru command that will do the backup.
# use default device from brutab if none is
# specified
#
if [ “$BRUDEV” != “” ]
then
BRUCMD=”bru -c $BRUOPTS -f $BRUDEV $DIRS”
else
BRUCMD=”bru -c $BRUOPTS $DIRS” # use default
fi # device
#
# create a temporary date marker file. if the
# backup is successful, this will be renamed
#
MARKER=/etc/BRULEVEL${LVL}
TMP=$MARKER.err
TS=`date`
echo “$TS - Started BRU Level $LVL Backup\n\tcommand = ‘$BRUCMD’” > $TMP
#
# change to the root directory and execute the
# bru backup. write output to log file if one
# is specified
#
BRUEXIT=2
cd /
if [ “$LOGFILE” != “” ]
then
$BRUCMD > $LOGFILE 2>&1
BRUEXIT=$?
else
$BRUCMD 2>&1
BRUEXIT=$?
fi
#
# check the exit code. if greater than or equal
# to 2, we’ve got a problem
#
TS=`date`
if [ “$BRUEXIT” -ge 2 ]
then
echo “incbru: ERROR in BRU Backup”
echo “$TS - ERROR IN BRU BACKUP, check log file: \
‘$LOGFILE’” >> $TMP
mail $MAILTO < $TMP exit 2 else echo “BRU Level $LVL Backup successful” mv $TMP $MARKER echo “$TS - BRU Level $LVL Backup successful, \ results in log file: ‘$LOGFILE’” | mail $MAILTO exit 0 fi