一、全量备份
环境:一台主SVN,一台备SVN(主要提供备份功能),后续可通过钩子脚本进行实时备份,后续发给大家。
工作原理:通过svn的hotcopy命令过行热备份,并进行一系列的检查,备份后通过rsync推送到备份机上。
脚本如下:
=======
#!/bin/bash
#Version: V2
#Date: 2015-02-03
#Author: wang
CONFDIR=/usr/local/httpd
BASEDIR=/home/xxx/scripts/svn_full_bak
SVNCMD=/usr/local/subversion/bin/svnadmin
SVNDIR=/data/svn
BAKDIR=$BASEDIR/full_bak_dir
SCDIR=/home/xxx/scripts
DISK=`df -h |sed -n '2p'|awk '{print $4}'|tr G " "|awk '{print $1}'`
######define function########
clear_bak_dir(){
sleep 2
${BAKDIR:=/home/xxx/scripts/svn_full_bak/full_bak_dir} &>/dev/null
rm -rf $BAKDIR/${repo}.bak
}
rm -f /home/xxx/scripts/svn_full_bak/logs/linshi.log
echo -e "\n" >>$BASEDIR/logs/Info.log
echo "######################### Backup Start in Time: $(date +%F-%T)#########################" >>$BASEDIR/logs/Info.log
echo "## SVN周备开始 Time:$(date +%F-%T) ##" >>/home/xxx/scripts/svn_full_bak/logs/linshi.log
##########Begin Loop backup SVN Repository##########
while read repo other
do
[ $DISK -lt 30 ] && {
# echo "Warning: Disk free less then 30G,svn backup failed (Time: $(date +%F-%T) ==>repo:$repo)"|mailx -s "Disk Free Check" wangbogui@xxx.com
echo "Warning: Disk free less then 30G,svn backup failed (Time: $(date +%F-%T) ==>repo:$repo)" >>$BASEDIR/logs/Info.log
echo "######################### Backup Stop in Time: $(date +%F-%T)#########################" >>$BASEDIR/logs/Info.log
echo "Warning: Disk free less then 30G,svn backup failed (Time: $(date +%F-%T) ==>repo:$repo)" >>/home/xxx/scripts/svn_full_bak/logs/linshi.log
echo "## SVN周备结束 Time:$(date +%F-%T) ##" >>/home/xxx/scripts/svn_full_bak/logs/linshi.log
mailx -s "SVN 周日全备" wangbogui@xxx.com < /home/xxx_a
dmin/scripts/svn_full_bak/logs/linshi.log
exit 1
}
${BAKDIR:=/home/xxx/scripts/svn_full_bak/full_bak_dir} &>/dev/null
[ ! -d $BAKDIR ] && mkdir -p $BAKDIR
/bin/chown -R xxx $BAKDIR
[ -d $BAKDIR/${repo}.bak ] && {
rm -rf $BAKDIR/${repo}.bak
}
[ ! -z "$other" ] && continue
[ ! -d $SVNDIR/$repo ] && {
echo "---- $repo repository ---- not exist ..."
echo "---- $repo repository ---- not exist ..." >>$BASEDIR/logs/Info.log
continue
}
echo " local backup start in Time: $(date +%F-%T) ==>repo:$repo" >>$BASEDIR/logs/Info.log
$SVNCMD hotcopy $SVNDIR/$repo $BAKDIR/${repo}.bak
[ $? -ne 0 ] && {
echo " local backup failed in Time: $(date +%F-%T) ==>repo:$repo" >>$BASEDIR/logs/Info.log
echo "$repo Local is Failed" >>/home/xxx/scripts/svn_full_bak/logs/linshi.log
clear_bak_dir
continue
}
############Begin remote back##############
/usr/bin/rsync -avz $BAKDIR/${repo}.bak xxx_web@xxx::${repo}/${repo}_$(date +%F) --password-file=/etc/rsyncd.passwd
[ $? -ne 0 ] && {
echo "remote backup failed in Time: $(date +%F-%T) ==>repo:$repo" >>$BASEDIR/logs/Info.log
echo "$repo is Failed" >>/home/xxx/scripts/svn_full_bak/logs/linshi.log
continue
}||{
echo "remote backup ..OK. in Time: $(date +%F-%T) ==>repo:$repo" >>$BASEDIR/logs/Info.log
echo "$repo is OK" >>/home/xxx/scripts/svn_full_bak/logs/linshi.log
}
clear_bak_dir
sleep 3
done < /home/xxx/scripts/svn_full_bak/repository.txt
###########Begin back svn conf directory##############
while read conf_dir rename other
do
[ ! -z $conf_dir -a -d $SVNDIR/$conf_dir ] && continue
[ -z $rename ] && continue
[ ! -z "$other" ] && {
echo "---- $conf_dir ---- Invalid format,please define Two parameter"
continue
}
[ ! -d $conf_dir ] && {
echo "---- $conf_dir conf_dir ---- not exist ..."
continue
}
echo "####### remote start backup --**${conf_dir}**--#######"
/usr/bin/rsync -avz ${conf_dir} xxx_web@xxx::bakdir/${rename}_$(date +%F) --password-file=/etc/rsyncd.passwd &>/dev/null
[ $? -eq 0 ] && {
echo "remote backup ${conf_dir} ..OK. in Time: $(date +%F-%T)" >>$BASEDIR/logs/Info.log
echo "${conf_dir} is OK" >>/home/xxx/scripts/svn_full_bak/logs/linshi.log
echo "####### remote backup .OK.. --**${conf_dir}**--#######"
}||{
echo "remote backup ${conf_dir} failed in Time: $(date +%F-%T)" >>$BASEDIR/logs/Info.log
echo "${conf_dir} is Failed" >>/home/xxx/scripts/svn_full_bak/logs/linshi.log
echo "remote backup ${conf_dir} is failed.."
}
done < /home/xxx/scripts/svn_full_bak/repository.txt
echo "######################### Backup Complete in Time: $(date +%F-%T)#########################" >>$BASEDIR/logs/Info.log
echo "## SVN周备结束 Time:$(date +%F-%T) ##" >>/home/xxx/scripts/svn_full_bak/logs/linshi.log
mailx -s "SVN 周日全备" wangbogui@xxx.com < /home/xxx/scripts/svn_full_bak/logs/linshi.log
二、增量备份
环境:一台主SVN,一台备SVN(主要提供备份功能),后续可通过钩子脚本进行实时备份,后续发给大家。
工作原理:
1、备机上通过nfs挂载到主机上,主要实现通过svnlook youngest来查看主和备间各版本库的版本号差别。(挂载后相当于在本地一样,就可以使用youngest参数或取到主和备版本号的区别别,并进行打包。)
2、挂载并打包后,将打包后的文件存放到挂载目录中,在到备机上通过还原脚本分别对更新的版本库进行还原,并将结果通过邮件发给告知人。
脚本如下:
======
主SVN上备份脚本:
#!/bin/bash
CMD1=/usr/local/subversion/bin/svnlook
CMD2=/usr/local/subversion/bin/svnadmin
SCDIR=/home/xxx/scripts/svn_incre_bak
BAKDIR=$SCDIR/incre_bak_dir
LOGS=/home/xxx/scripts/svn_incre_bak/logs
SVNDIR=/data/svn
SVNBAK=/svnbak
rm -f /svnbak/linshi.log
echo -e "\n" >>$LOGS/Info.log
echo "==================> Incremental Start in Time: $(date +%F-%T) <=========================" >>$LOGS/Info.log
echo "##SVN 增量备份开始 Time:$(date +%F-%T)##" >>/svnbak/linshi.log
#######check mount###############################
count=`ls /svnbak |wc -l`
/bin/mount |/bin/grep xxx
[ $? -ne 0 -o $count -lt 1 ] && {
/bin/mount -t nfs xxx:/svn/data /svnbak
RET=$?
}||{
RET=0
}
times=0
while true
do
if [ $RET -ne 0 ]
then
/bin/umount -lf /svnbak
/bin/mount -t nfs xxx:/data/svn/ /svnbak
count=`ls /svnbak |wc -l`
/bin/mount |grep xxx
[ $? -ne 0 -o $count -lt 1 ] && {
RET=$?
}||{
RET=0
}
sleep 1
let times++
else
break
fi
[ $times -eq 10 ]&&{
echo "mount xxx failed in Time: $(date +%F-%T)" >>$LOGS/logs/Info.log
echo "==================> Incremental Stop(failed:umount) in Time: $(date +%F-%T) <============" >>$LOGS/Info.loged.log
echo "mount xxx is Failed Time: $(date +%F-%T)" >>/svnbak/linshi.log
echo "##SVN 增量备份结束 Time:$(date +%F-%T)##" >>/svnbak/linshi.log
exit 1
}
done
##################################Begin backup################################################
rm -rf $SVNBAK/tmp/*
while read repo
do
[ ! -d $SVNBAK/$repo ] && {
echo "$repo not exist" >>$LOGS/Info.log
sleep 1
continue
}
V_NEW=`$CMD1 youngest $SVNDIR/$repo`
V_OLD=`$CMD1 youngest $SVNBAK/$repo`
V_OLD_1=$((${V_OLD}+1))
if [ $V_OLD -lt $V_NEW ]
then
sleep 1
$CMD2 dump --incremental -r ${V_OLD_1}:${V_NEW} $SVNDIR/$repo >$BAKDIR/${repo}_${V_OLD_1}:${V_NEW}
[ $? -ne 0 ] && {
echo "bakcup $repo dump failed" >>$LOGS/Info.log
echo "$repo dump is Failed" >>/svnbak/linshi.log
continue
}||{
echo "$repo dump is OK" >>$LOGS/Info.log
echo "$repo dump is OK" >>/svnbak/linshi.log
/bin/mkdir $SVNBAK/tmp/$repo -p
sleep 1
\cp -r $BAKDIR/${repo}_${V_OLD_1}:${V_NEW} $SVNBAK/tmp/$repo/
}
[ $? -eq 0 ] && {
# echo "$repo" >>$SCDIR/repository_remote.txt
/bin/rm -rf $BAKDIR/${repo}_${V_OLD_1}:${V_NEW}
}||{
echo "$repo copy to /svnbak/tmp is faild" >>$LOGS/Info.log
echo "$repo copy to /svnbak/tmp is faild" >>/svnbak/linshi.log
}
else
echo "$repo version is newest" >>$LOGS/Info.log
echo "$repo version is newest" >>/svnbak/linshi.log
sleep 1
continue
fi
done < $SCDIR/repository.txt
###################rsync repository.txt to xxx host########################
#[ ! -f $SCDIR/repository_remote.txt ] && {
#echo "==================> Incremental Stop(Version:newest) in Time: $(date +%F-%T) <===========" >>$LOGS/Info.log
#exit 0
#}
#sleep 1
#/usr/bin/rsync -avrz --delete $SCDIR/repository_remote.txt xxx_web@xxx::repolist/repository.txt --password-file=/etc/rsyncd.passwd
#[ $? -ne 0 ] && {
#echo "repository_remote.txt transful failed Time: $(date +%F-%T)" >>$LOGS/Info.log
#}||{
#\cp $SCDIR/repository_remote.txt $SCDIR/repository_remote.txt.bak
#echo "repository_remote.txt transful Successful Time: $(date +%F-%T)" >>$LOGS/Info.log
#/bin/rm -rf $SCDIR/repository_remote.txt
#}
echo "==================> Incremental Stop(Status:Complete) in Time: $(date +%F-%T) <==========" >>$LOGS/Info.log
echo "##SVN 增量备份结束 Time:$(date +%F-%T)##" >>/svnbak/linshi.log
备SVN上还原脚本:
#!/bin/bash
echo -e "\n" >>/root/scripts/svn_incre_restore/logs/Info.log
echo -e "\n" >>/data/svn/linshi.log
echo "##SVN 增量还原开始 Time:$(date +%F-%T)##" >>/data/svn/linshi.log
echo "####################### Recovery Start in Time: $(date +%F-%T) ######################" >>/root/scripts/svn_incre_restore/logs/Info.log
[ ! -d /data/svn/tmp/* ] && {
echo "No Repository Will Be Recovery ..." >>/root/scripts/svn_incre_restore/logs/Info.log
echo "####################### Recovery Complete in Time: $(date +%F-%T) ######################" >>/root/scripts/svn_incre_restore/logs/Info.log
echo "All repository is Neweast" >>/data/svn/linshi.log
echo "##SVN 增量还原结束 Time:$(date +%F-%T)##" >>/data/svn/linshi.log
mailx -s "SVN 每日增量备份及还原" wangbogui@xxx.com </data/svn/linshi.log
#rm -f /data/svn/linshi.log
exit 0
}
while read repo
do
[ ! -d /data/svn/tmp/$repo ] && continue
/usr/local/subversion/bin/svnadmin load /data/svn/$repo < `ls /data/svn/tmp/$repo/*`
V_NEW=`ls /data/svn/tmp/$repo/*|awk -F ":" '{print $2}'`
V_OLD=`/usr/local/subversion/bin/svnlook youngest /data/svn/$repo`
[ $V_NEW -eq $V_OLD ] && {
/bin/rm -rf /data/svn/tmp/$repo
echo "$repo recovery ..OK.." >>/root/scripts/svn_incre_restore/logs/Info.log
echo "$repo recovery is OK" >>/data/svn/linshi.log
}||{
echo "$repo recovery failed" >>/root/scripts/svn_incre_restore/logs/Info.log
echo "$repo recovery is Failed" >>/data/svn/linshi.log
}
done </root/scripts/svn_incre_restore/repository.txt
sleep 1
/bin/chown -R daemon /data/svn
echo "####################### Recovery Complete in Time: $(date +%F-%T) ######################" >>/root/scripts/svn_incre_restore/logs/Info.log
echo "##SVN 增量还原结束 Time:$(date +%F-%T)##" >>/data/svn/linshi.log
mailx -s "SVN 每日增量备份及还原" wangbogui@xxx.com </data/svn/linshi.log
#rm -f /data/svn/linshi.log
SVN全量备份+增量备份脚本的更多相关文章
-
mysql全量和增量备份详解(带脚本)
在日常运维工作中,对mysql数据库的备份是万分重要的,以防在数据库表丢失或损坏情况出现,可以及时恢复数据. 下面对这种备份方案详细说明下:1.MySQLdump增量备份配置执行增量备份的前提条件是M ...
-
Python实现目录文件的全量和增量备份
目标: 1.传入3个参数:源文件路径,目标文件路径,md5文件 2.每周一实现全量备份,其余时间增量备份 1.通过传入的路径,获取该路径下面的所有目录和文件(递归) 方法一:使用os.listdir ...
-
MySQL5.7.18 备份、Mysqldump,mysqlpump,xtrabackup,innobackupex 全量,增量备份,数据导入导出
粗略介绍冷备,热备,温暖,及Mysqldump,mysqlpump,xtrabackup,innobackupex 全量,增量备份 --备份的目的 灾难恢复:意外情况下(如服务器宕机.磁盘损坏等)对损 ...
-
python实现对文件的全量、增量备份
#!/user/bin/env python # @Time :2018/6/6 10:10 # @Author :PGIDYSQ #@File :FileBackup2.py import os i ...
-
oracle全量、增量备份
采用0221222增量备份策略,7天一个轮回 也就是周日0级备份,周1 2 4 5 6 采用2级增量备份,周3采用1级增量备份 打开控制文件自动备份 CONFIGURE CONTROLFILE AUT ...
-
关于Subversion主从备份方式的调整(全量、增量脚本)更新
本文引用于http://blog.chinaunix.net/uid-25266990-id-3369172.html 之前对Subversion服务器作了迁移,关于SVN的架构也走了调整,有单一的服 ...
-
innobackupex在线备份及恢复(全量和增量)
Xtrabackup是由percona开发的一个开源软件,它是innodb热备工具ibbackup(收费的商业软件)的一个开源替代品.Xtrabackup由个部分组成:xtrabackup和innob ...
-
Mysql备份工具xtraback全量和增量测试
Mysql备份工具xtraback全量和增量测试 xtrabackup 是 percona 的一个开源项目,可以热备份innodb ,XtraDB,和MyISAM(会锁表) 官方网址http:// ...
-
[MySQL] innobackupex在线备份及恢复(全量和增量)
安装percona-xtrabackup 方法1: percona-xtrabackup-2.1.9-744-Linux-x86_64.tar.gz(D:\share\src\linux-mysql) ...
-
MySQL数据以全量和增量方式,同步到ES搜索引擎
本文源码:GitHub·点这里 || GitEE·点这里 一.配置详解 场景描述:MySQL数据表以全量和增量的方式向ElasticSearch搜索引擎同步. 1.下载内容 elasticsearch ...
随机推荐
-
『TCP/IP详解——卷一:协议』读书笔记——16
2013-08-26 22:50:54 6.4 ICMP时间戳请求与应答 ICMP时间戳请求允许系统向另一个系统查询当前的时间.返回的建议值是自午夜开始计算的毫秒数(协调的统一时间,Coordinat ...
-
微信公众平台教程和SDK收集
教程收集: 1.Senparc(.net) http://www.cnblogs.com/szw/archive/2013/05/14/weixin-course-index.html 2.方倍工作室 ...
-
VRP介绍以及AC初始化配置-06
VRP介绍 VRP:多功能路由平台(Versatile Routing Platform) 角色:网络操作系统 支撑多种设备的软件平台 提供TCP/IP 路由服务 通用路由平台VRP(Versatil ...
-
Oracle三组难缠的hint no_unnest/unnest,push_subq,push_pred--平展化(转)
经常有人把这三个hint搞混,主如果因为对三种重写道理不清楚.特总结如下.(实验景象为10204)1. no_unnest, unnestunnest我们称为对子查询展开,顾名思义,就是别让子查询孤单 ...
-
Kano模型告诉你“是不是只要企业努力的提高产品或服务质量,顾客满意度就一定会提高吗?”
在 PO在敏捷需求下要遵守哪6条重要原则? 中讲到探索和交付两大阶段的6个原则 其中在原则[做有价值的需求]中讲了两个方法:BSA分析和产品Backlog 其中BSA分析是我在产品规划阶段常使用的 ...
-
ubuntu16.04设置tomcat自启动
我的tomcat名字叫tomcat8_product 1.拷贝catalina.sh到/etc/init.d/目录下 cd tomcat8_product/bin/catalina.sh /etc/i ...
-
Python3学习之路~3.1 函数基本语法及特性、返回值、参数、局部与全局变量
1 函数基本语法及特性 定义: 函数是指将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可 特性: 减少重复代码 使程序变的可扩展 使程序变得易维护 语法定义: d ...
-
本地为Windows,使用Xshell登录Linux云主机
以某东的云主机为实例 1. 下载并安装远程登录软件 下载Xshell软件 下载后双击xshell5_5.0.1332.exe进行安装 2. 安装完成,打开Xshell,并点击新建,根据要求输入相应参数 ...
-
【swiper】 滑块组件说明
swiper 滑块视图容器,其原型如下: <swiper indicator-dots="[Boolean]" indicator-color="[Color]&q ...
-
OpenCV之CvMat、Mat、IplImage之间相互转换实例(转)
OpenCV学习之CvMat的用法详解及实例 CvMat是OpenCV比较基础的函数.初学者应该掌握并熟练应用.但是我认为计算机专业学习的方法是,不断的总结并且提炼,同时还要做大量的实践,如编码,才能 ...