多功能SVN备份脚本
这个脚本个人觉得比较完美了,SVN完全备份,加增量备份,并将备份出来的数据,同步到另外一台服务器上,而且可以实现实时备份并发邮件通知,历史备份记录想查就查。
这个脚本参考了部分网上的资源。
稍作修改就可以应用到你的实际生产环境了,有问题的话,可以联系我(*^__^*) ……
具体脚本内容如下:
- #!/bin/sh
- #by 崔元荣
- #QQ:295749093
- #svn多功能备份脚本!
- svnbak_remote_dir=/data/192.168.1.7_svn/
- ###################################
- BACKUPDIR=/var/svnbackup
- ###################################
- SVNDIR=/var/svn
- ###################################
- ProjectLst=$BACKUPDIR/projectlist.txt
- ###################################
- LogFile=$BACKUPDIR/svnback.log
- History_LogFile=$BACKUPDIR/history_svnback.log
- DATE=`date +%Y%m%d-%T`
- # - 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 "###########################" >> $LogFile
- echo "$DATE" >> $LogFile
- echo "###########################" >> $LogFile
- echo " " >> $History_LogFile
- echo " " >> $History_LogFile
- echo "###########################" >> $History_LogFile
- echo "$DATE" >> $History_LogFile
- echo "###########################" >> $History_LogFile
- cd $BackDir
- }
- do_svndump()
- {
- PROJECTLIST=`cat $ProjectLst`
- cd $SVNDIR
- for project in $PROJECTLIST
- do
- echo "begin to dump $project databases" >> $LogFile
- echo "begin to dump $project databases" >> $History_LogFile
- if [ ! -f $BACKUPDIR/$project.dump ]
- then
- YOUNGEST=`svnlook youngest $project`
- svnadmin dump $project > $BACKUPDIR/$project.dump
- if [ $? != 0 ];then
- echo "full-backup faild" >> $LogFile
- echo "full-backup faild" >> $History_LogFile
- else
- echo "OK,dump file successfully!!" >> $LogFile
- echo "OK,dump file successfully!!" >> $History_LogFile
- fi
- echo "$YOUNGEST" > $BACKUPDIR/$project.youngest
- else
- echo "$project.dump existed,will do increatment job" >> $LogFile
- echo "$project.dump existed,will do increatment job" >> $History_LogFile
- if [ ! -f $BACKUPDIR/$project.youngest ]
- then
- echo "error, no youngest check!" >> $LogFile
- echo "error, no youngest check!" >> $History_LogFile
- else
- PREVYOUNGEST=`cat $BACKUPDIR/$project.youngest`
- NEWYOUNGEST=`svnlook youngest $project`
- if [ $PREVYOUNGEST -eq $NEWYOUNGEST ]
- then
- echo " no database updated!" >> $LogFile
- echo " no database updated!" >> $History_LogFile
- else
- LASTYOUNGEST=`expr $PREVYOUNGEST + 1`
- echo "last youngest is $LASTYOUNGEST" >> $LogFile
- echo "last youngest is $LASTYOUNGEST" >> $History_LogFile
- svnadmin dump $project --revision $LASTYOUNGEST:$NEWYOUNGEST --incremental > $BACKUPDIR/$project-$LASTYOUNGET-$NEWYOUNGEST.$DATE
- if [ $? != 0 ];then
- echo "zhengliang-backup faild" >> $LogFile
- echo "zhengliang-backup faild" >> $History_LogFile
- else
- echo "$NEWYOUNGEST" > $BACKUPDIR/$project.youngest
- echo "zhengliang-backup sucess!" >> $LogFile
- echo "zhengliang-backup sucess!" >> $History_LogFile
- fi
- fi
- fi
- fi
- done
- }
- do_rsync()
- {
- rsync -avz --partial --progress --delete $BACKUPDIR/* [email protected]:$svnbak_remote_dir
- if [ $? != 0 ]; then
- echo "svnbak 192.168.1.7 rsync to 192.168.1.6 faild!!!" >> $LogFile
- echo "svnbak 192.168.1.7 rsync to 192.168.1.6 faild!!!" >> $History_LogFile
- else
- echo "svnbak 192.168.1.7 rsync to 192.168.1.6 successfully!!" >> $LogFile
- echo "svnbak 192.168.1.7 rsync to 192.168.1.6 successfully!!" >> $History_LogFile
- fi
- }
- do_empty()
- {
- #echo "" > $LogFile
- for project in $PROJECTLIST
- do
- rm -f $BACKUPDIR/$project*
- done
- }
- do_mail()
- {
- cat $LogFile | mutt -s "SVN Backup status!" [email protected]
- }
- #################################################
- case "$1" in
- dump_full)
- do_empty && do_accounting && do_svndump && do_rsync && do_mail
- ;;
- dump_incremental)
- do_accounting && do_svndump && do_rsync && do_mail
- ;;
- *)
- echo $"Usage: $0 {dump_full|dump_incremental}"
- exit 2
- esac
相关推荐
ECSHOP专属建设 2020-11-13
xzjforDream 2020-09-23
fenggit 2020-09-15
起点 2020-08-17
leehbhs 2020-07-26
leehbhs 2020-07-04
pub_svnserve.conf的 pub_authz.conf的配置文件有非法字符的原因引起,需要查找pub_authz.conf提的非法内容比如多余的空格删除或直接将pub_authz.conf
起点 2020-06-28
leehbhs 2020-06-20
dingqinghu 2020-06-16
dengweijunkedafu 2020-06-09
nebulali 2020-05-27
起点 2020-05-10
起点 2020-05-05
83520298 2020-05-04