写给自己看的,方便查询

Svn服务器:10.6.0.2
Svn客户端:10.6.0.6
 
从前的勾子文件,每提交一次都会触发下面六条代码进行更新,只有当这些代码执行完后提交才会成功,同时更新这六条代码是很慢的,这样就导致每次提交文件非常慢。
vim post-commit
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/test&&svn update"
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/resource&&svn update"
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/test_rl&&svn update"
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/test_rl/language&&svn update"
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/test_rl/resource&&svn update"
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/test_rl/template&&svn update"
 
下面通过脚本来优化提交速度。
我们提交一个文件后,先在10.6.0.2上通过svnlook dirs-changed命令可以得到每次提交的文件路径。如:
#svnlook dirs-changed /data/svn_files/yx/
share/resource_template_language/resource/common_info/p_w_picpaths/
再回到10.6.0.6上通过svn info命令可以得到每个检出目录所对应的svn服务器目录路径。
# pwd
/opt/data/mfs/folder2/htdocs/test_rl/resource/common_info/p_w_picpaths
# svn info
路径: .
URL: svn://10.6.0.2/yx/share/resource_template_language/resource/common_info/p_w_picpaths
 
写一个脚本,自动判断每次提交到svn服务器(10.6.0.2)的文件的路径,然后根据路径来定向更新到客户端(10.6.0.6)指定的文件夹。而不是更新所有客户端检出的文件夹。这样由于更新范围被缩小,所以更新速度就得到大大的提高。
#!/bin/bash
svndir1=/opt/data/mfs/folder2/htdocs
svndir2=/opt/data/mfs/folder2/htdocs/test_rl
 
for i in `cat changed.log`
        do
                dir1=`echo "$i" |awk -F/ '{print $1}'`
                dir2=`echo "$i" |awk -F/ '{print $2}'`
                dir3=`echo "$i" |awk -F/ '{print $3}'`
#更新resource
        if [ "$dir1/$dir3" = 'web?\229?\137?\141?\231?\171?\175?\229?\188?\128?\229?\143?\145/resource' ];then
                svndir3=`echo $i |grep -Po '(?<=[/]...../).*'`
                echo "$svndir1/$svndir3"
                sshpass -p 123456 ssh -o GSSAPIAuthentication=no -o StrictHostKeyChecking=no [email protected] "cd $svndir1/$svndir3 &&svn up"
##更新test_rl/template
        elif [ "$dir2" = "resource_template_language" ] && [ "$dir3" = "resource" -o "$dir3" = "template" -o "$dir3" = "language" ];then
                svndir4=`echo $i |awk -F"share/resource_template_language/" '{print $2}'`
                echo "$svndir2/$svndir4"
                sshpass -p 123456 ssh -o GSSAPIAuthentication=no -o StrictHostKeyChecking=no [email protected] "cd $svndir2/$svndir4 &&svn up"
##更新test及test_rl
        elif [ $dir2 = "test" -o $dir2 = "test_rl" ];then
                svndir5=`echo $i |awk -F"share/" '{print $2}'`
                echo "$svndir1/$svndir5"
                sshpass -p 123456 ssh -o GSSAPIAuthentication=no -o StrictHostKeyChecking=no [email protected] "cd $svndir1/$svndir5 &&svn up"
        fi
#
        Done
 
将这个脚本命名为commit.sh,且放到/root/shell目录下
#cd /root/shell/
#ls commit.sh
commit.sh
 
在post-commit勾子文件中,添加如下行,且注释掉原来的代码行。
#vim post-commit
svnlook dirs-changed /data/svn_files/yx > /data/svn_files/yx/changed.log && /root/shell/commit.sh
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/test&&svn update"
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/resource&&svn update"
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/test_rl&&svn update"
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/test_rl/language&&svn update"
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/test_rl/resource&&svn update"
#sshpass -p 123456 ssh [email protected] "cd /opt/data/mfs/folder2/htdocs/test_rl/template&&svn update"
 
再次提交,速度就快了非常多了,再也不用面临漫长的等待了。