利用SVN更新网站
授权方式:署名,非商业用途,保持一致,转载时请务必以超链接(http://www.fwolf.com/blog/post/127)的形式标明文章原始出处和作者信息及本声明。如果你有一个假设在公网上的SVN服务器,而你的网站所在的主机允许你使用SVN客户端,并且开放了php的exec函数,那么你有福了,你可以利用SVN作为中转,更新你的网站程序。
首先,也是前提,就是你的网站程序是用SVN管理的,那么只要你的网站主机能够访问SVN,就能够使用SVN的update功能来更新程序。
准备工作一:将网站程序加上svn的控制标记,由于SVN的控制信息都存在程序所在目录的.svn子目录中,所以需要找一个空目录,并且将网站现有程序checkout到这个目录里面来,注意是checkout而不是export,因为接下来要将最新的网站程序连同他里面包含的很多个.svn目录一同上传到服务器上去。为了不让.svn目录泄露机密,要在.htaccess文件或者是httpd.conf中设定如下规则,禁止对.svn目录的访问。
Order Allow,Deny
Deny from all
</directory>
准备工作二:作一段小程序,调用服务器上的svn命令行命令,update网站程序,下面是一个写好了的简单例子。
$target_ar['fwolf'] = ‘d:\fwolf’;
//setup commandline
$svn_cmd1 = ‘d:\server\svn\bin\svn.exe update ‘;
$svn_cmd2 = ‘ –username updatebot –password xxxxxx –no-auth-cache’;
//output html string
$html = ”;
//recieve get parameter
$target = isset($_GET['target']) ? $_GET['target'] : ”;
if (empty($target) || !isset($target_ar[$target]))
{
$html = ‘Target does not correct.’;
}
else
{
//execute svn update command
$cmd = $svn_cmd1 . $target_ar[$target] . $svn_cmd2;
$ar = array();
$status = 0;
exec($cmd, $ar, $status);
for ($i=0; $i < count($ar); $i++)
$ar[$i] = htmlspecialchars($ar[$i]);
$html .= ‘Status: ‘ . $status . “<br />\r\n”;
$html .= implode(’<br />’ . “\r\n”, $ar);
}
echo $html;
把这个程序放到服务器上能够访问到的地方,也可以在此基础上加上一些访问限制,那么只要访问这个程序/页面,服务器就会自动更新你的网站啦。
D H:\cvswork\svntest\update_from_svn.php
Updated to revision 44.
这样,在利用SVN很好的管理网站程序的基础上,还实现了服务器程序的很方便的更新,一举两得!尤其是在程序上传不是十分方便的场合,用起来就更舒服了,我就是在更换了一个劣质防火墙,ftp无法正常使用的情况下想出这个怪招儿的:-)。
Update @ 2007-07-31
如果在windows主机上使用本方法,而svn服务器是采用了ssl的https://…地址,那么会遇到一点小麻烦,就是在执行svn update的时候,由于使用的是web的用户,在出现确认证书的提示信息时,用户是无法输入的:
Error validating server certificate for 'https://20070731.fwolf.com':
- The certificate is not issued by a trusted authority. Use the
fingerprint to validate the certificate manually!
Certificate information:
- Hostname: 20070731.fwolf.com
- Valid: from Jul 31 06:49:53 2007 GMT until Jul 28 06:49:53 2017 GMT
- Issuer: Fwolf, US
- Fingerprint: 38:43:0b:29:75:1t:ba:d8:29:8f:94:9a:10:42:a0:fe:ae:93:4d:91
(R)eject, accept (t)emporarily or accept (p)ermanently?
这时就只能用变通的方法了,首先在dos方式中使用svn up,svn会自动缓存身份验证以及ssl确认信息,这些信息保存在C:\Documents and Settings\Administrator\Application Data\Subversion目录下,然后把这个目录整体拷贝到C:\Documents and Settings\Default User\Application Data\Subversion就可以了,测试环境windows2003,并且试过复制到All Users的对应目录无效。
另外修改配置文件servers,添加ssl-trust-default-ca = yes的方式在windows下好像没有作用。
![[Bloglines]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/bloglines.png)
![[co.mments]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/comments.png)
![[del.icio.us]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/digg.png)
![[diigo]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/diigo.png)
![[Facebook]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/facebook.png)
![[Furl]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/furl.png)
![[Google]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/google.png)
![[MySpace]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/myspace.png)
![[Reddit]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/reddit.png)
![[Rojo]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/rojo.png)
![[Slashdot]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/technorati.png)
![[Windows Live]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.fwolf.com/blog/wp-content/plugins/bookmarkify/email.png)
January 19th, 2006 at 2:17:21
[...] [...]
June 3rd, 2007 at 19:36:32
有一点不是很清楚,下面这段不您确定可以放在.htaccess里吧, apache的规则不允许,似乎只能放在httpd.conf里
Order Allow,Deny
Deny from all
[Reply]
June 3rd, 2007 at 19:38:49
有一点不是很清楚,下面这段不您确定可以放在.htaccess里吧, apache的规则不允许,似乎只能放在httpd.conf里
<directory ~ “.svn”>
Order Allow,Deny
Deny from all
</directory>
[Reply]
June 4th, 2007 at 1:02:27
<Directory>是必须放在httpd.conf中使用的但是
可以放在
.htaccess中使用。[Reply]
November 9th, 2007 at 14:27:39
[...] 授权方式:署名,非商业用途,保持一致,转载时请务必以超链接(http://www.fwolf.com/blog/post/127)的形式标明文章原始出处和作者信息及本声明。 [...]
November 22nd, 2007 at 19:18:48
[...] 授权方式:署名,非商业用途,保持一致,转载时请务必以超链接(http://www.fwolf.com/blog/post/127)的形式标明文章原始出处和作者信息及本声明。 [...]
November 25th, 2007 at 23:11:01
[...] 授权方式:署名,非商业用途,保持一致,转载时请务必以超链接(http://www.fwolf.com/blog/post/127)的形式标明文章原始出处和作者信息及本声明。 分类: 网络技术 | 浏览: 16 次 [...]