Lenmore Blog -- 我的记事本、备忘录

SVN自动备份、压缩、转移脚本(Windows)

written on Friday, September 4, 2009

1、自动备份、压缩 SvnBackup.bat,此脚本在SVN服务上运行

@echo off
REM 此脚本在0~9点间运行会有Bug,懒的处理了

set rep=%1
if "%rep%"=="" goto error
set svndir=F:\SvnData\%rep%
set bakbase=F:\SvnBackup\
set bakdir=%rep%_%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
set rar="D:\Program Files\WinRAR\rar.exe"

cd /d %bakbase%
if exist %bakdir% goto error

echo 备份%svndir%
mkdir %bakdir%
svnadmin hotcopy %svndir% %bakbase%%bakdir%

echo 压缩并删除目录
%rar% a -df %bakdir% %bakdir%

echo 保留最后3个备份,删除之前的
dir %bakbase%%rep%_*.rar /O:-D > %bakbase%tmp.txt
REM 5+N天
for /F "skip=8 tokens=4″ %%f in (tmp.txt) do @if exist %%f del %%f

goto end

:error
echo 参数错误
rem exit 0

:end
rem exit 0

2、SVN服务器安装FTP服务,建立用户指向到SVN备份目录

3、转移脚本 GetSvnBackup.bat,此脚本在其他机器运行

@echo off
cd /d G:\SvnBackup
ftp -s:G:\SvnBackup\ftp.txt

echo 保留最后7个备份,删除之前的
dir rep1_*.rar /O:-D > tmp.txt
REM 5+N天
for /F "skip=12 tokens=4″ %%f in (tmp.txt) do @if exist %%f del %%f

dir rep2_*.rar /O:-D > tmp.txt
REM 5+N天
for /F "skip=12 tokens=4″ %%f in (tmp.txt) do @if exist %%f del %%f

ftp.txt

verbose off
prompt off
open 192.168.0.3
svnbackup
123456
lcd G:\SvnBackup
mget *.rar
disconnect
bye

This entry was tagged svn