linux中SVN鉤子post-commit和rsync實現自動同步資料

來源:互聯網
上載者:User

我們通過之前文章《SVN鉤子簡介和常用鉤子說明》已經知道 ,SVN鉤子實際就是一些shell指令碼。今天我們就通過post-commit鉤子來實現下svn資料更新,藉助rsync實現自動同步資料。
以我們之前建立的版本庫/home/svndata/21yunweinew為例說明。
我們建立一個網站源碼目錄放置我們的程式,實際生產環境中可以是已經存在的web源碼目錄,比如/home/webdata/21yunweinew。
之前我們同步資料會是通過下載或更新命令來實現:

svn co svn://59.46.80.248/21yunweinew /home/webdata/21yunweinew  --user=xxxxxx --password=xxxxxx
如今,我們直接操作svn版本庫上的鉤子,寫指令碼來直接實現資料同步操作。首先,我們進入21yunweinew的鉤子hooks目錄編輯指令碼post-commit如下:

#!/bin/bash
REPOS="$1"
REV="$2"
export  LC_CTYPE="en_US.UTF-8"
export  LC_ALL=
LOGPATH="/home/svn/log"
[ ! -d ${LOGPATH} ]  &&  mkdir -p $LOGPATH
SVN=/usr/bin/svn
$SVN up /home/webdata/21yunweinew --username 21yunwei  --password xxxx  2>&1 >>$LOGPATH
if [ $? -eq 0 ]
  then
     /usr/bin/rsync -az  --delete /home/webdata/21yunweinew /tmp/
fi
 
為了測試,我們將新增的資料放到了/tmp目錄中。通過資料更新查看tmp目錄內容:

[root@servermanager hooks]# ls  /tmp/21yunweinew/ -l
total 160
drwxr-xr-x 4 root root  4096 Aug 30 16:48 branch
-rw-r--r-- 1 root root 33792 Aug 30 16:48 DHCP伺服器的配置1.doc
-rw-r--r-- 1 root root 24576 Aug 30 16:48 DHCP伺服器的配置.doc
-rw-r--r-- 1 root root 34304 Aug 30 16:48 DHCP伺服器的配置二.doc
-rw-r--r-- 1 root root 46592 Aug 30 16:48 DNS伺服器的配置.doc
-rw-r--r-- 1 root root   830 Aug 30 16:48 rsync.sh
drwxr-xr-x 3 root root  4096 Aug 30 16:32 tag
drwxr-xr-x 3 root root  4096 Aug 30 16:48 trunk
注意事項:1,鉤子要給shell指令碼執行許可權。2,指令碼中命令調用最好使用絕對路徑。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.