diff --git a/makefile b/makefile index dea95de..8c67d39 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ # Build a release of 'tbku' using 'make' -# $Id: makefile,v 1.104 2012/06/09 18:07:30 tundra Exp $ +# $Id: makefile,v 1.105 2012/06/09 18:14:29 tundra Exp $ # Requires a modern 'make' like GNU. # Uncomment One Of The Following For Early Releases @@ -13,7 +13,7 @@ ##### PROGNAME = tbku -PROGMAIN = tbku +PROGMAIN = tbku.sh PROGFILES = ${PROGMAIN} # setup.py # Uncomment this if desired for python modules PROGDOCS = ${PROGMAIN}.ps diff --git a/tbku b/tbku new file mode 100755 index 0000000..f413d57 --- /dev/null +++ b/tbku @@ -0,0 +1,156 @@ +#!/bin/sh +# Automated Backup Script For TundraWare Inc. Servers +# Copyright (c) 2004-2008, TundraWare Inc., Des Plaines, IL +# All Rights Reserved. +# For Updates See: http://www.tundraware.com/Software/tbku +# $Id: tbku,v 1.1 2012/06/09 18:14:29 tundra Exp $ + + +##### +# Things User May Want To Change +##### + +### +# Program Locations +### + +# Try to figure out where things are on this particular +# system. If you can't, default to FreeBSD settings. + +DATE=`which date` +LS=`which ls` +SED=`which sed` +TAR=`which tar` +TOUCH=`which touch` +UNAME=`which uname` + +DATE=${DATE:-"/bin/date"} +LS=${LS:-"/bin/ls"} +SED=${SED:-"/usr/bin/sed"} +TAR=${TAR:-"/usr/bin/tar"} +TOUCH=${TOUCH:-"/usr/bin/touch"} +UNAME=${UNAME:-"/usr/bin/uname"} + +### +# Default Directories +### + +# You can override with corresponding environment +# variable or change the default value here. + +BKUDIR=${TBKUDIR:-"/bku"} # Where to write the backup files +FILESETDIR=${TBKUSETS:-"$HOME/tbku"} # Where to find fileset files + +### +# Tape Device +### + +TAPEDEV=${TBKUTAPE:-"/dev/sa0"} # Default to FreeBSD SCSI tape + +### +# File Naming +### + +DATETIME=-`${DATE} "+%Y%m%d"` # Datestamp used to uniquely ID backups +MACHINE=`${UNAME} -n`- # Name of the machine we're on +OSTYPE=`${UNAME} -s`- # Operating System Type +OSREV=`${UNAME} -r`- # Operating System Revision Level +HWTYPE=`${UNAME} -p` # Processor Type + +BKUNAME=${MACHINE}${OSTYPE}${OSREV}${HWTYPE} # Backup base name +BKUNAME=${TBKUNAME:-$BKUNAME} # But the user can override it + +#### +# Automatic Deletion Of Previous Backups +#### + +# Use this with caution! + +BKUDEL=${TBKUDEL:-"NO"} # Must be "YES" for autodelete + + +############## Nothing Below Should Need To Be Changed ############# + + +ALLSETS="allsets" # Special name to force every backup set to be done +COMMON="auto" # Common name for automated backups + +##### +# Setup +##### + +umask 077 # Make sure only owner can read backups +mkdir -p ${BKUDIR} # Make sure the backup directory exists + + +##### +# Figure Out Which Backup Sets To Do +##### + +cd $FILESETDIR + +if [ $# -ne 0 ] +then + if [ _$1 = _$ALLSETS ] + then + LIST=`${LS} * 2>/dev/null` + else + for arg in $* + do + a=`${LS} *${arg} 2>/dev/null` + LIST=$LIST" $a" + done + fi + +else + LIST=`${LS} $COMMON* 2>/dev/null` +fi + + +##### +# Do The Actual Backups, And Leave Indication Of Start/Stop Times For Each Backup Set +##### + + +# If nothing matches / there is nothing to do, tell the user + +LST=`echo $LIST | ${SED} "s/\ //"` # Get rid of spaces from concatenation above +if [ "_${LST}" = "_" ] +then + echo "tbku: Nothing to do! Exiting ..." + exit +fi + + +# Otherwise process each fileset + +for x in $LIST +do + s=`echo $x | ${SED} "s/.*\.//"` # Get the suffix + + BASENAME=$BKUNAME-$s + STAMPEDNAME=${BASENAME}${DATETIME} + + ##### + # Distinguish Between Tape And File Backups + ##### + + if [ "_${s}" = "_tape" ] + then + FULLNAME=$TAPEDEV + else + FULLNAME=$BKUDIR/$STAMPEDNAME.tar.gz + fi + + # Optionally, get rid of previous backups of this fileset + + if [ _${TBKUDEL} = "_YES" ] + then + rm $BKUDIR/.$BASENAME* $BKUDIR/$BASENAME* + fi + + echo "Now Doing Backup Set: $s" + ${TOUCH} $BKUDIR/.$STAMPEDNAME-begin + ${TAR} -cvzT $FILESETDIR/$x -f $FULLNAME >$BKUDIR/$STAMPEDNAME.log 2>&1 + ${TOUCH} $BKUDIR/.$STAMPEDNAME-end +done