Subversion repository mirror

Creating a mirror of your Subversion repository means you have an up to date copy of your repository in a safe place. This guide shows how to set up a mirror and configure it for synchronisation. The instructions are for Windows.

Setting up the mirror uses svnsync which can be very slow over the network. It’s better to take a dump of the repository and load that into the mirror before starting the sync.

Take a backup

On the central repository:
$ cd c:\temp
$ svnadmin dump c:\subversion\my_repository --incremental -q > my-repository.dump
Create a 7zip archive of the dump file and delete the dump.
Copy the archived dump file to the repository mirror machine.

Create the mirror

On the mirror’s machine:
$ mkdir c:\repos && cd c:\repos
$ svnadmin create my-mirror

Load the dump file.
$ svnadmin load my-mirror -q < c:\temp\my-repository.dump

Serve up.
$ svnserve -d -r c:\repos\my-mirror
$ svn info svn://localhost/

Allow write access

anon-access = none
auth-access = write
password-db = passwd.txt
authz-db = authz.txt

repobot = Robot1

repobot = rw

Note: It can be easier to set up with anon-access = write and once it’s all working then upgrade the security.

Set up a pre-revision hook

[ > Step 3.]
$ cp C:\repos\my-mirror\hooks\pre-revprop-change.tmpl pre-revprop-change.bat
set repository=%1
set revision=%2
set userName=%3
set propertyName=%4
set action=%5

:: Allow editing of revision properties for user.
if "%userName%" == "repobot" goto :eof else goto :ERROR_USER

echo Only admin user may change revision properties. >&2

exit 1

Set up properties to allow svnsync with the pre-populated mirror

$ svn info https://repo-box:8443/svn/my_repository

Use the UUID of the remote:
$ svn propset --revprop -r0 svn:sync-from-uuid 5aab9995-1597-de4e-ac02-ede68baf940a svn://localhost/

Use the last merged revision number:
$ svn propset --revprop -r0 svn:sync-last-merged-rev 14175 svn://localhost/

Set to sync from url:
$ svn propset --revprop -r0 svn:sync-from-url https://repo-box:8443/svn/my_repository svn://localhost/

Initial Sync

$ svnsync synchronize svn://localhost/


svnsync --non-interactive --steal-lock --sync-username repobot --sync-password Robot1 --source-username repobot --source-password Robot1 sync svn://mirror-box/ svn://repo-box/

$ sc create SvnServe binpath= "\"%programfiles%\CollabNet\Subversion Client\svnserve.exe\" --service -r c:\subversion\my_repository" depend= Tcpip start= auto
$ net start svnserve

Create Windows Service for svnserve

sc delete SvnServe
sc create SvnServe binPath= "%programfiles%\TortoiseSVN\bin\svnserve.exe --service -r c:\repos\my-mirror" depend= Tcpip start= auto
net start SvnServe


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s