Listing 1 online-dump.sh script
#!/bin/sh
#
# script to dump FreeBSD partitions to backup disk
# Jamie Castle 06/19/2003
###################################################################
# Revision History
# 06/19/2003 Initial code
# 07/14/2003 Added function to purge old backups
# 07/27/2003 Added Month and Level hierarchy to directory structure
# 10/19/2003 Added day of month and day function to determine dump level
# 05/06/2004 Added logic to perform manual level 0 from cmd line
#
###################################################################
# Declare variables
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin
HOST=`hostname -s`
PARTITIONS_LIST="/ /usr /var"
DUMP="/sbin/dump"
DOM=`date | awk '{print $3}'`
DAY=`date | awk '{print $1}'`
MONTH=`date | awk '{print $2}'`
LABEL=`date +%m%d%Y_%H%M`
DUMP_DISK="/backups"
export PATH
# Mount the dump disk partition, exit on failure. This helps protect
# from filling up the / partition if the mount fails.
/sbin/mount $DUMP_DISK || exit 1
# Determine dump level
if [ $DOM -eq 1 ] || ( [ $1 ] && [ $1 -eq 0 ] )
then
DUMPARGS="0u -a -f";LEVEL=L0
else
case $DAY in
Fri) DUMPARGS="1u -a -f";LEVEL=L1;;
Sat) DUMPARGS="2u -a -f";LEVEL=L2;;
Sun) DUMPARGS="3u -a -f";LEVEL=L3;;
Mon) DUMPARGS="4u -a -f";LEVEL=L4;;
Tue) DUMPARGS="5u -a -f";LEVEL=L5;;
Wed) DUMPARGS="6u -a -f";LEVEL=L6;;
Thu) DUMPARGS="7u -a -f";LEVEL=L7;;
esac
fi
DUMP_DEST="$DUMP_DISK/$HOST/$MONTH/$DOM/"
# Create Month directory if necessary
if test ! -d $DUMP_DEST
then mkdir -p $DUMP_DEST
fi
# Dump partitions to NFS-mounted /backups
for SLICE in $PARTITIONS_LIST
do
if [ $SLICE = '/' ]
then
DUMP_VOL='.root'
else
DUMP_VOL=`echo $SLICE | sed 's/\\//./g'`
fi
$DUMP $DUMPARGS $DUMP_DEST$LABEL$DUMP_VOL.$LEVEL.dmp $SLICE
chmod 444 $DUMP_DEST$LABEL$DUMP_VOL.$LEVEL.dmp
done
# Purge old backups as necessary. Retains 3 months of backups.
case $MONTH in
Jan) DELETE_MONTH=Sep;;
Feb) DELETE_MONTH=Oct;;
Mar) DELETE_MONTH=Nov;;
Apr) DELETE_MONTH=Dec;;
May) DELETE_MONTH=Jan;;
Jun) DELETE_MONTH=Feb;;
Jul) DELETE_MONTH=Mar;;
Aug) DELETE_MONTH=Apr;;
Sep) DELETE_MONTH=May;;
Oct) DELETE_MONTH=Jun;;
Nov) DELETE_MONTH=Jul;;
Dec) DELETE_MONTH=Aug;;
esac
if [ $DOM -eq '1' ]
then
rm -rf $DUMP_DISK/$DELETE_MONTH
fi
# Unmount the dump disk partition
/sbin/umount $DUMP_DISK
# End of online-dump.sh
|