svnsync alternative

svnsync, like its doc says, is the Subversion remote repository mirroring tool. We may need to have a mirror for backup, or for faster checkout/update in a remote datacenter.

There are lots of documentations and articles about how to set up a mirror using svnsync. But in a situation that connection between mirror and master is really bad, svnsync fails frequently and leaves the mirror locked. Then we have to manually unlock the mirror repository to get it recovered.

Is there an alternative? Short answer – YES:

svnrdump --incremental --non-interactive -r$start_version:$target_version http://master/path/to/repo | pbzip2 | ssh $MIRROR_HOST "bzcat | svnadmin load /path/to/repo"

This one-liner alone doesn’t work, but we just need to write a simple script to help.

It’s easy to decide the version range to sync. To get the current revision of a repository:

svn info http://server/path/to/repo | egrep '^Revision: [0-9]+$' | sed -e 's/^Revision: //i'

Some other points:

  • Initialise the mirror repository as usual. Use svnadmin create.
  • svnrdump is available since Subversion 1.7. It’s like “svnadmin dump” but can be run on remote servers, a handy replacement if you don’t have access to the master server file system.
  • bzip2 is slow and may become the bottleneck of the pipeline, so we’d better use the parallel version. However uncompressing is always faster, and the ordinary bzcat suffices.
  • Schedule it in crontab and make it run every minute, you’ll have a mirror always in sync (almost!). But remember to use a lock to make sure only at most one instance runs at any time.
  • I bet you don’t want to commit into the mirror repo, so create a pre-commit hook and make it just “exit 1”
  • You may need to add username/password information to the svn commands above.

I personally enjoy sync’ing repositories with this method. Sometimes I receive error reports, but they recover automatically.

Leave a comment

Your email address will not be published. Required fields are marked *

Prove your intelligence before hitting * Time limit is exhausted. Please reload CAPTCHA.