同步程序思路:用户提交程序到SVN,SVN触发hooks,按不同的hooks进行处理,这里用到的是post-commit,利用post-commit到代码检出到SVN服务器的本地硬盘目录,再通过rsync同步到远程的WEB服务器上。
知识点:
1、SVN的hooks
# start-commit 提交前触发事务
# pre-commit 提交完成前触发事务
# post-commit 提交完成时触发事务
# pre-revprop-change 版本属性修改前触发事务
# post-revprop-change 版本属性修改后触发事务
通过上面这些名称编写的脚本就就可以实现多种功能了,相当强大。
2、同步命令rsync的具体参数使用
3、具有基个语言的编程能力bash python perl都可以实现
post-commit具体实现细节
post-commit脚本
编辑文件:sudo vim /home/svn/fitness/hooks/post-commit
注意:编辑完成post-commit后,执行:sudo chmod 755 post-commit
内容:
- #!/bin/sh
- export LANG=zh_CN.UTF-8
- sudo /usr/bin/svn update /var/www/www --username mirze --password 123456
- 或
- #Set variable
- SVN=/usr/bin/svn
- WEB=/home/test_nokia/
- RSYNC=/usr/bin/rsync
- LOG=/tmp/rsync_test_nokia.log
- WEBIP="192.168.0.23"
- export LANG=en_US.UTF-8
- #update the code from the SVN
- $SVN update $WEB --username user --password password
- #If the previous command completed successfully, to continue the following
- if [ $? == 0 ]
- then
- echo "" >> $LOG
- echo `date` >> $LOG
- echo "##############################" >> $LOG
- chown -R nobody:nobody /home/test_nokia/
- #Synchronization code from the SVN server to the WEB server, notes:by the key
- $RSYNC -vaztpH --timeout=90 --exclude-from=/home/svn/exclude.list $WEB root@$WEBIP:/www/ >> $LOG
- fi
以上是具体的post-commit程序
