#!/bin/ksh
# filename: fullbackup.sh
# description: performs a level 0 cpio backup
on either Sun or HP
#
platforms.
# author: robin manapsal, 11-23-99
# version: 1.0, revised to cpio instead of ufsdump/vxdump
command
UNAME=`/usr/bin/uname -s`
SUNDEV=/dev/rmt/0mn
HPDEV=/dev/rmt/0mn
HOSTNAME=`/usr/bin/hostname`
CONTACTS="[email protected]"
FILE=/tmp/tape.status
DATE=`date '+%Y-%m-%d'`
LOGDIR=/tmp/backups/backup.log_$DATE
TEE=/bin/tee
GRAPH=/tmp/graphfile
CPIO=/bin/cpio
EXCLUDE=/sysadmin/exclude
INCLUDE=/sysadmin/include
##########################################################
#
#
#
Probe the status of the tape device
#
#
#
#
Checks the size of the $FILE. If the $FILE=0 bytes
#
#
the backup procedure is aborted. If the $FILE>0 bytes
#
#
the procedure is initiated until the process is
#
#
completed.
#
#
#
##########################################################
echo "Probing OS and tape device"
if [ "$UNAME"="SunOS" ]; then
mt -f $SUNDEV
status > $FILE
elif [ "$UNAME"="HP-UX" ]; then
mt -t $HPDEV
rew > $FILE
fi
if [ ! -s $FILE ]; then
echo "$UNAME device is not
ready"
mailx -s "Error: Aborting
backup on $HOSTNAME - tape not mounted" $CONTACTS < /dev/null
> /dev/null 2>&1
exit 0
else
echo "$UNAME device is ready"
echo "Proceeding with the backup"
fi
##########################################################
#
#
#
Collecting files for backup
#
#
#
##########################################################
echo "Collecting graphfile"
if [ ! -f $GRAPH ]; then
echo "$GRAPH does not exist"
find / -fstype ufs > $GRAPH
else
echo "Graphfile exist"
fi
###########################################################
#
#
#
Determine the OS Version and excute the cpio
#
#
This part of the script uses the local cpio depending
#
#
on the flavor of UNIX. This part can be modified to
#
#
suit the various flavors of UNIX such as BSD, Linux
#
#
Solaris, HP, IBM-AIX, SCO (maybe)..
#
#
#
###########################################################
echo "Please wait: Identifying HOST and UNIX
flavor"
case $UNAME in
SunOS)
if [ "$UNAME"="SunOS"
]; then
(grep -c
$INCLUDE | $CPIO -ocBv > $SUNDEV) 2>&1 | $TEE -a $LOGDIR
mailx -s
"$HOSTNAME: Backup Complete" $CONTACTS < /dev/null > /dev/null 2>&1
fi
;;
HP-UX)
if [ "$UNAME"="HP-UX"
]; then
(cat $GRAPH
| $CPIO -ocBv > $HPDEV) 2>&1 | $TEE -a $LOGDIR
mailx -s
"$HOSTNAME: Backup Complete" $CONTACTS < /dev/null > /dev/null 2>&1
fi
;;
*)
echo "$UNAME
is not supported in this script"
echo "Backup
failed"
mailx -s
"Error: Backup failed on $HOSTNAME" $CONTACTS < /dev/null > /dev/null
2>&1
;;
esac
##########################################################
#
#
#
Eject the tape(s)
#
#
#
##########################################################
echo "Ejecting Tape"
if [ "$UNAME"="SunOS" ]; then
mt -f $SUNDEV offline
elif
[ "$UNAME"="HP-UX" ]; then
mt -f $HPDEV offl
else
echo "Tape on $UNAME is offline"
mailx -s "$HOSTNAME: No tape loaded
or drive offline" $CONTACTS < /dev/null > /dev/null 2>&1
fi
echo "Tape Ejected"
##########################################################
#
#
Compress the log files
#
##########################################################
echo "Compressing Log file"
$GZIP $LOGDIR
echo "Compression done"
##########################################################
#
#
Clean up the backup logs
#
##########################################################
echo "Removing log file"
find $LOGDIR -mtime +5 -exec rm -f {} \;