#!/bin/ksh
#prints usage
usage()
{
echo "$VERSION"
echo "
Usage: `basename $0` [command] [MEB options]
Commands:
full make full backup
incremental make incremental backup
incremental-with-redo-log-only make incremental backup with redo log only
verify-to-tape verify backup images, then copy to tape
prepare prepare backups
remove-old remove old backups
"
}
# creates defaults values
initialize()
{
VERSION=0.3
MEBOPTIONS=
CURDATE=`date +%y%m%d_%H%M%S`
#pre-defined defaults, can be overriden
dMYSQLBACKUP="/service/mysql/bin/mysqlbackup"
dBACKUPDIR=$HOME/BACKUPDIR
dINCREMENTALDIR=$HOME/INCREMENTALDIR
dPREPAREDDIR=$HOME/PREPAREDDIR
dLOGDIR=$HOME/log
dBACKUPIMAGENAME=backup
dOUTLOG=backup_output.log
dERRORLOG=backup_error.log
dVERIFYTIME=42
dPREPARETIME=7
dREMOVETIME=180
#clean failed backups
dCLEANUP=0
}
#parses options
parse_options()
{
if [ -z "$1" ]
then
usage
exit 1
fi
case $1 in
full) COMMAND=do_full;;
incremental) COMMAND=do_incremental;;
incremental-with-redo-log-only) COMMAND=do_incremental_with_redo_log_only;;
verify-to-tape) COMMAND=do_verify_to_tape;;
prepare) COMMAND=do_prepare;;
remove-old) COMMAND=do_remove_old;;
*) usage; exit 1;;
esac
shift
MEBOPTIONS=$@
#setting environment variables
if [ -z $MYSQLBACKUP ]
then
MYSQLBACKUP=`which mysqlbackup`
if [ -z $MYSQLBACKUP ]
then
MYSQLBACKUP=$dMYSQLBACKUP
fi
fi
if [ -z $BACKUPDIR ]
then
BACKUPDIR=${dBACKUPDIR}
fi
if [ -z $INCREMENTALDIR ]
then
INCREMENTALDIR=${dINCREMENTALDIR}
fi
if [ -z $PREPAREDDIR ]
then
PREPAREDDIR=$dPREPAREDDIR
fi
if [ -z $LOGDIR ]
then
LOGDIR=$dLOGDIR
fi
if [ -z $BACKUPIMAGENAME ]
then
BACKUPIMAGENAME=${dBACKUPIMAGENAME}.${CURDATE}.bki
fi
if [ -z $OUTLOG ]
then
OUTLOG=${dOUTLOG}.${CURDATE}
fi
if [ -z $ERRORLOG ]
then
ERRORLOG=${dERRORLOG}.${CURDATE}
fi
if [ -z $VERIFYTIME ]
then
VERIFYTIME=$dVERIFYTIME
fi
if [ -z $PREPARETIME ]
then
PREPARETIME=$dPREPARETIME
fi
if [ -z $REMOVETIME ]
then
REMOVETIME=$dREMOVETIME
fi
if [ -z $CLEANUP ]
then
CLEANUP=$dCLEANUP
fi
}
#cleans up failed backups
cleanup()
{
result=$?
if [[ 0 -ne $result ]]
then
echo "Backup failed"
if [[ 1 -eq $CLEANUP ]]
then
echo "Environment variable CLEANUP set, removing corrupted backup image"
rm -f $1
fi
exit 1;
else
echo "Backup successful"
fi