由开发提交到测试环境,经测试,在由运维统一上线。试验需求一台测试服务器,一台线上(生产环境)服务器。测试服务器上跑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]# # 代码成功同步到测试环境
[root@v01-svn-test-server localsvn]# ls
default1.html default.html index.html index.php test.txt
[root@v01-svn-test-server localsvn]# cat test.txt
客服端提交代码到svn服务上
[root@v01-svn-test-server localsvn]# svn status
? test.txt
#通过rsync -vr --exclude=".svn" --delete /alidata/www/online/ /alidata/www/localsvn 来实现代码同步

然后根据开发统一上线(可以全部,也可一特定代码上线!!)

[root@v03-svn-client client_webtest]# echo "更新代码---》1" >> test.txt
[root@v03-svn-client client_webtest]# touch test2.txt #添加新的代码test.txt
[root@v03-svn-client client_webtest]# svn status
? test2.txt
M test.txt
[root@v03-svn-client client_webtest]# svn add test2.txt
A test2.txt
[root@v03-svn-client client_webtest]# svn ci -m "'更新代码---》1'>> test.txt 添加新的代码test.txt"
Sending test.txt
Adding test2.txt
Transmitting file data ..
Committed revision 44.
[root@v01-svn-test-server online]# pwd
/alidata/www/online
[root@v01-svn-test-server online]# ls
default1.html default.html index.html index.php test2.txt test.txt
[root@v01-svn-test-server online]# cat test.txt
客服端提交代码到svn服务上
更新代码---》1
[root@v01-svn-test-server online]# svn status
[root@v01-svn-test-server online]# 代码根新成功!!!
[root@v01-svn-test-server localsvn]# pwd
/alidata/www/localsvn
[root@v01-svn-test-server localsvn]# ls
default1.html default.html index.html index.php test2.txt test.txt
[root@v01-svn-test-server localsvn]# cat test.txt
客服端提交代码到svn服务上
更新代码---》1
[root@v01-svn-test-server localsvn]# svn status
? test2.txt
? test.txt
#通过rsync同步成功!

验证:目标于源目录文件是否时时同步,包裹删除!

[root@v03-svn-client client_webtest]# ls
default1.html default.html index.html index.php test2.txt test.txt
[root@v03-svn-client client_webtest]# svn status
[root@v03-svn-client client_webtest]# ls
default1.html default.html index.html index.php test2.txt test.txt
[root@v03-svn-client client_webtest]# svn delete test2.txt
D test2.txt
[root@v03-svn-client client_webtest]# svn status
D test2.txt
[root@v03-svn-client client_webtest]# ls
default1.html default.html index.html index.php test.txt
[root@v03-svn-client client_webtest]# svn ci -m "delete test2.txt" test2.txt
Deleting test2.txt Committed revision 45.
[root@v01-svn-test-server online]# pwd
/alidata/www/online
[root@v01-svn-test-server online]# ls
default1.html default.html index.html index.php test.txt
[root@v01-svn-test-server online]# svn status
[root@v01-svn-test-server www]# cd localsvn/
[root@v01-svn-test-server localsvn]# ls
default1.html default.html index.html index.php test.txt
[root@v01-svn-test-server localsvn]# cat test.txt
客服端提交代码到svn服务上
更新代码---》1
[root@v01-svn-test-server localsvn]# svn status
? test.txt
[root@v03-svn-client client_webtest]# cat test.txt
客服端提交代码到svn服务上
更新代码---》1
[root@v03-svn-client client_webtest]# ls
default1.html default.html index.html index.php test.txt
[root@v03-svn-client client_webtest]# svn status
[root@v03-svn-client client_webtest]# echo "更新代码----》2" >> test.txt
[root@v03-svn-client client_webtest]# svn status
M test.txt
[root@v03-svn-client client_webtest]# svn ci -m "echo'更新代码----》2' >> test.txt "
Sending test.txt
Transmitting file data .
Committed revision 46.
[root@v03-svn-client client_webtest]# svn status
[root@v03-svn-client client_webtest]#
[root@v01-svn-test-server online]# pwd
/alidata/www/online
[root@v01-svn-test-server online]# ls
default1.html default.html index.html index.php test.txt
[root@v01-svn-test-server online]# svn status
[root@v01-svn-test-server online]# cat test.txt
客服端提交代码到svn服务上
更新代码---》1
更新代码----》2
[root@v01-svn-test-server online]#

线上正式环境的svn的钩子脚本:

[root@v02-svn-online ~]# cat /svn/webtest/hooks/post-commit

REPOS="$1"
REV="$2"
SVN=/usr/bin/svn
WEB=/alidata/www/webtest
LOG=/alidata/log/svn/svn.log
export LANG=en_US.UTF-8
$SVN update $WEB --username user001 --password 123 >>$LOG
#mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf

(切忌防火墙不果没配的话,可以先关了!)

[root@v01-svn-test-server localsvn]# pwd
/alidata/www/localsvn
[root@v01-svn-test-server localsvn]# ls
default1.html default.html index.html index.php test.txt
[root@v01-svn-test-server localsvn]# svn status
? test.txt
[root@v01-svn-test-server localsvn]# cat test.txt
客服端提交代码到svn服务上
更新代码---》1
更新代码----》2
[root@v01-svn-test-server localsvn]# svn add test.txt
A test.txt
[root@v01-svn-test-server localsvn]# svn ci -m ”定时网线上发布代码“ test.txt
svn: Commit failed (details follow):
svn: Can't connect to host '192.168.1.65': No route to host(因为防火请端口没开)
[root@v01-svn-test-server localsvn]# svn ci -m ”定时网线上发布代码“ test.txt
Adding test.txt
Transmitting file data .
Committed revision 30.
[root@v02-svn-online webtest]# pwd
/alidata/www/webtest
[root@v02-svn-online webtest]# ls
default1.html default.html index.html index.php test.txt xxxzz.tar xxzz.zip
[root@v02-svn-online webtest]# cat test.txt
客服端提交代码到svn服务上
更新代码---》1
更新代码----》2
[root@v02-svn-online webtest]# 上线成功!
[root@v03-svn-client client_webtest]# echo "更新-----》3" > test.txt
[root@v03-svn-client client_webtest]# svn status
M test.txt
[root@v03-svn-client client_webtest]# cat test.txt
更新-----》3
[root@v03-svn-client client_webtest]#
[root@v03-svn-client client_webtest]# svn ci -m "echo "更新-----》3" > test.txt "
Sending test.txt
Transmitting file data .
Committed revision 47.
[root@v03-svn-client client_webtest]#
[root@v01-svn-test-server online]# svn status
[root@v01-svn-test-server online]# ls
default1.html default.html index.html index.php test.txt
[root@v01-svn-test-server online]# cat test.txt
更新-----》3
[root@v01-svn-test-server online]#
[root@v01-svn-test-server localsvn]# pwd
/alidata/www/localsvn
[root@v01-svn-test-server localsvn]# ls
default1.html default.html index.html index.php test.txt
[root@v01-svn-test-server localsvn]# svn status
M test.txt
[root@v01-svn-test-server localsvn]# cat test.txt
更新-----》3
[root@v01-svn-test-server localsvn]#
[root@v01-svn-test-server localsvn]# svn ci -m "更新-----》3 test.txt" test.txt
Sending test.txt
Transmitting file data .
Committed revision 31.
[root@v01-svn-test-server localsvn]#
[root@v02-svn-online webtest]# cat test.txt
更新-----》3
[root@v02-svn-online webtest]#

回滚代码:

[root@v01-svn-test-server localsvn]# svn  diff -r 31:30
Index: test.txt
===================================================================
--- test.txt (revision 31)
+++ test.txt (revision 30)
@@ -1 +1,3 @@
-更新-----》3
+客服端提交代码到svn服务上
+更新代码---》1
+更新代码----》2
[root@v01-svn-test-server localsvn]# svn diff -r 31:30 test.txt
Index: test.txt
===================================================================
--- test.txt (revision 31)
+++ test.txt (revision 30)
@@ -1 +1,3 @@
-更新-----》3
+客服端提交代码到svn服务上
+更新代码---》1
+更新代码----》2
[root@v01-svn-test-server localsvn]# svn -r 31:30 "" test.txt
[root@v01-svn-test-server localsvn]# svn merge -r31:30 ""
svn: Cannot reverse-merge a range from a path's own future history; try updating first
[root@v01-svn-test-server localsvn]# svn up
At revision 31.
[root@v01-svn-test-server localsvn]# svn merge -r31:30 ""
--- Reverse-merging r31 into '.':
U test.txt
[root@v01-svn-test-server localsvn]# cat test.txt
客服端提交代码到svn服务上
更新代码---》1
更新代码----》2
[root@v01-svn-test-server localsvn]# svn log -v test.txt
------------------------------------------------------------------------
r31 | user001 | 2016-05-19 11:57:52 +0800 (Thu, 19 May 2016) | 1 line
Changed paths:
M /test.txt 更新-----》3 test.txt
------------------------------------------------------------------------
r30 | user001 | 2016-05-19 11:38:30 +0800 (Thu, 19 May 2016) | 1 line
Changed paths:
A /test.txt ”定时网线上发布代码“
------------------------------------------------------------------------
[root@v01-svn-test-server localsvn]#
[root@v01-svn-test-server localsvn]# svn ci -m "merge -r31:30" test.txt
Sending test.txt
Transmitting file data .
Committed revision 32.
[root@v02-svn-online webtest]# cat test.txt
客服端提交代码到svn服务上
更新代码---》1
更新代码----》2
[root@v02-svn-online webtest]# svn log test.txt
------------------------------------------------------------------------
r32 | user001 | 2016-05-19 13:27:47 +0800 (Thu, 19 May 2016) | 1 line merge -r31:30
------------------------------------------------------------------------
r31 | user001 | 2016-05-19 11:57:52 +0800 (Thu, 19 May 2016) | 1 line 更新-----》3 test.txt
------------------------------------------------------------------------
r30 | user001 | 2016-05-19 11:38:30 +0800 (Thu, 19 May 2016) | 1 line ”定时网线上发布代码“
------------------------------------------------------------------------
[root@v02-svn-online webtest]# 回滚成功!

svn 结合rsync 的代码发布系统的更多相关文章

  1. 【运维工具】Git代码发布系统

    引言 代码发布系统是互联网公司必备的运维系统,作用主要用户发布业务代码 到 业务服务器 为什么需要代码发布系统 有的同学可能说,我们公司服务器就那么一台,做个发布系统太麻烦了? 不认同这说法 发布系统 ...

  2. Walle代码发布系统

    Walle 一个web部署系统工具,配置简单.功能完善.界面流畅.开箱即用!支持git.svn版本管理,支持各种web代码发布,PHP,Python,JAVA等代码的发布.回滚,可以通过web来一键完 ...

  3. modelform+代码发布系统前奏

    目录 注意点 form.html 添加编辑页面 ModelForm 添加 编辑 删除 代码优化 优化1 优化2 优化3 注意点 <form class="form-horizontal ...

  4. walle代码发布系统配置

    walle Walle 一个web部署系统工具,配置简单.功能完善.界面流畅.开箱即用! 支持git.svn版本管理,支持各种web代码发布, PHP,Python,JAVA等代码的发布.回滚,可以通 ...

  5. Walle代码发布

    一.概述 Walle 一个web部署系统工具,配置简单.功能完善.界面流畅.开箱即用!支持git.svn版本管理,支持各种web代码发布,PHP,Python,JAVA等代码的发布.回滚,可以通过we ...

  6. Linux实战教学笔记41:企业级SVN版本管理与大型代码上线方案

    第1章 SVN服务实战应用指南 1.1 SVN介绍 1.1.1 什么是SVN(Subversion)? Svn(subversion)是近年来崛起的非常优秀的版本管理工具,与CVS管理工具一样,SVN ...

  7. SVN版本管理与大型代码上线方案(一)

    SVN版本管理与大型代码上线方案(一) 链接:https://pan.baidu.com/s/1A3Iq3gGkGS27L_Gt37_I0g 提取码:ncy2 复制这段内容后打开百度网盘手机App,操 ...

  8. jenkins配置记录(2)--代码发布流程

    在我们的日常运维工作中,使用jenkins来完成业务代码发版上线是至关重要的一环.前面已经提到在jenkins上添加用户权限的操作,今天重点说下如何在jenkins下构建项目工程进行代码发布? 在此简 ...

  9. svn + nginx unit + python3自动化发布web服务方法

    本周将python web服务管理更换成nginx unit以后发现接口性能有了明显的提升,访问速度快了不少.不过有个很大的问题就是使用svn自动化发布以后,服务并没有刷新使用新的代码运行,而又不懂得 ...

随机推荐

  1. Linux 下模拟Http 的get or post请求(curl和wget两种方法)

    一.get请求: 1.使用curl命令: curl "http://www.baidu.com"  如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地curl -i & ...

  2. 利用dedecms autoindex让文章列表加上序列号

    有些时候我们在制作模板的需要在文章标题前面加上序列号,可以通过织梦自带的autoindex属性来实现,实现方法很简单,只需要在序号递增的地方加上 这段代码就行,[field:global runphp ...

  3. mouseover和mouseout闪烁问题

    在父级元素上注册了mouseover和mouseout事件后,当鼠标移动到子元素上时,会触发父级的mouseout和mouseover事件,反复触发,形成闪烁. 原因: 一种是由于冒泡,子级的mous ...

  4. 陷阱~EF中的Update与Insert共用一个数据上下文

    事情是这样的,有一个列表,里面有很多用户信息,可能会有重复的用户,将这个列表的用户插入到数据表中,如果用户已经存在,就更新这个用户的FillTimes 字段,让它加1,使用的底层ORM是entity ...

  5. linux 的终端字体色和背景色的修改方法(一)

    更改Linux系统终端的颜色主题 随着Linux系统在服务器端的崛起,Linux也在慢慢进军个人桌面系统领域.如果在使用Linux系统的终端时,对其颜色主题不是很满意,该怎么修改颜色的主题呢?今天笔者 ...

  6. Web基础架构:负载均衡和LVS

    在大规模互联网应用中,负载均衡设备是必不可少的一个节点,源于互联网应用的高并发和大流量的冲击压力,我们通常会在服务端部署多个无状态的应用服务器和若干有状态的存储服务器(数据库.缓存等等). 一.负载均 ...

  7. 批量删除wordpress垃圾评论留言

    wordpress博客的存在,垃圾评论注定会找上门来.大家还可以用Akismet.Bad Behavior.Spam Karma等一些其他的插件或者直接用程序写个验证码函数对留言进行验证来过滤 垃圾评 ...

  8. [Effective JavaScript 笔记] 第1章:让自己习惯javascript小结

    在这里整理一下,每条对应的提示 第1条:了解使用的js版本 确定应用程序支持的js的版本(浏览器也是应用程序噢) 确保使用的js特性是应用程序支持的(要不写了也运行不了) 总是在严格模式下编写和测试代 ...

  9. [Effective JavaScript 笔记]第39条:不要重用父类的属性名

    假设想给上节讲的场景图库添加收集诊断信息的功能.这对于调试和性能分析很有用. 38条示例续 给每个Actor实例一个唯一的标识数. 添加标识数 function Actor(scene,x,y){ t ...

  10. 第17章 使用iSCSI服务部署网络存储

    章节概述: 本章节将分析SCSI与iSCSI技术结构的不同,了解iSCSI技术的优势.SAN存储网络技术结构以及iSCSI HBA卡的作用. 完整演示部署iSCSI target服务程序的方法流程:创 ...