SVN服务器 与 web服务器 文件同步

来源:互联网 发布:淘宝如何发布话费充值 编辑:程序博客网 时间:2024/05/18 20:08

     为使整个项目开发、测试更加便捷,可利用SVN的hook功能就能实现将SVN服务器上的数据同步到Web服务器。

     思路:  
     找 到SVN Server中的仓库(Repositories)文件夹的位置,在相应的项目文件夹中找到hooks文件夹。在该文件夹中添加一个post- commit文件;当有commit动作发生时(提交到SVN Server时)就会执行这个post-commit文件,在该文件实现数据的复制。  

      实例:  
     环境:SVN Server与测试用的Web Server在同一台Windows系统服务器上,SVN Server使用的是VisualSVN,Web Server使用的是Apache。项      目的名称为test,客户端使用TortoiseSVN。  
     首先在apache的www目录下创建一个文件夹,进行checkout,输入需要用户名和密码,将test项目取出到该文件夹中。  
     找到SVN Server的Repositories目录,在Repositories/test/hooks文件夹中创建post-commit.bat,在其中写入命令:  
    "C:\Program Files\VisualSVN Server\bin\svn.exe" update "D:\www\test" --quiet --username name --password pwd  

   (即执行svn update命令,请自行替换用户名和密码) 

  也可以这样写

@echo off

set REPOS="%1"

set TXN="%2"

"C:\Program Files\Subversion\bin\svn.exe" update "f:\wwwroot" --quiet --username admin --password admin

好了,大功告成。  

可直接点击post-commit.bat 进行测试!

修改提交时遇到的错误:post-commit hook failed (exit code 1) with output:

svn: run 'svn cleanup' to remove locks (type 'svn help cleanup' for details)
svn: E155004: Working copy 'D:\www\Test' locked
svn: E200031: sqlite: attempt to write a readonly database
svn: E200031: sqlite: attempt to write a readonly database

可右键 D:\www\Test  

点击svn-->clean up


TortoiseSVN 提交到 VisualSVN Server 时 hook 的 post-commit.bat 不执行的解决方法:
这是因为 bat 文件执行需要权限,而 VisualSVN Server 默认用的是 NETWORK 用户组,该组没有执行 bat 的权限,导致了 post-commit.bat 文件不能执行,解决方法如下:

我的电脑-管理-服务:
VisualSVN_Server Service
将 VisualSVN Server 服务运行于超级管理员权限,然后重启这个服务。
问题到此解决了~!

参考:http://www.im87.net/topics/visualsvn-server-hook-post-commit-bat/

http://my.oschina.net/yanzhiwei/blog/111089



  
原创粉丝点击