Pre-Requisites:
- Windows 2003 (not tested on 2000 or 2008)
- Subversion installed locally (tools and repository) with the \bin folder in the path
What this script does:
- If I call it with "FULL" it will:
- delete all previous subversion dumps
- create a new dump, using deltas, named "FULL_REV-#_YYYY-MM-DD.svndump" where # is the current revision number
- If I call it with "INC" it will:
- create a new dump incremental from the previous revision number, named "INC_REV-#_YYYY-MM-DD.svndump"
- Store the revision number of the last successful dump, and then perform the next incremental off that instead of assuming just N-1 (in case previous night's job failed)
- Utilize the "ERR_FLAG" to send errors to our monitoring system.
- You can download the script here: svn_dump_8.4.11.rar
- Download the code
- Extract it anywhere you want to run it
- Modify the file to replace the values of "RepoPath" and "DumpPath" with the proper locations for your environment
- Execute either as "svn_dump INC" or "svn_dump FULL" (see above for what each does).
For reference, here's the script code:
@ECHO OFF
SETLOCAL
SET VERSION=v8.4.11 Aaron Dodd
SET USAGE=svn_dump.cmd [FULL -or- INC]
:: Settings
::===========================================================================
SET RepoPath=D:\state_management\repository
SET DumpPath=D:\state_management\repository_dumps
:: Date/Time formatting
::---------------------
FOR /F "Tokens=2" %%I in ( " %date% " ) Do Set StrDate=%%I
FOR /F "Tokens=1 delims=/ " %%M in ( " %StrDate% " ) Do Set Month=%%M
FOR /F "Tokens=2 delims=/ " %%D in ( " %StrDate% " ) Do Set Day=%%D
FOR /F "Tokens=3 delims=/ " %%L in ( " %StrDate% " ) Do Set Year=%%L
FOR /F "Tokens=1 delims=. " %%I in ( " %time% " ) Do Set StrTime=%%I
FOR /F "Tokens=1 delims=: " %%H in ( " %StrTime% " ) Do Set Hour=%%H
FOR /F "Tokens=2 delims=: " %%M in ( " %StrTime% " ) Do Set Minute=%%M
FOR /F "Tokens=3 delims=: " %%S in ( " %StrTime% " ) Do Set Second=%%S
:: Process Arguments
::------------------
IF '%1' == '' GOTO USAGE
IF "%1" EQU "FULL" SET DumpType=FULL
IF "%1" EQU "full" SET DumpType=FULL
IF "%1" EQU "INC" SET DumpType=INC
IF "%1" EQU "inc" SET DumpType=INC
IF '%DumpType%' == '' GOTO USAGE
:: Verify Dependencies
IF NOT EXIST "%RepoPath%" CALL :ERROR_PATH REPOSITORY
IF NOT EXIST "%DumpPath%" CALL :ERROR_PATH DUMP
SVNADMIN 2> NUL
IF %ErrorLevel% EQU 9009 CALL :ERROR_DEP SVNADMIN
SVNLOOK 2> NUL
IF %ErrorLevel% EQU 9009 CALL :ERROR_DEP SVNLOOK
:: MAIN
::===========================================================================
::Determine latest subversion revision number
::-------------------------------------------
FOR /F %%Y IN ('SVNLOOK youngest "%RepoPath%"') DO SET RepoVer=%%Y
SET /A RepoPriorVer=%RepoVer% - 1 >NUL
SET DumpFile=%DumpPath%\%DumpType%_REV-%RepoVer%_%Year%-%Month%-%Day%.svndump
:: Clean up old svn dumps
::-----------------------
IF "%DumpType%" EQU "FULL" DEL /Q "%DumpPath%\*.svndump" >NUL
:: Perform backup
::---------------
IF "%DumpType%" EQU "FULL" SVNADMIN dump "%RepoPath%" --deltas > %DumpFile%
IF "%DumpType%" EQU "INC" SVNADMIN dump "%RepoPath%" -r %RepoPriorVer%:%RepoVer% --incremental > %DumpFile%
GOTO END
:: Subroutines
::===========================================================================
:USAGE
ECHO %VERSION%
ECHO %USAGE%
ECHO Edit this script to change where the repository path is, and where to save the dump
GOTO END
:ERROR_DEP
ECHO !!ERROR!! - Dependency not found
IF "%1" EQU "SVNADMIN" ECHO svnadmin.exe cannot be found.
IF "%1" EQU "SVNLOOK" ECHO svnlook.exe cannot be found.
ECHO Verify Subversion is installed and the \bin folder is in the system-wide PATH environment variable.
SET ERR_FLAG=1
GOTO END
:ERROR_PATH
ECHO !!ERROR!!
IF "%1" EQU "REPOSITORY" ECHO Cannot find %RepoPath%
IF "%1" EQU "DUMP" ECHO Cannot find %DumpPath%
SET ERR_FLAG=1
GOTO END
:END
ENDLOCAL
2 comments:
here's a modification for french servers ...dates :-)
Set StrDate=%date%
FOR /F "Tokens=1 delims=/ " %%D in ( " %StrDate% " ) Do Set Day=%%D
FOR /F "Tokens=2 delims=/ " %%M in ( " %StrDate% " ) Do Set Month=%%M
FOR /F "Tokens=3 delims=/ " %%L in ( " %StrDate% " ) Do Set Year=%%L
FOR /F "Tokens=1 delims=. " %%I in ( " %time% " ) Do Set StrTime=%%I
FOR /F "Tokens=1 delims=: " %%H in ( " %StrTime% " ) Do Set Hour=%%H
FOR /F "Tokens=2 delims=: " %%M in ( " %StrTime% " ) Do Set Minute=%%M
FOR /F "Tokens=3 delims=: " %%S in ( " %StrTime% " ) Do Set Second=%%S
Thx a lot for this great script that doesn't hang unlike vbs ...
IZ
http://www.gpit.fr
Any ideas on how to get the expected FS format to be 3 instead of 2?
Post a Comment