Using svnsync to mirror a google code repository

Why use svnsync, there already a repository !

All our websites are put into production using subversion (But not directly, first we update an hidden working copy, then rsync it on filer).

We use minify and log4php with svn:externals and want to keep it versionned to easily switch to new release but don’t want to be dependent on or repositories, that sometime goes into 502 or 503, to put new releases in production. or permit us to use svnsync, let’s see how to easily use it. Note that you can use Google Code repository as a mirror and have your master repository on your server (in case you own the project), but keep in mind that wiki is also in project repository, so front end modification on wiki will alter your mirror repository, and break the sync.

Create the mirror repository

At work, subversion is on an “open bar” mode, no user authentication required at all, we’ve got a general user, and a svn superuser, no use of username or sync-username.

Let’s make the svn superuser the only able to commit and edit properties on the mirror repository, the mirror must be read-only for any method other than ‘svnsync’.

To do that we must enable revision property changes and commit to the dedicated server account on the mirror repository.

Enable the pre-revprop-change hook

then insert

if you don’t want to use a specific user, simply leave the svn pre-revprop-change hook empty.

Enable the start-commit hook

then insert

if you don’t want to use a specific user, simply leave the svn start-commit hook empty

As you see, it’s not 100% secure, it’s only to prevent mistakes.

Give the execution right to both svn hooks

Otherwise you’ll have a message like blocked by pre-revprop-change hook (exit code 255) with no output.

Init the synchronisation

We use svn over ssh, you can also use svn://, http:// whatever protocol you use usually.

Command usage is svnsync init DEST_URL SOURCE_URL

If everything is ok you’ll see

You can check mirror repository by using command

svn:sync-last-merged-rev and svn:sync-from-url are ok

Synchronize the repository

Command usage is svnsync sync DEST_URL

Every revision and properties from source repository will be mirrored.

This could be long, very long, repository has more than 960 000 revisions, and svnsync must read each one.

If you want, you can stop the sync process, but you will have a sync-lock error message like :

Execute this command to be able to resume the sync process

Use & update of the mirror

Now you can checkout and update from the mirror repository without dependence to original repository or network, remember no commit or properties change on the repository only svnsync.

Make manual svnsync or cron to keep the repository up to date.


Leave a Reply