#!/bin/sh
# # subversion data backup script # by scud http://www.jscud.com # 2005-11-27 # # subversion完整备份的脚本,调整好后使用crontab -e 放到自动执行里面即可. #
#备份日志文件 LogFile=/backup/svn/svnbak.log
DATE=`date +%Y%m%d`
#备份目录 BakDir=/backup/svn/data
#日常备份目录,如果有 DailyDir=/backup/svn/daily
#要备份的项目列表文件,只有项目名 ProjectLst=/backup/svn/project.lst
#所有项目都保存在这个目录下 SvnDir=/var/svn
#svnadmin程序的路径 SVNADMIN=/app/subversion/bin/svnadmin
echo " " >> $LogFile echo " " >> $LogFile echo "-------------------------------------------" >> $LogFile echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile echo "--------------------------" >> $LogFile
cd $BakDir
#读取项目列表 PROJECTLIST=`cat $ProjectLst`
for project in $PROJECTLIST do projectdata=$SvnDir/$project destdir=$BakDir/$project dumpfile=$DATE.$project.tgz if [ -f $BakDir/$dumpfile ] then echo "backup file have exist!" >>$LogFile else
$SVNADMIN hotcopy $projectdata $destdir --clean-logs
tar czvf $dumpfile $destdir >/dev/null rm -fr $project echo "backup $project done into $dumpfile ">>$LogFile
fi ## delete old tgz 此处根据crontab的时间调整,例如一周一次备份,此处保留了5份备份,以前的删除 oldfile="$BakDir/"$(date +%y%m%d --date=’28 days ago’).$project.tgz if [ -f $oldfile ] then rm -f $oldfile >> $LogFile 2>&1 echo "[$oldfile]Delete Old File Success!" >> $LogFile else echo "[$oldfile]No Old Backup File!" >> $LogFile fi done
#delete previous daily backup files cd $DailyDir rm -f *
|