SVN热备份脚本
2011-08-03 徐磊
#!/bin/sh
#########################################################
# Script to do incremental rsync backups
# modidfy: wanjie.info
# date: 2010/06/04
# 这个脚本不是xulei写的,我只是拿来主义,当然如果大家看不明白,可以提问,给予解释
#########################################################
###################################
# svn backup log path
# - This is used to log result
###################################
LogFile=~/tmp/svnbackup/svnback.log
DATE=`date +%Y%m%d`
###################################
# mail address for status updates
# - This is used to email you a status report
###################################
MAILADDR=webmaster@wanjie.info
###################################
# HOSTNAME and project list
# - This is also used for reporting
###################################
ProjectLst=~/tmp/svnbackup/projectlist.txt
###################################
# backup directory
# - This is the path to the backup directory
###################################
BackDir=~/tmp/svnbackup/$DATE
BACKUPDIR=~/tmp/svnbackup/$DATE
###################################
# svn directory
# - This is the path to the directory you want to archive
###################################
SVNDIR=~/svn
###################################
# svnadmin path
# - This is the path to the directory you want to archive
###################################
SVNADMIN=/usr/bin/svnadmin
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
# our actual rsyncing function
# 这个函数主要是在备份日志里面打上时间,用了个前面date命令获取到的日期
do_accounting()
{
echo " " >> $LogFile
echo " " >> $LogFile
echo "###########################" >> $LogFile
echo "$DATE" >> $LogFile
echo "###########################" >> $LogFile
cd $BackDir
}
# do_svndump就是这个脚本最主要的部分,通过使用svnadmin dump命令
# 来进行备份。对于SVN的Repository来说,不同数据仓储是按文件夹的形式
# 进行管理的,备份出来的是xxx.dump,这个文件是相当有用处的,无论你是
# 在linux下恢复配置库,还是windows下恢复都可以使用。脚本里面决定是否进行
# 新的备份,是通过xxx.youngest的日志文件的内容来判断的。
do_svndump()
{
PROJECTLIST=`cat $ProjectLst`
cd $SVNDIR
for project in $PROJECTLIST
do
echo "begin to dump $project databases" >> $LogFile
if [ ! -f $BACKUPDIR/$project.dump ]
then
YOUNGEST=`svnlook youngest $project`
svnadmin dump $project > $BACKUPDIR/$project.dump
echo "OK,dump file successfully!!"
echo "$YOUNGEST" > $BACKUPDIR/$project.youngest
else
echo "$project.dump existed,will do increatment job" >> $LogFile
if [ ! -f $BACKUPDIR/$project.youngest ]
then
echo "error, no youngest check!" >> $LogFile
else
PREVYOUNGEST=`cat $BACKUPDIR/$project.youngest`
NEWYOUNGEST=`svnlook youngest $project`
if [ $PREVYOUNGEST -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/$project-$LASTYOUNGET-$NEWYOUNGEST.$DATE
echo "$NEWYOUNGEST" > $BACKUPDIR/$project.youngest
fi
fi
fi
done
}
# our post rsync accounting function
# 这个就是把你日志文件的内容当做邮件发送
do_mail()
{
mail $MAILADDR -s svn-back_log < $LogFile
}
# some error handling and/or run our backup and accounting
do_accounting && do_svndump && do_mail
-------------------------------------------------------------------------------------------------------
这个是比较麻烦的,要是想简单,可以直接hotcopy之后,然后就tar压缩,不用dump备份,因为dump是相当的花时间的。要是天天都备份的话,就很悲剧。
脚本的衍生就是,你可以把你备份出来的东西放置该机器的ftp上,然后再用其他的机器通过脚本,拷走配置库的备份,因为谁都不知道svn服务器是不是会down掉,要是down掉了,一旦你的备份又是在svn服务器上,那就白备份了。
0
该文章对我有帮助
359°|3568 人阅读|3
条评论
金鑫 2011-08-03
要是在配合 注释 就完美了 呵呵
徐磊 2011-08-03
金鑫: 要是在配合 注释 就完美了 呵呵ok 没问题 重新编辑下
刘旸 2011-08-15
呵呵,还以为是keepalived的脚本呢
请 登录 后发表评论