svn服务器:192.168.40.110
备份服务器:192.168.40.162
在svn服务器进行本地备份
1.全量备份
# vim /data/shell/backup_svn.sh
#!/bin/sh
#
PATH=$PATH:/usr/local/subversion/bin
export PATH
#定义时间变量,用于文件名后缀
DATE=$(date +%F)
#定义SVN库目录变量
SVN_DIR_docs=/data/Repositories/docs
SVN_DIR_tools=/data/Repositories/tools
#定义备份文件存放目录变量
SVN_BAK_DIR=/data/bak/
#初始化版本号,全库备份一定是从0版本号开始
echo '0' > /data/svnnum/docs_svn_id
echo '0' > /data/svnnum/tools_svn_id
#取初始化版本号
NUM_docs1=$(cat /data/svnnum/docs_svn_id)
NUM_tools1=$(cat /data/svnnum/tools_svn_id)
#取当前最新的版本号
NUM_docs2=$(svnlook youngest $SVN_DIR_docs)
NUM_tools2=$(svnlook youngest $SVN_DIR_tools)
#备份用户认证以及授权文件
\cp /data/Repositories/{authz,passwd} /data/bak/.
#开始备份
#判断备份是否成功,若成功,则记录当前最新的版本号到临时文件中,用于下次增量备份使用
All_Backup_svn(){
svnadmin dump $SVN_DIR_docs -r $NUM_docs1:$NUM_docs2 --incremental > $SVN_BAK_DIR/docs_bak_$DATE
if [ $? -eq 0 ];
then
echo $NUM_docs2 > /data/svnnum/docs_svn_id
else
echo "$(date +%F) docs backup fail...." >> /tmp/svnback.log
fi
svnadmin dump $SVN_DIR_tools -r $NUM_tools1:$NUM_tools2 --incremental > $SVN_BAK_DIR/tools_bak_$DATE
if [ $? -eq 0 ];
then
echo $NUM_tools2 > /data/svnnum/tools_svn_id
else
echo "$(date +%F) tools backup fail...." >> /tmp/svnback.log
fi
}
All_Backup_svn
2.增量备份
# vim /data/shell/day_backup_svn.sh#!/bin/bash#PATH=$PATH:/usr/local/subversion/binexport PATH#定义时间变量,用于文件名后缀DATE=$(date +%F) #定义SVN库目录变量SVN_DIR_docs=/data/Repositories/docs SVN_DIR_tools=/data/Repositories/tools #定义备份文件存放目录变量SVN_BAK_DIR=/data/bak/ #取初始化版本号NUM_docs1=$(cat /data/svnnum/docs_svn_id)NUM_tools1=$(cat /data/svnnum/tools_svn_id) #取当前最新的版本号NUM_docs2=$(svnlook youngest $SVN_DIR_docs)NUM_tools2=$(svnlook youngest $SVN_DIR_tools) #开始备份#判断备份是否成功,若成功,则记录当前最新的版本号到临时文件中,用于下次增量备份使用Day_Backup_svn(){if [ $NUM_docs1 -lt $NUM_docs2 ];then svnadmin dump $SVN_DIR_docs -r $NUM_docs1:$NUM_docs2 --incremental > $SVN_BAK_DIR/docs_bak_$DATEif [ $? -eq 0 ];thenecho $NUM_docs2 > /data/svnnum/docs_svn_idelseecho "$(date +%F) docs backup fail...." >> /tmp/svnback.logfifiif [ $NUM_tools1 -lt $NUM_tools2 ];thensvnadmin dump $SVN_DIR_tools -r $NUM_tools1:$NUM_tools2 --incremental > $SVN_BAK_DIR/tools_bak_$DATEif [ $? -eq 0 ];thenecho $NUM_tools2 > /data/svnnum/tools_svn_idelseecho "$(date +%F) tools backup fail...." >> /tmp/svnback.logfifi}Day_Backup_svn
3.添加定时任务
# crontab -e#start0 2 * * * /usr/sbin/ntpdate time.nist.gov > /dev/null 2>&1#每周日做一次全量备份59 23 * * 0 /data/shell/backup_svn.sh &>/dev/null#对svn进行增量备份59 23 * * 1-6 /data/shell/day_backup_svn.sh
4.配置rsync服务器:
# rpm -qa rsync(如果安装 yum install rsync -y)rsync-3.0.6-12.el6.x86_64# yum install xinetd -y启用rsync# vim /etc/xinetd.d/rsync # default: off# description: The rsync server is a good addition to an ftp server, as it \# allows crc checksumming etc.service rsync{ disable = no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID}
提供rsync配置文件# vim /etc/rsyncd.conf#rsync --daemon --config=/etc/rsyncd.conf#全局选项 strict modes =yes # 是否检查口令文件的权限 port = 873# 默认端口873 log file = /var/log/rsyncd.log# 日志记录文件 pid file = /var/run/rsyncd.pid# 运行进程的ID写到哪里 [svn]path = /data/bak# 这里是认证的模块名,在client端需要指定 max connections = 0# 客户端最大连接数,默认0(没限制) uid = root# 指定该模块传输文件时守护进程应该具有的uid gid = root# 指定该模块传输文件时守护进程应该具有的gid ignore errors# 可以忽略一些无关的IO错误 read only = yes# no客户端可上传文件,yes只读 write only = no# no客户端可下载文件,yes不能下载 hosts allow = * # 充许任何主机连接 #hosts deny = 10.5.3.1# 禁止指定的主机连接 auth users = root# 认证的用户名,如果没有这行,则表明是匿名 secrets file = /etc/backserver.pas# 指定认证口令文件位置
5.提供认证文件,且权限必须为600
# vim /etc/backserver.pas root:123456# chmod 600 /etc/backserver.pas
6.重启服务
# /etc/init.d/xinetd restart
7.同步备份至192.168.40.162
提供认证文件,且权限必须为600
# vim /etc/backserver.pas 123456# chmod 600 /etc/backserver.pas# mkdir -p /data/bak/svn# vim /home/bak/backup_svn.sh #!/bin/bash#备份svn仓库/usr/bin/rsync -vzrtopg --progress --delete root@192.168.40.110::svn /data/bak/svn --password-file=/etc/backserver.pas添加定时任务# crontab -e#Start0 2 * * * /usr/sbin/ntpdate time.nist.gov > /dev/null 2>&1#备份svn35 01 * * * /home/backup_svn.sh &> /dev/null#End
8. svn恢复测试
# mkdir docs # svnadmin create newrepos # svnadmin load newrepos < docs_bak_Mon# svnadmin load newrepos < docs_bak_Tue # svnadmin load newrepos < docs_bak_Wed# svnadmin load newrepos < docs_bak_Thu# svnadmin load newrepos < docs_bak_Fri# svnadmin load newrepos < docs_bak_Sun
本文出自 “Linux之旅” 博客,请务必保留此出处http://openlinuxfly.blog.51cto.com/7120723/1671301