由开发提交到测试环境,经测试,在由运维统一上线。试验需求一台测试服务器,一台线上(生产环境)服务器。测试服务器上跑svn是开发用于代码管理,而线上跑的svn是运维用来代码上线的。结合rsync保持测试端的代码与 svn的线上控制端(线上svn,在测试服务器上的一个workcopy)的代码保持一致。开发结合运维,并由运维周期性的提交代码,如果有问题,回滚,保证线上正常!!
svn服务器上chackout 一个workcopy 在用户端:(注意防火墙)
[root@v03-svn-client ~]# svn co svn://192.168.1.35/webtest client_webtest
Authentication realm: <svn://192.168.1.35:3690> 18ab87c6-8455-4174-a313-7b6fd3775a73
Password for 'root':
Authentication realm: <svn://192.168.1.35:3690> 18ab87c6-8455-4174-a313-7b6fd3775a73
Username: svnadmin
Password for 'svnadmin':
Authentication realm: <svn://192.168.1.35:3690> 18ab87c6-8455-4174-a313-7b6fd3775a73
Username: user01
Password for 'user01':
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<svn://192.168.1.35:3690> 18ab87c6-8455-4174-a313-7b6fd3775a73
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)? yes
A client_webtest/default.html
A client_webtest/default1.html
A client_webtest/k.txt
A client_webtest/index.html
A client_webtest/index.php
Checked out revision 40.
[root@v03-svn-client ~]# tree client_webtest/
client_webtest/
├── default1.html
├── default.html
├── index.html
├── index.php
└── k.txt
0 directories, 5 files
[root@v01-svn-test-server www]# svn co svn://192.168.1.35/online
上面的一条命令是在网站根目录下check out 个workcopy (online)同时新建一个目录localsvn,同过rsync同步online(除.svn)的所欲文件 到localsvn
[root@v01-svn-test-server www]# ls
authz index.php online phpwind rsync_test.sh webtest
index.html localsvn passwd project svnserve.conf
[root@v01-svn-test-server www]# svn co svn://192.168.1.65/webtest localsvn#从线上的svn服务器上chackout个文化workcopy 并重命名为localsvn 为以后网线上提价代码用
编写svn(测试服务器上) 钩子代码:
[root@v01-svn-test-server hooks]# ls
post-commit post-unlock.tmpl pre-unlock.tmpl
post-commit.tmpl pre-commit.tmpl start-commit.tmpl
post-lock.tmpl pre-lock.tmpl
post-revprop-change.tmpl pre-revprop-change.tmpl
[root@v01-svn-test-server hooks]# pwd
/svn/webtest/hooks
[root@v01-svn-test-server www]# cd /svn/webtest/hooks/
[root@v01-svn-test-server hooks]# vi post-commit
REPOS="$1"
REV="$2"
SVN=/usr/bin/svn
LOCALSVN=/alidata/www/localsvn
WEB=/alidata/www/online
RSYNC=/usr/bin/rsync
LOG=/alidata/log/svn/svn.log
export LANG=en_US.UTF-8
$SVN update $WEB --username user01 --password 123
if [ $? == 0 ];then
echo "" >>$LOG
echo `date` >>$LOG
echo "############################" >>$LOG
$RSYNC -vr --exclude=".svn" --delete $WEB/ $LOCALSVN >>$LOG
fi
#rsync 参数--exclude =".svn" 是除.svn都同步;--delete 删除目标目录的在源目录中不存在的文件,保证目标目录与源目录保持一致(这一点很关键!!)
[root@v03-svn-client client_webtest]# pwd
/root/client_webtest
[root@v03-svn-client client_webtest]# echo "客服端提交代码到svn服务上">> test.txt
[root@v03-svn-client client_webtest]# cat test.txt
客服端提交代码到svn服务上
[root@v03-svn-client client_webtest]# svn status
? test.txt
[root@v03-svn-client client_webtest]# svn add test.txt
A (bin) test.txt
[root@v03-svn-client client_webtest]# svn ci -m "客服端添加文件" test.txt
Adding (bin) test.txt
Transmitting file data .
Committed revision 43.
[root@v01-svn-test-server online]# svn status
[root@v01-svn-test-server online]# cat test.txt
客服端提交代码到svn服务上
[root@v01-svn-test-server online]# # 代码成功同步到测试环境