Tuesday, April 27, 2010

Windows Subversion Maintenance Scripts

create_repo.bat

@echo off

REM Check command line args to make sure a customer and project name were passed
IF (%1)==() GOTO CMDLINE
IF (%2)==() GOTO CMDLINE

REM If svnadmin is not in your path, uncomment the following
REM PATH=%PATH%;"D:\Program Files\Subversion\bin"

REM Set up variables with the directories
SET CUSTOMER=%1
SET PROJECT=%2
SET CUR_DIR=%~dp0
SET CUR_DIR=%CUR_DIR:\=/%
SET SVN_DIR=%CUR_DIR%/repos/%CUSTOMER%
SET PROJ_DIR=file:///%SVN_DIR%/%PROJECT%

echo Creating directory in %SVN_DIR%

svnadmin create "%SVN_DIR%"
svn -m "Create default structure." mkdir %PROJ_DIR% %PROJ_DIR%/trunk %PROJ_DIR%/tags %PROJ_DIR%/branches
GOTO END

:CMDLINE
echo Usage: %0 ^ ^

:END
echo Done



dump_all.bat

@echo off

SET DUMP_DIR=dumps
SET REPOS_DIR=repos

IF NOT EXIST %DUMP_DIR% (
echo Creating directory %DUMP_DIR%
md %DUMP_DIR%
)

echo Dumping...

FOR /f %%i IN ('dir /B /A:D %REPOS_DIR%\*') DO (
echo Dumping %REPOS_DIR%\%%i to %DUMP_DIR%\%%i.dump
svnadmin dump %REPOS_DIR%\%%i > %DUMP_DIR%\%%i.dump
)


restore_all.bat

@echo off

SET DUMP_DIR=dumps
SET REPOS_DIR=repos

echo Restoring....

REM %%~ni becomes the dump name without .dump

FOR /f %%i IN ('dir /B %DUMP_DIR%\*.dump') DO (
echo Restoring %DUMP_DIR%\%%i to %REPOS_DIR%\%%~ni
svnadmin create %REPOS_DIR%\%%~ni
svnadmin load %REPOS_DIR%\%%~ni < %DUMP_DIR%\%%i
)

No comments: