다기 능 SVN 백업 스 크 립 트 공유

이 스 크 립 트 는 개인 적 으로 완벽 하 다 고 생각 합 니 다. SVN 은 완전히 백업 하고 증분 백업 을 하 며 백업 한 데 이 터 를 다른 서버 에 동기 화 할 수 있 습 니 다. 또한 실시 간 백업 과 메 일 알림 을 실현 할 수 있 습 니 다. 역사 백업 기록 을 찾 고 싶 으 면 찾 아 보 세 요.
이 스 크 립 트 는 일부 인터넷 자원 을 참고 했다.
조금 만 수정 하면 실제 생산 환경 에 적용 할 수 있 습 니 다. 문제 가 있 으 면 연락 주세요 (* ^ ^ *)...
구체 적 인 스 크 립 트 내용 은 다음 과 같 습 니 다.
   
   
   
   
  1. #!/bin/sh  
  2. #by 崔元荣
  3. #QQ:295749093 
  4. #svn多功能备份脚本! 
  5. svnbak_remote_dir=/data/192.168.1.7_svn/   
  6.  
  7. ###################################  
  8. BACKUPDIR=/var/svnbackup  
  9.  
  10. ###################################  
  11. SVNDIR=/var/svn  
  12.  
  13. ###################################  
  14. ProjectLst=$BACKUPDIR/projectlist.txt  
  15.  
  16. ###################################  
  17. LogFile=$BACKUPDIR/svnback.log  
  18. History_LogFile=$BACKUPDIR/history_svnback.log  
  19. DATE=`date +%Y%m%d-%T`  
  20.  
  21. # - This is the path to the directory you want to archive  
  22. ###################################  
  23. export PATH=$PATH:/bin:/usr/bin:/usr/local/bin  
  24.  
  25. # our actual rsyncing function 
  26. do_accounting()  
  27. {  
  28.     echo " " > $LogFile  
  29.         echo " " >> $LogFile  
  30.         echo " " >> $LogFile  
  31.         echo "###########################" >> $LogFile  
  32.         echo "$DATE" >> $LogFile  
  33.         echo "###########################" >> $LogFile  
  34.  
  35.         echo " " >> $History_LogFile  
  36.         echo " " >> $History_LogFile  
  37.         echo "###########################" >> $History_LogFile  
  38.         echo "$DATE" >> $History_LogFile  
  39.         echo "###########################" >> $History_LogFile  
  40.  
  41.         cd $BackDir  
  42. }  
  43.  
  44. do_svndump()  
  45. {  
  46.    PROJECTLIST=`cat $ProjectLst`  
  47.    cd $SVNDIR  
  48.    for project in $PROJECTLIST  
  49.           do  
  50.           echo "begin to dump $project databases" >> $LogFile  
  51.           echo "begin to dump $project databases" >> $History_LogFile  
  52.                 if [ ! -f $BACKUPDIR/$project.dump ]  
  53.                 then 
  54.                 YOUNGEST=`svnlook youngest $project`  
  55.                 svnadmin dump $project > $BACKUPDIR/$project.dump  
  56.                   if [ $? != 0 ];then 
  57.                 echo "full-backup faild" >> $LogFile  
  58.                 echo "full-backup faild" >> $History_LogFile   
  59.                     else 
  60.                         echo "OK,dump file successfully!!" >> $LogFile  
  61.                         echo "OK,dump file successfully!!" >> $History_LogFile   
  62.                       fi  
  63.                 echo "$YOUNGEST" > $BACKUPDIR/$project.youngest  
  64.                 else 
  65.                         echo "$project.dump existed,will do increatment job" >> $LogFile  
  66.                         echo "$project.dump existed,will do increatment job" >> $History_LogFile   
  67.                         if [ ! -f $BACKUPDIR/$project.youngest ]  
  68.                         then 
  69.                         echo "error, no youngest check!" >> $LogFile  
  70.                         echo "error, no youngest check!" >> $History_LogFile  
  71.                         else 
  72.                                 PREVYOUNGEST=`cat $BACKUPDIR/$project.youngest`  
  73.                                 NEWYOUNGEST=`svnlook youngest $project`  
  74.                                 if [ $PREVYOUNGEST -eq $NEWYOUNGEST ]  
  75.                                 then 
  76.                                         echo " no database updated!" >> $LogFile  
  77.                                         echo " no database updated!" >> $History_LogFile  
  78.                                 else 
  79.                                         LASTYOUNGEST=`expr $PREVYOUNGEST + 1`  
  80.                                         echo "last youngest is $LASTYOUNGEST" >> $LogFile  
  81.                                         echo "last youngest is $LASTYOUNGEST" >> $History_LogFile  
  82.                                         svnadmin dump $project --revision $LASTYOUNGEST:$NEWYOUNGEST --incremental > $BACKUPDIR/$project-$LASTYOUNGET-$NEWYOUNGEST.$DATE  
  83.                                           if [ $? != 0 ];then 
  84.                                              echo "zhengliang-backup faild" >> $LogFile  
  85.                                              echo "zhengliang-backup faild" >> $History_LogFile  
  86.                                                else 
  87.                                                     echo "$NEWYOUNGEST" > $BACKUPDIR/$project.youngest  
  88.                                                     echo "zhengliang-backup sucess!" >> $LogFile  
  89.                                                     echo "zhengliang-backup sucess!" >> $History_LogFile  
  90.                                                    fi  
  91.                                 fi  
  92.                         fi  
  93.   fi  
  94.         done  
  95. }  
  96.  
  97.  
  98. do_rsync()  
  99. {  
  100. rsync -avz --partial --progress --delete $BACKUPDIR/* [email protected]:$svnbak_remote_dir  
  101. if [ $? != 0 ]; then 
  102.     echo "svnbak 192.168.1.7 rsync to 192.168.1.6 faild!!!" >> $LogFile  
  103.     echo "svnbak 192.168.1.7 rsync to 192.168.1.6 faild!!!" >> $History_LogFile   
  104. else 
  105.     echo "svnbak 192.168.1.7 rsync to 192.168.1.6 successfully!!" >> $LogFile  
  106.     echo "svnbak 192.168.1.7 rsync to 192.168.1.6 successfully!!" >> $History_LogFile   
  107. fi  
  108. }  
  109.  
  110. do_empty()  
  111. {  
  112. #echo "" > $LogFile  
  113. for project in `cat $ProjectLst`  
  114. do  
  115.     rm -f $BACKUPDIR/$project*  
  116. done  
  117. }  
  118.  
  119. do_mail()  
  120. {  
  121. cat $LogFile | mutt -s "SVN Backup status!" [email protected]  
  122. }  
  123. #################################################  
  124.  
  125. case "$1" in 
  126.     dump_full)  
  127.         do_empty && do_accounting && do_svndump && do_rsync && do_mail  
  128.         ;;  
  129.     dump_incremental)  
  130.         do_accounting && do_svndump && do_rsync && do_mail  
  131.         ;;  
  132.     *)  
  133.         echo $"Usage: $0 {dump_full|dump_incremental}" 
  134.         exit 2  
  135. esac  

 

좋은 웹페이지 즐겨찾기