svn dump 全自動備份指令碼

kidking2010發表於2011-12-20

svn dump 全自動備份指令碼

Posted on 2010-09-26 11:24 幻海藍夢 閱讀(116) 評論(0)  編輯  收藏 所屬分類: Linux版本管理 svn dump 全自動備份指令碼

原文:http://carywu.blog.51cto.com/13185/207571
最近要給美國的SVN伺服器做升級,由於這臺伺服器有一定年份了,在本公司也算是個三朝元老,儲存了多少code啊!。為了保險起見,老闆將遷移的工作鄭重的交到我的手上。在欣欣然的同時也顫抖著。
不過還好我已經對其輕車熟路,在新的伺服器上安裝好apache和subversion軟體後,開始著手備份與遷移了。
由於舊伺服器版本太低,沒有svnsync的功能,考慮再三,我選擇使用了svnadmin dump去做備份。
可是有一個問題了,每個庫的版本都有幾萬了,然後伺服器上有十幾個庫,我可沒耐心一個個輸入svnadmin dump去備份它們,那會讓我覺得長夜漫漫,難於睡眠!
管理員的最高境界就是花力氣去懶惰,我很嚮往這個境界。所以,我花了些時間寫了個shell,就讓系統自己去幹這些事情吧!

shell功能:
只需要大家修改源庫所在的目錄,和備份存放的目錄就可以了。
第一次執行會全部備份,然後以後每次執行會增量備份。
所以,恢復的時候,先恢復全部備份,然後依次按照日期恢復增量備份即可。

#!/bin/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
###################################
MAILADDR=carywu@yahoo.cn

###################################
# 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 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

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23141985/viewspace-713635/,如需轉載,請註明出處,否則將追究法律責任。

相關文章