How do I back up a Subversion repository?
Author: Deron Eriksson
Description: This tutorial demonstrates how to back up a subversion repository.
Tutorial created using: Windows 7


Page:    1

This tutorial will show two ways of making a full SubversionW repository backup on Windows, along with a batch file to put these backups on a separate server.

When backing up a subversionW repository, it's a good idea not to rely on a basic recursive copy command. Rather, one of Subversion's backup methods should be used. The first method is the "hotcopy" command, such as the following:

svnadmin hotcopy C:\dev\svn-1.6.6\repository \\SEQUOIA\svn-ultor-backup\repo1\hotcopy\repository-backup

In this example, a hotcopy of the original repository (at C:\dev\svn-1.6.6\repository) is made to a mapped network drive on the SEQUOIA server. The backup repository is a complete Subversion repository, which consists of a directory containing the various files and directories that make up a Subversion repository.

Another command that can be used to perform a Subversion backup is the "dump" command. When used with the "--incremental" option, you can perform an incremental backup. If the "--incremental" switch is not specified, then a full backup is performed. Here is an example of a "dump" command:

svnadmin dump C:\dev\svn-1.6.6\repository > C:\dev\svn-1.6.6\repository-backup.dmp

This dump command makes a full backup of the repository at C:\dev\svn-1.6.6\repository and stores it as a dump file, named repository-backup.dmp. Unlike the hotcopy command, which gives you a backup as a full directory structure, the dump command gives you a backup as a single dump file.


Next, let's be extra safe and create a Windows batch file that we can run to back up the repository to another server both as a hotcopy and as a dump file. The original repository is located at:

C:\dev\svn-1.6.6\repository

We'll backup to the following remote locations:

\\SEQUOIA\svn-ultor-backup\repo1\dump\
\\SEQUOIA\svn-ultor-backup\repo1\hotcopy\

We'll label each backup with the current _YEAR_MONTH_DAY_HOUR_MINUTE_SECOND at the time of backup.

Subversion Dump and Hotcopy Batch File


@echo off

set SVN_DIR=C:\dev\svn-1.6.6\
set SVN_REPO_DIR=%SVN_DIR%repository
set SVN_REPO_DUMP_FILENAME=repository-backup.dmp
set SVN_REPO_DUMP=%SVN_DIR%%SVN_REPO_DUMP_FILENAME%

set DEST_DIR=\\SEQUOIA\svn-ultor-backup\repo1\


:: do a dump of repo
echo creating dump file
svnadmin dump %SVN_REPO_DIR% > %SVN_REPO_DUMP%

:: copy dump file to backup location
set YEAR=%date:~10,4%
set MONTH=%date:~4,2%
set DAY=%date:~7,2%
set THE_DATE=%YEAR%_%MONTH%_%DAY%
echo Date: %THE_DATE%
set SPACE_CHECK=%time:~0,1%
if "%SPACE_CHECK%"==" " goto handlehourspace
set HOURS=%time:~0,2%
goto hourdone
:handlehourspace
set HOURS=0%time:~1,1%
:hourdone
set MINUTES=%time:~3,2%
set SECONDS=%time:~6,2%
set THE_TIME=%HOURS%_%MINUTES%_%SECONDS%
echo Time: %THE_TIME%
set SOURCE=%SVN_REPO_DUMP%
:: echo Source: %SOURCE%
set DEST=%DEST_DIR%dump\%SVN_REPO_DUMP_FILENAME%_%THE_DATE%_%THE_TIME%
:: echo Destination: %DEST%
echo copying dump file
copy %SOURCE% %DEST%

:: do a hotcopy of repo
echo making hotcopy of repository
svnadmin hotcopy %SVN_REPO_DIR% %DEST_DIR%hotcopy\repository_%THE_DATE%_%THE_TIME%

This batch file makes a local dump file and then copies this dump file to the remote location, labeling the remote dump file with the _YEAR_MONTH_DAY_HOUR_MINUTE_SECOND so we can tell when it was created.

After this, the batch file performs a hotcopy of the repository, where the hotcopy destination is labeled with _YEAR_MONTH_DAY_HOUR_MINUTE_SECOND.


To make daily backups, we can set up a Task in the Windows Task Scheduler. Here, we can see that I created a "svn backup" Task.

'svn backup' Task in Task Scheduler

I set the task to be triggered each night at 10 PM.

Task triggered daily at 10 PM

When the task is triggered, the C:\dev\svn-repo1-backup.bat batch file is executed. This performs the dump and hotcopy backups.

Task action executes our batch file

On the remote SEQUOIA server, we can see our Subversion backups, where each one is labeled with the date and time of the backup. The dump backups are stored in the dump directory, and the hotcopies are stored in the hotcopy directory.

Subversion repository dump and hotcopy backups

Of course, to back up your repository, you really only need to do a hotcopy or a dump, not both.

Page:    1