egscripts/egsvndump/egsvndump

118 lines
No EOL
2.8 KiB
Bash
Executable file

#!/bin/bash
#
# a script to dump a complete remote subversion repository and make periodic
# backups...
# Copyright 2004, David Lane for Egressive Limited, www.egressive.com
#
EMAIL=dlane@egressive.com
SUBJECT="Apu Subversion Dump"
BUROOT=egsvnrepos
BUDIR=/extra/subversion
REPOS=/home/sites/subversion/egressive
VERBOSE=1
#
# Defaults
#
# default email address to which to send backup reports
LOG=/var/log/svnDump.log
BUOLD=$BUROOT-prev.gz
BUOLDRPT=$BUROOT-prev.report
BUCUR=$BUROOT-current.gz
BUCURRPT=$BUROOT-current.report
DATE=`date '+%Y-%m-%d-%a'`
# determine today's date
TIME=`date '+%H-%M-%S'`
# email program
MAIL=/bin/mail
# temporary holding point for email
TMP_EMAIL=/tmp/tmp_email.$DATE_$TIME
#
SVNADMIN=/usr/bin/svnadmin
SVNARGS="dump"
GZIP=/bin/gzip
GZARGS="-f -"
#
# function to direct a message...
message() {
#
# a timestamp for logging purposes
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
echo "$0: $TIMESTAMP $@" >> $LOG
if test -f $TMP_EMAIL ; then
echo "$0: $TIMESTAMP $@" >> $TMP_EMAIL
fi
verbose "$TIMESTAMP $@"
}
#
# create the temporary email file
create_tmp_email() {
touch $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "created temporary email $TMP_EMAIL"
else
message "failed to create temporary email $TMP_EMAIL"
fi
}
#
# send the contents of the temporary file to the
# designated report recipient
send_email_report() {
if test -f $TMP_EMAIL ; then
message "sending email report to $EMAIL"
$MAIL -s "$SUBJECT" $EMAIL < $TMP_EMAIL
rm $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "failed to remove temporary email $TMP_EMAIL"
else
message "successfully removed temporary email $TMP_EMAIL"
fi
message "email report successfully sent"
fi
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $LOG
verbose ""
}
#
# function to direct a message...
verbose() {
if test $VERBOSE = 1 ; then
echo "$@"
fi
}
#
# whack the date on there
EMAIL_SUBJ="$EMAIL_SUBJ on $DATE"
#
# Do the actual dump...
#
# start the email
create_tmp_email
#
# first, remove the previous backup...
if test -f $BUDIR/$BUOLD ; then
message "removing old backup, $BUOLD"
rm $BUDIR/$BUOLD
rm $BUDIR/$BUOLDRPT
else
message "there's no $BUOLD to remove..."
fi
#
# then move current backup to old
if test -f $BUDIR/$BUCUR ; then
message "moving $BUCUR to $BUOLD"
mv $BUDIR/$BUCUR $BUDIR/$BUOLD
mv $BUDIR/$BUCURRPT $BUDIR/$BUOLDRPT
else
message "there's no $BUCUR to shift to $BUOLD..."
fi
#
# now create the actual dump!
COMMAND="$SVNADMIN $SVNARGS $REPOS | $GZIP $GZARGS > $BUDIR/$BUCUR"
message "running the following backup: $COMMAND"
$SVNADMIN $SVNARGS $REPOS | $GZIP $GZARGS > $BUDIR/$BUCUR 2>&1 $BUDIR/$BUCURRPT
#
# done with the backup, now send the report...
send_email_report