#!/usr/local/bin/ksh
#################################################################################
# Script backup.cliff #
# Description Backs up important files to tape. #
# Written On 09/06/01 #
# Modifications 09/15/01 - Added /var to backup directory list. Also added the #
# ability to calculate tape usage. - rmorten #
# 11/12/01 - Cleanup wasn't working since we run this file every #
# week but wanted to delete files 30 days old. Changed to 28 #
# days. - rmorten #
# 02/12/03 - Added new serial number to end of file to show finish#
# time. - rmorten #
# 02/20/03 - Corrected serial number addition with printf. #
# - rmorten #
# Written By Rick Mortensen #
#################################################################################

# Program Variables
bkdate=/bin/bkdate
DAYMINUS28=`$bkdate -d28 '+%y%m%d'`
SERIAL=`date '+%y%m%d%H%M%S'`

# Directory Variables
BIN=/home/bin
TAPE=/dev/nrsa0
DIRS="/etc /usr/ECS /usr/home /usr/bin /usr/local /usr/Source /root /bin /var"
LOGS=/var/log/backup
UBIN=/usr/bin

# File Variables
TAR=$UBIN/tar
MT=$UBIN/mt
awk=$UBIN/awk

# Command Variables
REW="$MT -f $TAPE rewind"
EJECT="$MT -f $TAPE rewoffl"
LIST="$TAR -tvf $TAPE"
ARCHIVE="$TAR -cvf $TAPE"

# Temp Files
TMP1=/tmp/tmp1.$$
TMP2=/tmp/tmp2.$$
TMP3=/tmp/tmp3.$$
TMP4=/tmp/tmp4.$$

# Now that all the prework is finished, start to actually get some work done!
echo "\n\nRewinding tape" | tee -a $LOGS/$SERIAL.activitylog
$REW 2>>$LOGS/$SERIAL.error

echo "\n\nListing existing tape dir" | tee -a $LOGS/$SERIAL.activitylog
$LIST | tee -a $LOGS/$SERIAL.oldtapedir 2>>$LOGS/$SERIAL.error

echo "\n\nRewinding tape" | tee -a $LOGS/$SERIAL.activitylog
$REW 2>>$LOGS/$SERIAL.error

echo "\n\nArchivig to tape (via tar)" | tee -a $LOGS/$SERIAL.activitylog
$ARCHIVE $DIRS | tee -a $LOGS/$SERIAL.archive 2>>$LOGS/$SERIAL.error

echo "\n\nRewinding tape" | tee -a $LOGS/$SERIAL.activitylog
$REW 2>>$LOGS/$SERIAL.error

echo "\n\nListing new tape dir" | tee -a $LOGS/$SERIAL.activitylog
$LIST | tee -a $LOGS/$SERIAL.newtapedir 2>>$LOGS/$SERIAL.error

echo "\n\nEjecting tape" | tee -a $LOGS/$SERIAL.activitylog
$EJECT 2>>$LOGS/$SERIAL.error

echo "\n\nCalculating tape size" | tee -a $LOGS/$SERIAL.activitylog
NEWDATE=`date '+%y%m%d'`
NEWTIME=`date '+%H%M%S'`
$awk '{tapesize = tapesize + $3; n = n + 1}
END {printf("%06d%06d - %d bytes in %d files\n", '$NEWDATE', '$NEWTIME', tapesize, n)}' $LOGS/$SERIAL.newtapedir | tee -a $LOGS/$SERIAL.activitylog 2>>$LOGS/$SERIAL.error

# Cleanup
rm -fr $LOGS/$DAYMINUS28*
rm -fr $TMP1* $TMP2* $TMP3* $TMP4*

 

  • Expect the best and be prepared for the worst.

  • It is the service that counts, the product can be found anywhere...

[Under Construction]This website will always be under construction...
The information contained within this website is confidential and only to be used in conjunction with the employment of Richard C. Mortensen.  All other use is unauthorized.
Send mail to webmaster@can-be-scanned.com with questions or comments about this web site.
Copyright © 2000 PR Enterprises, Inc.
Last modified: June 09, 2000