Mirroring SVN Repositories Read-Only

The svnsync tool allows you to create a read-only copy of a repository. Since different systems can use different database storage formats (i.e., different Berkeley DB versions), simply copying the database files is not a good solution as the database files may be incompatible. svnsync can operate over all standard Subversion protocols (http, https, svn and svn+ssh).

In these examples, we are going to create a read-only mirror of a repository myrepo located on svnmaster.domain.ext over the https protocol.

Setting up the mirror repository

First create the mirror repository on the server using svnadmin:

  $ svnadmin create ~/mymirror

Now we need to add a commit hook that will allow svnsync to make arbitrary revprop changes:

  $ cat <<'EOF' > ~/mymirror/hooks/pre-revprop-change
if [ "$USER" = "myusername" ]; then exit 0; fi
echo "Permission denied"
exit 1
  $ chmod +x ~/mymirror/hooks/pre-revprop-change

Change myusername for the user that will be running svnsync (typically your username, but you could use a sub-account as well).

Preparing the sync

Run svnsync init to prepare the sync. This will copy a few properties, but no data is going to be copied yet. If you are using some form of authentication, it will prompt for your username/password.

  $ svnsync init file://$HOME/mymirror https://svnmaster.domain.ext/myrepo
Synchronizing the data

Now you can start copying the data. The initial sync can take a very long time if you have a large number of revisions.

  $ svnsync --non-interactive sync file://$HOME/mymirror

Be careful not to abort the sync (i.e., using control+c) or you will have to clean up the lock files in order to resume the sync. If this happens, stale locks can be removed with svn propdelete:

  $ svn propdelete svn:sync-lock --revprop -r 0 file://$HOME/mymirror
Keeping the data synchronized

One way to do this is by periodically invoking svnsync from your crontab:

  0 2 * * * * svnsync --non-interactive sync file://$HOME/mymirror

But it is also possible to trigger immediate synchronization whenever a commit is made. On the master repository, append the following to your myrepo/hooks/post-commit file:

  svnsync --non-interactive sync mirror-url &

Substitute mirror-url for the URL of the mirror repository, such as https://svnmirror.domain.ext/mymirror.

To propagate other operations such as the edition of log messages, append the following to myrepo/hooks/post-revprop-change as well:

  svnsync --non-interactive copy-revprops mirror-url ${REV} &

© 2024 CubeSoft Communications
All Rights Reserved.