SVN每日定时备份脚本

SVN每日定时备份脚本

SVN每日定时备份脚本:

@ECHO off
REM SVN安装目录
SET SVN_HOME="D:\Program Files\VisualSVNServer"
REM 版本库根目录
SET REPOSITORY_ROOT=D:\Repositories
REM 备份根目录
SET BACK_HOME=E:\svnbak
REM 备份目录
SET BACK_DIRECTORY=%BACK_HOME%\%DATE:~,%
SET BACK_LOG=%BACK_HOME%\backup.log set DaysAgo=
call :DateToDays %date:~,% %date:~,% %date:~,% PassDays
set /a PassDays-=%DaysAgo%
call :DaysToDate %PassDays% DstYear DstMonth DstDay
set DstDate=%DstYear%-%DstMonth%-%DstDay% SET DEL_BACK_DIRECTORY=%BACK_HOME%\%DstDate% IF EXIST %BACK_DIRECTORY% (
ECHO "备份目录%BACK_DIRECTORY%已存在!请清空。"
GOTO END
) ECHO "删除备份目录%DEL_BACK_DIRECTORY%" RD /q /s %DEL_BACK_DIRECTORY%" ECHO "创建备份目录%BACK_DIRECTORY%" >> %BACK_LOG%
MD %BACK_DIRECTORY%
REM 遍历版本库目录,备份每个仓库
FOR /R %REPOSITORY_ROOT% %%I IN (.) DO (
  IF EXIST "%%I\conf\svnserve.conf" (
    ECHO "正在备份版本库%%~fI"
%SVN_HOME%\BIN\SVNADMIN hotcopy "%%~fI" %BACK_DIRECTORY%\%%~nI
    ECHO "版本库%%~fI已备份到%BACK_DIRECTORY%\%%~nI"
)
)
GOTO END :DateToDays %yy% %mm% %dd% days
setlocal ENABLEEXTENSIONS
set yy=% & set mm=% & set dd=%
if %yy% LSS if %yy% LSS (set yy=%yy%) else (set yy=%yy%)
set /a dd=%dd%%%,mm=%mm%%%
set /a z=-mm,z/=,y=yy+-z,m=mm+*z-,j=*m+
set /a j=j/+dd+y*+y/-y/+y/-
endlocal & set %=%j% & goto :EOF :DaysToDate %days% yy mm dd
setlocal ENABLEEXTENSIONS
set /a a=%+,b=*a+,b/=,c=-b*,c/=,c+=a
set /a d=*c+,d/=,e=-*d,e/=,e+=c,m=*e+,m/=,dd=*m+,dd/=
set /a dd=-dd+e+,mm=-m/,mm*=,mm+=m+,yy=b*+d-+m/
(if %mm% LSS set mm=%mm%)&(if %dd% LSS set dd=%dd%)
endlocal & set %=%yy%& set %=%mm%&set %=%dd%& goto :EOF :END pause EXIT
05-11 20:45