阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

svn 结合rsync 的代码发布系统

373次阅读
没有评论

共计 11663 个字符,预计需要花费 30 分钟才能阅读完成。

由开发提交到测试环境,经测试,在由运维统一上线。试验需求一台测试服务器,一台线上 (生产环境) 服务器。测试服务器上跑 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]# 回滚成功!

RSync 实现文件备份同步详解   http://www.linuxidc.com/Linux/2014-09/106967.htm

利用 inotifywait 监控主机文件和目录 http://www.linuxidc.com/Linux/2013-03/81075.htm

利用 inotify+rsync 实现 Linux 文件批量更新 http://www.linuxidc.com/Linux/2012-01/52132.htm

inotify-tools+rsync 实时同步文件安装和配置 http://www.linuxidc.com/Linux/2012-06/63624.htm

rsync 同步完整配置 http://www.linuxidc.com/Linux/2013-06/85781.htm

CentOS 6.5 下 Rsync 远程同步 http://www.linuxidc.com/Linux/2014-05/101084.htm

Linux 文件夹对比并提取的差分文件技巧 -rsync 的妙用 http://www.linuxidc.com/Linux/2016-02/128307.htm

Rsync 的详细介绍:请点这里
Rsync 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-05/131565.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计11663字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19351
评论数
4
阅读量
7985346
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
【1024程序员】我劝你赶紧去免费领一个AWS、华为云等的主机

【1024程序员】我劝你赶紧去免费领一个AWS、华为云等的主机

【1024 程序员】我劝你赶紧去免费领一个 AWS、华为云等的主机 每年 10 月 24 日,程序员们都会迎来...
Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集 在云原生体系中,Prometheus 已成为最主流的监控与报警...
星哥带你玩飞牛NAS-4:飞牛NAS安装istore旁路由,家庭网络升级的最佳实践

星哥带你玩飞牛NAS-4:飞牛NAS安装istore旁路由,家庭网络升级的最佳实践

星哥带你玩飞牛 NAS-4:飞牛 NAS 安装 istore 旁路由,家庭网络升级的最佳实践 开始 大家好我是...
亚马逊云崩完,微软云崩!当全球第二大云“摔了一跤”:Azure 宕机背后的配置风险与警示

亚马逊云崩完,微软云崩!当全球第二大云“摔了一跤”:Azure 宕机背后的配置风险与警示

亚马逊云崩完,微软云崩!当全球第二大云“摔了一跤”:Azure 宕机背后的配置风险与警示 首先来回顾一下 10...
星哥带你玩飞牛NAS-16:不再错过公众号更新,飞牛NAS搭建RSS

星哥带你玩飞牛NAS-16:不再错过公众号更新,飞牛NAS搭建RSS

  星哥带你玩飞牛 NAS-16:不再错过公众号更新,飞牛 NAS 搭建 RSS 对于经常关注多个微...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
4盘位、4K输出、J3455、遥控,NAS硬件入门性价比之王

4盘位、4K输出、J3455、遥控,NAS硬件入门性价比之王

  4 盘位、4K 输出、J3455、遥控,NAS 硬件入门性价比之王 开篇 在 NAS 市场中,威...
自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个 AI 智能体 — 跟创业大佬对话 前言 智能体(Agent)已经成为创业者和技术人绕...
开源MoneyPrinterTurbo 利用AI大模型,一键生成高清短视频!

开源MoneyPrinterTurbo 利用AI大模型,一键生成高清短视频!

  开源 MoneyPrinterTurbo 利用 AI 大模型,一键生成高清短视频! 在短视频内容...
星哥带你玩飞牛NAS-11:咪咕视频订阅部署全攻略

星哥带你玩飞牛NAS-11:咪咕视频订阅部署全攻略

星哥带你玩飞牛 NAS-11:咪咕视频订阅部署全攻略 前言 在家庭影音系统里,NAS 不仅是存储中心,更是内容...
星哥带你玩飞牛 NAS-9:全能网盘搜索工具 13 种云盘一键搞定!

星哥带你玩飞牛 NAS-9:全能网盘搜索工具 13 种云盘一键搞定!

星哥带你玩飞牛 NAS-9:全能网盘搜索工具 13 种云盘一键搞定! 前言 作为 NAS 玩家,你是否总被这些...