##############################################################
第一种方式:
svn服务端 也是rsync的客户端
web 是rsync的服务端
svn服务端执行:
[root@xinyou04 ~]#sh yum-svn02.sh
[root@xinyou04 ~]#mkdir /var/www/bbs -p
[root@xinyou04 ~]#svn checkout http://192.168.13.120/svn/mobile_game /var/www/bbs|tee -a svn.log
以下授权很重要:
###############################################################
chmod 777 -R /data/
chown -R apache.apache /data/
chmod -R 777 /var/www/bbs/
chown -R apache.apache /var/www/bbs/
chmod 777 -R /data/svn/mobile_game/hooks/post-commit
chown -R apache.apache /data/svn/mobile_game/hooks/post-commit
###############################################################
[root@xinyou04 ~]#cd /data/svn/mobile_game/hooks
[root@CactiEZ hooks]#cat post-commit
#!/bin/sh
#修改为服务编码
export LANG="zh_CN.UTF-8"
#Set variable
REPOS="$1"
REV="$2"
SVN=/usr/bin/svn
WEB=/var/www/bbs
LOG=/data/auto_svn.log
#update the code from the SVN
$SVN update $WEB --username mobile_game --password 123456 --non-interactive
#......................
if [ $? == 0 ]
then
/bin/echo "$REPOS" "$REV" >> $LOG
/bin/echo `date` >> $LOG
/bin/echo "##############################" >> $LOG
rsync -avzp $WEB/* rsync_backup@192.168.13.104::www --password-file=/etc/rsync.password
fi
###########################################################################################
第二种方式:
svn服务端:192.168.0.106采用ssh免密码方式把公钥匙发送给web
web 服务:192.168.0.103
#######此步很重要
[root@hh-c2c-php02 ~]# cp -rf .ssh/ /var/www/
######svn钩子脚本02
[root@xinyou04 ~]#cd /data/svn/mobile_game/hooks
[root@CactiEZ hooks]#cat post-commit
#!/bin/sh
#修改为服务编码
export LANG="zh_CN.UTF-8"
#Set variable
REPOS="$1"
REV="$2"
SVN=/usr/bin/svn
WEB=/var/www/bbs
LOG=/data/auto_svn.log
IP=192.168.103
FILE=/var/www/html/bbs
#update the code from the SVN
$SVN update $WEB --username mobile_game --password 123456 --non-interactive
#......................
if [ $? == 0 ]
then
/bin/echo "$REPOS" "$REV" >> $LOG
/bin/echo `date` >> $LOG
/bin/echo "##############################" >> $LOG
rsync -azp $WEB/* root@$IP:$FILE
fi
本文出自 “liunx系统” 博客,谢绝转载!
svn钩子自动化同步代码提交任务,布布扣,bubuko.com
原文地址:http://cuncai2014.blog.51cto.com/8733819/1538294