May
23
Posted on 23-05-2008
Filed Under (Programming) by Johan Känngård

The first is something you should do weekly on your Subversion repository - a full dump. Put the following in a BAT or CMD file on a Windows box, and run it scheduled.


@echo off
REM Creates a full dump of the repository, should be run weekly

for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set year=%%a
for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set month=%%b
for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set day=%%c
for /f \"tokens=1-2 delims=: \" %%a in (\'time /T\') do set hour=%%a
for /f \"tokens=1-2 delims=: \" %%a in (\'time /T\') do set minute=%%b
set TODAY=%year%%month%%day%
set NOW=%hour%%minute%

for /F \"tokens=1 \" %%i IN (\'svnlook youngest c:\\repository\') do call set YOUNGEST=%%i
echo %YOUNGEST% > c:\\backup\\repository\\latestRev.dat
svnadmin dump c:\\repository > c:\\backup\\repository\\svndump_full_rev%YOUNGEST%.%TODAY%%NOW%

The above example makes a dump to c:\backup\repository of your repository at c:\repository named with the most recent revision and todays date and time.
The example below creates incremental dumps using the latestRev.dat file to store the latest revision that was dumped.

  @echo off
  REM Creates a partial dump with all revisions since last full dump, should be run daily

  for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set year=%%a
  for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set month=%%b
  for /f \"tokens=1-4 delims=- \" %%a in (\'date /T\') do set day=%%c
  for /f \"tokens=1-2 delims=: \" %%a in (\'time /T\') do set hour=%%a
  for /f \"tokens=1-2 delims=: \" %%a in (\'time /T\') do set minute=%%b
  set TODAY=%year%%month%%day%
  set NOW=%hour%%minute%

  for /F \"tokens=1 \" %%i in (\'svnlook youngest c:\\repository\') do call set YOUNGEST=%%i
  set PREVIOUS=0
  if not exist c:\\backup\\repository\\latestRev.dat goto nolatestrev

  for /F \"tokens=1 \" %%i in (c:\\backup\\repository\\latestRev.dat) do call set PREVIOUS=%%i

:nolatestrev:
  if %YOUNGEST% == %PREVIOUS% goto noupdate

  echo %YOUNGEST% > c:\\backup\\repository\\latestRev.dat

  svnadmin dump -r %PREVIOUS%:%YOUNGEST% c:\\repository > c:\\backup\\repository\\svndump_incremental_rev%PREVIOUS%to%YOUNGEST%.%TODAY%%NOW%
  goto finally

:noupdate
  echo No dump needed
:finally

I’m no Windows batch file pro, but I got this working anyway with some help from Google.

(3) Comments    Read More