玩转SVN
1. SVN简介
参照百度文库:
http://baike.baidu.com/link?url=u3jMeBI9JJF3TF1sk4sLChh3LUFOEkV-olDSWXidNxeXbC3jDIbUWiADoItKvQX0K5EB4M2dwENvhyqjhPlYPa
2. SVN搭建
2.1 SVN Server环境介绍:
[root@svn_server ~]# cat /etc/issue CentOS release 6.3 (Final) #操作版本系统 Kernel \r on an \m [root@svn_server ~]# uname -m x86_64 #操作系统位数 [root@svn_server ~]# uname -r 2.6.32-279.el6.x86_64 #内核版本
2.2 SVN安装(采用yum方式安装,简单、粗暴、高效):
[root@svn_server ~]# sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf #安装但不删除原软件 [root@svn_server ~]# yum list | grep subversion subversion.x86_64 1.6.11-15.el6_7 @updates [root@svn_server ~]# yum install subversion -y [root@svn_server ~]# rpm -qa | grep subversion subversion-1.6.11-15.el6_7.x86_64
2.3 启动SVN
[root@svn_server ~]# mkdir /data/svn_data [root@svn_server ~]# svnadmin create /data/svn_data/svn_test #创建一个svn实例(SVN版本库) [root@svn_server ~]# svnserve -d -r /data/svn_data/ #启动svn [root@svn_server ~]# ps -aux | grep svn #查看svn进程 Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ root 11060 0.0 0.0 174516 884 ? Ss 16:45 0:00 svnserve -d -r /data/svn_data/ root 11062 0.0 0.0 103248 840 pts/0 S+ 16:46 0:00 grep svn [root@svn_server ~]# netstat -aunpt | grep svn #查看svn的默认端口 tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 11060/svnserve [root@svn_server svn_test]# ps -aux | grep svn #重启svn Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ root 11073 0.0 0.0 103248 840 pts/0 S+ 16:50 0:00 grep svn [root@svn_server svn_test]# svnserve -d -r /data/svn_data/ [root@svn_server svn_test]# ps -aux | grep svn Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ root 11075 0.0 0.0 174516 884 ? Ss 16:50 0:00 svnserve -d -r /data/svn_data/ root 11077 0.0 0.0 103248 836 pts/0 S+ 16:50 0:00 grep svn
2.4 配置SVN
[root@svn_server ~]# cd /data/svn_data/svn_test/ [root@svn_server svn_test]# ls conf db format hooks locks README.txt [root@svn_server conf]# pwd /data/svn_data/svn_test/conf [root@svn_server conf]# cp svnserve.conf svnserve.conf.bak.$(date +%F) [root@svn_server conf]# ls authz passwd svnserve.conf svnserve.conf.bak.2016-04-15 [root@svn_server conf]# egrep "\-access|\-db =" svnserve.conf # anon-access = read # auth-access = write # password-db = passwd # authz-db = authz [root@svn_server conf]# sed -i 's/# auth-access = write/auth-access = none/g' svnserve.conf #修改配置文件 [root@svn_server conf]# sed -i 's/# anon-access = read/anon-access = none/g' svnserve.conf [root@svn_server conf]# sed -i 's/# password-db = passwd/password-db = passwd/g' svnserve.conf [root@svn_server conf]# sed -i 's/# authz-db = authz/authz-db = authz/g' svnserve.conf [root@svn_server conf]# egrep "\-access|\-db =" svnserve.conf anon-access = none # 控制非鉴权用户访问版本库的权限 auth-access = write # 控制鉴权用户访问版本库的权限 password-db = passwd #指定svn版本库的密码文件(存放svn用户的密码信息) authz-db = authz #指定svn版本库的用户文件(存放svn用户的权限信息) [root@svn_server conf]# cat authz [groups] leader=ht group1=ht001 group2=ht002,ht003 [svn_test:/] @leader = rw [svn_test:/test] @group1 = rw [svn_test:/test/ht] @group2=rw [root@svn_server conf]# cat passwd [users] ht = !ht@ ht001 = !ht001@ ht002 = !ht002@ ht002 = !ht003@ [root@svn_server conf]# chmod 700 passwd [root@svn_server svn_test]# ps -aux | grep svn #重启svn Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ root 11073 0.0 0.0 103248 840 pts/0 S+ 16:50 0:00 grep svn [root@svn_server svn_test]# svnserve -d -r /data/svn_data/
2.5 SVN客户端操作
[root@svn_client ~]# yum install subversion -y [root@svn_client ~]# mkdir /svn_client_data [root@svn_client svn_client_data]# mkdir branch tags trunk [root@svn_client svn_client_data]# echo "This is a svn test" > t.txt [root@svn_client svn_client_data]# cp t.txt branch/ [root@svn_client svn_client_data]# cp t.txt tags/ [root@svn_client svn_client_data]# cp t.txt trunk/ [root@svn_client svn_client_data]# svn import -m "first commit" /svn_client_data/ svn://14.18.204.173/svn_test #上传数据到svn server #Password for 'root': 输入服务器的root密码 #Username: 输入svn的账号 #Password: 输入svn账号对应的密码 #Store password unencrypted (yes/no)? 是否保持svn密码 [root@svn_client ~]# mkdir /test svn checkout svn://14.18.204.173:/svn_test /test/ --username ht --password '!ht@' #第一次下载svn server服务器需要checkout,后面直接update即可。 [root@svn_client test1]# ls /test/ branch tags trunk t.txt [root@svn_client svn_client_data]# svn update svn://14.18.204.173:/svn_test /test/ --username ht --password '!ht@' #update [root@svn_client svn_client_data]# ls /test/ branch tags test trunk t.txt [root@svn_client svn_client_data]# svn list svn://14.18.204.173:/svn_test --username ht --password '!ht@' #查看svn数据 branch/ t.txt tags/ test/ trunk/ [root@svn_client svn_client_data]# svn cat svn://14.18.204.173:/svn_test/t.txt --username ht --password '!ht@' This is a svn test
2.6 SVN hooks(钩子)
#转载
post-commit变更前的代码: 以前每一次的提交都会造成整个svn的更新。当svn目录越来越大,文件越来越多的时候,svn提交也会越来越慢。 export LANG="zh_CN.UTF-8" REPOS="$1" REV="$2" SVN_PATH=/usr/bin/svn WEB_PATH=/var/rekfan_web/wwwroot LOG_PATH=/var/log/svn_update.log #/usr/bin/svn update --username user --password password $WEB_PATH --no-auth-cache echo "nnn##########开始提交 " `date "+%Y-%m-%d %H:%M:%S"` '##################' >> $LOG_PATH echo `whoami`,$REPOS,$REV >> $LOG_PATH $SVN_PATH update --username svnuser --password svnpass $WEB_PATH --no-auth-cache >> $LOG_PATH chown -R www:www $WEB_PATH 这个时候,可以稍微变通一下,尝试用svnlook只更新那些有变化的文件夹。 post-commit变更后的代码: export LANG="zh_CN.UTF-8" REPOS="$1" REV="$2" SVN_PATH=/usr/bin/svn SVNDATA_PATH=/var/svn/rekfan_www WEB_PATH=/var/rekfan_web LOG_PATH=/var/log/svn_update.log echo "##########开始提交 " `date "+%Y-%m-%d %H:%M:%S"` '##################' >> $LOG_PATH for change_dir in `svnlook dirs-changed $SVNDATA_PATH` do $SVN_PATH update --username svnuser --password svnpass --no-auth-cache -N $WEB_PATH/$change_dir >> $LOG_PATH done echo `whoami`,$REPOS,$REV >> $LOG_PATH chown -R www:www $WEB_PATH/$change_dir
2.6 SVN远程备份

浙公网安备 33010602011771号