Creating an SVN mirror

If you haven’t had the pleasure of working with a distributed version control system such as Mercurial or Git, you may find that it necessary to take some manual steps to set up a mirror of your repository.

For SVN, this process isn’t well integrated into the system itself, but there are tools we can use to achieve this goal. An important thing to be aware of, is that unlike a distributed, you won’t be able to merge changes from your mirror back into the original repo. You should make sure the only thing writing to the mirrored copy is the svnsync process.

Tthe documentation on the internet is pretty terse for this, here’re the steps which worked for me.

I wanted to locally mirror a repo which is normally servered over https (although it’d work equally well for repos servers using svn or svn+ssh).

  • Remote repo: https://svn.example.org/repos/project
  • Local directory: /home/svn/project

Create an empty SVN repository locally:
svn create /home/svn/project

You need to create a hook script at /home/svn/project/hooks/pre-revprop-change which looks like:

#!/bin/sh

USER="$3"

exit 0

if [ "$USER" = "syncuser" ]; then exit 0; fi

echo "Only the syncuser user may change revision properties" >&2
exit 1

Make the script executable:
chmod 755 /home/svn/project/hooks/pre-revprop-change

Now initialise the repo as a mirror:
svnsync init file:///home/svn/project https://svn.example.org/repos/project

Finally, you can do the sync:
svnsync sync file:///home/svn/project

I have that last command run from cron every minute to keep things up to date:
/etc/cron.d/svnsync
# Sync the SVN mirror every minute
* * * * * root /usr/bin/svnsync sync file:///home/svn/project

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top