#!/bin/sh
###################################
# svn backup log path
# - This is used to log result
###################################
LogFile=/backup/svnsync/svnback.log
DATE=`date +%Y%m%d`
###################################
# mail address for status updates
# - This is used to email you a status report
###################################
[email protected]
###################################
# HOSTNAME and project list
# - This is also used for reporting
###################################
ProjectLst=/backup/svnsync/projectlist.txt
###################################
# backup directory
# - This is the path to the backup directory
###################################
BackDir=/backup/svnsync/repository
###################################
# svn directory
# - This is the path to the directory you want to archive
###################################
SVNDIR=/home/svnroot/repository
###################################
# svn command path
# - This is the path to the directory you want to archive
###################################
SVNSYNC=/usr/local/bin/svnsync
SVNLOOK=/usr/local/bin/svnlook
SVNADMIN=/usr/local/bin/svnadmin
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
# our actual rsyncing function
do_echo()
{
touch $hookfile
echo "REPOS="\$1"" >> $hookfile
echo "REV="\$2"" >> $hookfile
echo "USER="\$3"" >> $hookfile
echo "PROPNAME="\$4"" >> $hookfile
echo "ACTION="\$5"" >> $hookfile
chmod 755 $hookfile
}
do_accounting()
{
echo " " > $LogFile
echo " " >> $LogFile
echo "###########################" >> $LogFile
echo "$DATE" >> $LogFile
echo "###########################" >> $LogFile
cd $BackDir
}
do_rsync()
{
PROJECTLIST=`cat $ProjectLst`
for project in $PROJECTLIST
do
projectdata=$SVNDIR/$project
destdir=$BackDir/$project
hookfile="$destdir/hooks/pre-revprop-change"
ssrepo=`$SVNLOOK youngest $projectdata`
dtrepo=`$SVNLOOK youngest $destdir`
#check whether svn repository is existed. if not, then use svnadmin create it.
if [ -d $destdir ]
then
echo "#######################" >> $LogFile
echo "$project" >> $LogFile
echo "#######################" >> $LogFile
echo "checking hooks file" >> $LogFile
if [ -f $hookfile ]
then
chmod 755 $hookfile
else
do_echo
fi
echo "OK, seems we have $project repository,now do init or sync!!" >> $LogFile
echo " " >> $LogFile
echo " " >> $LogFile
else
echo "en.... seems we have no $project repository, now will create it and do init and sync!" >> $LogFile
echo " " >> $LogFile
echo " " >> $LogFile
$SVNADMIN create $destdir
oeo_echo
fi
#check svn version, if 0, then init it.
if [ "$dtrepo" -eq "0" ]
then
$SVNSYNC init file:///$destdir file:///$projectdata
$SVNSYNC sync file:///$destdir
echo "sync $project done into $destdir" >> $LogFile
else
if [ "$ssrepo" -eq "$dtrepo" ]
then
echo "sorry, the repository $project is updated, dont need do it" >> $LogFile
else
$SVNSYNC sync file:///$destdir
echo "sync $project done into $destdir" >> $LogFile
fi
fi
done
}
# our post rsync accounting function
do_mail()
{
mail $MAILADDR -s svn-back_log < $LogFile
}
# run our backup and accounting
do_accounting && do_rsync && do_mail
~