SVN作为我们的版本管理库,记录着我们在整个项目过程中的变更和修改,对整个项目的生命流程有着重要的意义,所以,做好备份,不让数据在不可预料的情况下丢失,是非常重要而迫切的。
SVN备份策略:
1) 完全备份 每周一次
2) 增量备份 每天一次
3) 实时同步 项目没有需求,所以不做
1)项目列表
##############################################
#
# Write Repository Name in here 2009-12-03
# Author: ******
#
##############################################
#Document Repository
svndocrepos
#SourceCode Repository
svnsrcrepos
2)完全备份
fullbackup.sh
#/bin/bash
#
#Full Backup SVN Repository on 2009-12-03
# Author:******
#Subversion Home
SVN_HOME=/usr/local/subversion
#Backup Directory
BACKUP_DIR=/backup/svnrepos/weekly
#Log Directory
LOG_PATH=/backup/svnrepos/log
#Backup Date
DATE=`date +%Y%m%d`
#Backup Time
TIME=`date +%T`
#Project File
PROJLST=/svnrepos/script/project.lst
#SVNADMIN Command Path
SVNADMIN=$SVN_HOME/bin/svnadmin
#Project List
LIST=`cat $PROJLST | grep -v "#" | awk 'NF'`
#Read the Project Name in Project List
for PROJNAME in $LIST
do
#如果你的仓库都在一个目录下面,就不需要这个判断
echo "The Project Name is $PROJNAME." >> $LOG_PATH/Fullbackup_$PROJNAME"_"$DATE.log
echo "The SVN directory is $SVN_ROOT." >>$LOG_PATH/Fullbackup_$PROJNAME"_"$DATE.log
#Require the newest version
VERSION=`$SVN_HOME/bin/svnlook youngest $SVN_ROOT/$PROJNAME`
echo "The current version is $VERSION." >> $LOG_PATH/Fullbackup_$PROJNAME"_"$DATE.log
FILENAME=$PROJNAME"_"$DATE"_"$VERSION.tar.bz2
#Check if the backup file exist or not
if [ -f $BACKUP_DIR/$FILENAME ]
then echo "Backup file $FILENAME is already exist $DATE $TIME." >> $LOG_PATH/Fullbackup_$PROJNAME"_"$DATE.log
else
#Start hotcopy backup
echo "Start Backup the SVN repository $PROJNAME $DATE $TIME" >> $LOG_PATH/Fullbackup_$PROJNAME"_"$DATE.log
$SVNADMIN hotcopy $SVN_ROOT/$PROJNAME --clean-logs $BACKUP_DIR/$PROJNAME
#Require the version for backup project
BAKVER=`$SVN_HOME/bin/svnlook youngest $BACKUP_DIR/$PROJNAME`
echo "The backup version of $PROJNAME is $BAKVER $DATE $TIME." >> $LOG_PATH/Fullbackup_$PROJNAME"_"$DATE.log
#Test if the backup is success
if [ $BAKVER = $VERSION ]
then
cd $BACKUP_DIR
tar cjf $FILENAME $PROJNAME
rm -fr $BACKUP_DIR/$PROJNAME
# echo "VERSION" > $LOG_PATH/$PROJNAME"_"last_revision.txt
echo "Full Backup Successful $DATE $TIME!!!" >> $LOG_PATH/Fullbackup_$PROJNAME"_"$DATE.log
else
echo "Full Backup failed $DATE $TIME." >> $LOG_PATH/Fullbackup_$PROJNAME"_"$DATE.log
fi
fi
#Upload to file server
HOST=10.253.125.62
echo "Start upload backup files $DATE `date +%T`......" |tee -a $LOGFILE
lftp -u wmsvn,wmsvn $HOST -e "cd /svnroot/$PROJNAME && lcd $BACKUP_DIR && put $FILENAME && bye" |tee -a $LOGFILE
echo "End upload backup files successful $DATE `date +%T`" |tee -a $LOGFILE
done
3)增量备份
increbackup.sh
#/bin/bash
#
#Increment Backup SVN Repository on 2009-12-03
#
#Subversion Home
SVN_HOME=/usr/local/subversion
#Backup Directory
BACKUP_DIR=/backup/svnrepos/daily
#Log Directory
LOG_PATH=/backup/svnrepos/log
#Backup Date
DATE=`date +%Y%m%d`
#Backup Time
TIME=`date +%T`
#Project File
PROJLST=/svnrepos/script/project.lst
#SVNADMIN Command Path
SVNADMIN=$SVN_HOME/bin/svnadmin
#Project List
LIST=`cat $PROJLST | grep -v "#" | awk 'NF'`
#Read the Project Name in Project List
for PROJNAME in $LIST
do
#如果你的仓库都在一个目录下面,就不需要这个判断
LOGFILE=$LOG_PATH/Increbackup_$PROJNAME"_"$DATE.log
VERFILE=$LOG_PATH/$PROJNAME"_"last_revision.txt
echo "The Project Name is $PROJNAME." | tee $LOGFILE
echo "The SVN directory is $SVN_ROOT." | tee -a $LOGFILE
LOWER=0
UPPER=0
#Require the newest version
VERSION=`$SVN_HOME/bin/svnlook youngest $SVN_ROOT/$PROJNAME`
echo "The current version is $VERSION." | tee -a $LOGFILE
UPPER=$VERSION
#Require the last backup version
if [ -f $VERFILE ]
then echo "Require the last version from file $VERFILE $DATE $TIME." | tee -a $LOGFILE
LOWER=`cat $VERFILE`
LOWER=`expr $LOWER + 1`
else
LOWER=$LOWER
fi
#Check if it need to backup or not
if [ $UPPER -le $LOWER ];then
echo "The $PROJNAME Repository newest version is $UPPER, last backup version is `expr $LOWER - 1`, it did not need to backup $DATE $TIME" |tee -a $LOGFILE
continue
fi
#Start Increment Backup
FILENAME=$PROJNAME"_"$DATE"_"$LOWER"_"$UPPER.tar.bz2
DMPFILE=$BACKUP_DIR/$PROJNAME"_"$DATE"_"$LOWER"_"$UPPER.dmp
echo "Start Increment Backup the SVN repository $PROJNAME from $LOWER to $UPPER $DATE $TIME" | tee -a $LOGFILE
$SVNADMIN dump $SVN_ROOT/$PROJNAME -r $LOWER:head --incremental > $DMPFILE
#Test if the backup is success
if [ -f $DMPFILE ]
then
cd $BACKUP_DIR
echo "Start compress the dmp file $DMPFILE......" |tee -a $LOGFILE
tar cjf $FILENAME $PROJNAME"_"$DATE"_"$LOWER"_"$UPPER.dmp
echo "Delete the dmp file $DMPFILE...... " |tee -a $LOGFILE
rm -fr $BACKUP_DIR/$PROJNAME"_"$DATE"_"$LOWER"_"$UPPER.dmp
echo "$UPPER" > $VERFILE
echo "Increment Backup Successful $DATE $TIME!!!" |tee -a $LOGFILE
else
echo "Increment Backup failed $DATE $TIME." |tee -a $LOGFILE
fi
#Upload to file server
HOST=10.253.125.62
echo "Start upload backup files $DATE `date +%T`......" |tee -a $LOGFILE
lftp -u wmsvn,wmsvn $HOST -e "cd /svnroot/$PROJNAME && lcd $BACKUP_DIR && put $FILENAME && bye" |tee -a $LOGFILE
echo "End upload backup files successful $DATE `date +%T`" |tee -a $LOGFILE
done
加到crontab上:crontab -e
0 1 * * * sh /svnrepos/script/increbackup.sh >>/backup/svnrepos/log/crontab_backup.log
0 3 * * 5 sh /svnrepos/script/fullbackup.sh >>/backup/svnrepos/log/crontab_backup.log
还没有加上存放到其他服务器上的备份,没有拿到FTP服务器,后续更新。
做好备份,就可以高枕无忧了,每个月做一次恢复测试就OK了。
已经加上ftp上传的部分,算是完整了。
阅读(2042) | 评论(0) | 转发(0) |