#!/bash/sh
###########################################
#this script is used for svn repository backup
#written:carywu
#date:2008/11/21
###########################################
###########################################
#mail address for status updates
# -this is used to email you a status report
###########################################
###########################################
#backup directory,please change it
# - this is the path to the backup directory
BACKUPDIR=/svnroot/svnback
###########################################
#svn repository directory,please change it.
# - this is the path to the directory you want to archive
###########################################
SVNDIR=/SVNROOT/repository
###########################################
#HOSTNAME and project list
# - this is also used for reporting
###########################################
projectlst=$BACKUPDIR/projectlist.txt
###########################################
#svn backup log path and date
# - this is used to log result
###########################################
LOGfile=$BACKUPDIR/SVNBACK.log
DATE='date +%y%m%d-%t
###########################################
#svn command path
# -this is the path to the directory you want to archive
###########################################
export PATH=$PATH:/bin:/USR/bin:/usr/local/bin
#our actual rsyncing function
do_accounting()
{
echo " " >> $logfile
echo " " >> $logfile
echo "#############################" >> $logfile
echo "$DATE" >> $Logfile
echo "#############################" >> $logfile
cd $backdir
}
do_svndump()
{
PROJECTLIST='Cat $projectlst
cd $SVNDIR
for project in $projectlist
do
echo "begin to dump $project database" >>logfile
if [ ! -f $BACKUPDIR/$PROJECT.dump ]
then
YOUNGEST='svnlook youngest $project'
svnadmin dump $project > $BACKUPDIR/$project.dump
echo "OK,dump file successfully!!"
echo "$YOUNEST" > $BACKUPDIR/$project.youngest
else
echo "$project.dump existed,will do increatment
job" >> $logfile
if [ ! -f $BACKUPDIR/$project ]
then
echo "error,no youngest check!" >> $logfile
else
PREVYOUNGEST='cat $BACKUPDIR/
$project.youngest
NEWYOUNGEST='SVNLOOK youngest $project'
if [ $PERVYOUNGEST -eq $NEWYOUNGEST ]
then
echo "no database updated!" >>logfile
else
LASTYOUNGEST='expr $PREVYOUNGEST +1
echo "last youngest is $LASTYOUNGEST" >>
$logfile
svnadmin dump $project --revision
$LASTYOUNGEST:$NEWYOUNGEST --incremental >$BACKUPDIR/
echo "$NEWYOUNGEST" >$BACKUPDIR/
$project.youngest
fi
fi
fi
done
}
#our post rsync accounting funcation
do_mail()
{
mail $MAITLADDR -S SVN-back_log < $logfile
}
#some error handling and/or run our backup and accounting
do_accounting && do_svndump && do_mail