1. 程式人生 > >SVN 鉤子操作-同步更新web目錄

SVN 鉤子操作-同步更新web目錄

checkout authent ica color 創建 epo 功能 src www

一個簡單的鉤子演示:也可以網上搜索其他高級的

本次想要達到的功能是:每次用戶commit 到倉庫後,倉庫的鉤子會自動把程序又更新的www/的web發布目錄

1.現在web目錄下創建一個test.com網站目錄

[root@wentao13 ~]# cd /var/www/html/
[root@wentao13 html]# svn checkout svn://localhost/test.com
Authentication realm: <svn://localhost:3690> 59865037-2557-40be-aa97-d460f66b4c60
Password for
root: Authentication realm: <svn://localhost:3690> 59865037-2557-40be-aa97-d460f66b4c60 Username: wentao Password for wentao: ----------------------------------------------------------------------- ATTENTION! Your password for authentication realm: <svn://localhost:3690> 59865037-2557-40be-aa97-d460f66b4c60
can only be stored to disk unencrypted! You are advised to configure your system so that Subversion can store passwords encrypted, if possible. See the documentation for details. You can avoid future appearances of this warning by setting the value of the store-plaintext-passwords option to either
yes or no in /root/.subversion/servers. ----------------------------------------------------------------------- Store password unencrypted (yes/no)? y A test.com/2.txt A test.com/3.txt A test.com/test.php A test.com/1.php Checked out revision 8. [root@wentao13 html]#

按照提示需要輸入root 密碼,和svn授權用戶名和密碼

然後配置hook文件夾的腳本

[root@wentao13 hooks]# pwd
/root/svnRepo/test.com/hooks
[root@wentao13 hooks]# ll
total 36
-rw-r--r--. 1 root root 1977 Mar 29 08:59 post-commit.tmpl
-rw-r--r--. 1 root root 1638 Mar 29 08:59 post-lock.tmpl
-rw-r--r--. 1 root root 2289 Mar 29 08:59 post-revprop-change.tmpl
-rw-r--r--. 1 root root 1567 Mar 29 08:59 post-unlock.tmpl
-rw-r--r--. 1 root root 3426 Mar 29 08:59 pre-commit.tmpl
-rw-r--r--. 1 root root 2434 Mar 29 08:59 pre-lock.tmpl
-rw-r--r--. 1 root root 2786 Mar 29 08:59 pre-revprop-change.tmpl
-rw-r--r--. 1 root root 2122 Mar 29 08:59 pre-unlock.tmpl
-rw-r--r--. 1 root root 2780 Mar 29 08:59 start-commit.tmpl
[root@wentao13 hooks]# 

把下面的鉤子文件模板改成可執行文件

[root@wentao13 hooks]# cp post-commit.tmpl post-commit
[root@wentao13 hooks]# chmod +x post-commit
[root@wentao13 hooks]# 

vim post-commit 添加下面內容:

export LANG=en_US.UTF-8
/usr/bin/svn update /var/www/html/test.com --username wentao --password 123456

技術分享圖片

網站發布目錄同步更新

技術分享圖片

SVN 鉤子操作-同步更新web目錄