svn主从备份以及开机启动脚本

A主从备份:

原由:从我入职公司到现在svn服务器就一台,年前我就有想法搞一台备的,不然到时候机器挂了数据丢了就尴尬了。

昨天搞了一整天,网上的各种教学,改来改去,遇到一个坑:同步只能同步版本,不能同步数据。

晚上回家又想了下,没想通。今天早上来重新对了下各个配置。发现只有一个没有改:svnserve.conf里

anon-access = read 改为了anon-access = none就没问题了。

附上操作:

svn主搭建忽略。

主svn:svn://192.168.52.102/test1

从svn:svn://192.168.52.103/test1

大部分都是从上操作:

从上操作:

[建svn库:

mkdir /home/svn/test1

svnadmin create /home/svn/test1

 

把主上的conf下的文件拷贝到备上的conf下:简单配置如下:

[root@localhost conf]# cat authz | grep ^[^#]
[aliases]
[groups]
admin=lipeng
dev=lipengdev
[/]
@admin=rw
@dev=rw
[repository:/]
@admin=rw
@dev=rw
[root@localhost conf]# cat passwd | grep ^[^#]
[users]
lipeng = xxxxxx
lipengdev = xxxxxx
[root@localhost conf]# cat svnserve.conf | grep ^[^#]
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
[sasl]

 

修改hooks下的pre-revprop-change

全部清空,写入

#!/bin/sh
exit 0

给执行权限:

chmod 755 pre-revprop-change

先把从的svn起起来  svnserve -d -r /home/svn   下图中是服务器启动的,下面会贴上服务脚本。

 

从上开始初始化:

svnsync init svn://192.168.52.103/test1 svn://192.168.52.102/test1 --username lipeng --password xxxxxx --no-auth-cache

 

从上直接同步:

svnsync sync --non-interactive svn://192.168.52.103/test1 --username lipeng --password xxxxxx

上图就遇到了开头说的问题,只同步了版本属性,没有同步数据。需要修改

svnserve.conf里

anon-access = read 改为了anon-access = none就没问题了。(主从上都要改为none 切记)

改完貌似需要重新初始化。这边直接删掉重建了库。

再次同步问题解决:

 

]###[]内都是从上操作的。

主上操作:

修改hooks的post-commit,用户提交代码就会自动备份到从。

修改hooks上的post-commit(初始内容直接清空,写入以下内容即可)

chmod +x post-commit

#!/bin/sh
svnsync sync --non-interactive svn://192.168.52.103/test1 --username lipeng --password xxxxxx

 

 下面验证:

在例外一台机器上验证:

checkout主的test1:

在别的目录checkout从的test1

主的test1里面增删改查,并提交。

[root@svn opt]# cd test1/
[root@svn test1]# ls
asdadasd.txt sakjdhkjashdhjk.txt test1_2_3_4_5_6_7_8.txt test1_2_3_4_5_6.txt test1_2_3_4.txt test1_2.txt ysb
askjhdjkha.txt test11111111.txt test1_2_3_4_5_6_7.txt test1_2_3_4_5.txt test1_2_3.txt test1.txt
[root@svn test1]# touch aaaa.txt
[root@svn test1]# svn add aaaa.txt
A aaaa.txt
[root@svn test1]# svn commit -m "add aaaa.txt"
增加 aaaa.txt
传输文件数据.
提交后的版本为 18。

进到从的那个库里,直接update看结果:成功。

 

 B:svn启动服务脚本:

vim /etc/init.d/svnboot

chmod +x /etc/init.d/svnboot

chkconfig --add svnboot

chkconfig svnboot on

脚本内容如下:

#!/bin/bash
# chkconfig: 2345 85 15
# description: svn server
SVN_HOME=/home/svn
SVN_SERVER=/usr/bin/svnserve

if [ ! -x $SVN_SERVER ]; then
echo "svnserver startup: cannot start"
exit
fi

case "$1" in
start)
echo "Starting svnserve…"
$SVN_SERVER -d -r $SVN_HOME
echo "Finished!"
;;
stop)
echo "Stoping svnserve…"
killall svnserve
echo "Finished!"
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: svn { start | stop | restart } "
exit 1
esac

 

posted @ 2019-03-06 16:01  lpaxq  阅读(425)  评论(0编辑  收藏  举报