分类: 项目管理
2011-02-17 11:38:41
我们的svn服务器开始搭建在windows2003系统上,搭建好以后需要定期进行数据备份。备份策略是每周进行一次全备份,每天进行一次增量备份,备份文件保存在本地,同时拷贝一份到远程服务器上。于是我编写了几个批处理文件实现这个功能,通过windows的计划任务调度。下面是各个脚本的具体内容。
1、全备份脚本(svnbackup.bat),Z:\是通过网络映射的远程服务器备份目录
@Echo off
@title backup svn files
Rem 每周一次全备份
Rem 获取版本信息
svnlook youngest F:\Repositories\Cmp_Vob > F:\svntools\version.txt
Rem 执行svn 全备份
cd F:\Program Files\VisualSVN Server\bin
svnadmin dump F:\Repositories\Cmp_Vob > F:\svntools\svnbackup\svnbackup_all_%DATE:~0,10%
Rem 备份其他文件
copy F:\Repositories\htpasswd F:\svntools\svnbackup\htpasswd_%DATE:~0,10%
copy F:\Repositories\authz F:\svntools\svnbackup\authz_%DATE:~0,10%
Rem 拷贝备份文件
cd F:\svntools\svnbackup
copy *_%DATE:~0,10% Z:\
2、每日增量备份脚本(svnbackup_day.bat)
@Echo off
@title backup svn files
Rem 每日增量备份
Rem 获取最新版本信息
cd F:\svntools
svnlook youngest F:\Repositories\Cmp_Vob > F:\svntools\tmp.txt
for /f "tokens=* delims= " %%a in (tmp.txt) do (
set /a youngest=%%a
)
Rem 获取上次备份版本信息,并进行增量备份
for /f "tokens=* delims= " %%b in (version.txt) do (
set /a old=%%b
)
Rem 进行增量备份
if %youngest% gtr %old% (
svnadmin dump --revision %old%:%youngest% F:\Repositories\Cmp_Vob > F:\svntools\svnbackup\svnbackup_day_%DATE%
)
Rem 记录最新版本信息
echo %youngest% > F:\svntools\version.txt
Rem 拷贝备份文件
cd F:\svntools\svnbackup
copy *_%DATE:~0,10% Z:\
3、备份文件清理(只保留最近7天的备份文件)
@echo off
set _tian=7
>tmptmp.vbs echo wscript.echo dateadd("d",-%_tian%,date)
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo tmptmp.vbs') do (
set /a y=%%i,m=100%%j%%100,d=100%%k%%100
)
if %m% lss 10 (set "mm=0%m%") else (set "mm=%m%")
if %d% lss 10 (set "dd=0%d%") else (set "dd=%d%")
set "difdate=%y%-%mm%-%dd%"
del/q tmptmp.vbs
del /q F:\svntools\svnbackup\*%difdate%