Using svnsync to mirror a google code repository
By Cyrille Mahieux on Wednesday, May 12 2010, 20:21 - Subversion - Permalink
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 code.google.com or apache.org repositories, that sometime goes into 502 or 503, to put new releases in production.
code.google.com or apache.org 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
svnadmin create /repos/minify
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
vi minify/hooks/pre-revprop-change
then insert
#!/bin/sh USER="$3" if [ "$USER" = "svnroot" ]; then exit 0; fi echo "Only the svnroot user may change revision properties" >&2 exit 1
if you don't want to use a specific user, simply leave the svn pre-revprop-change hook empty.
#!/bin/sh
Enable the start-commit hook
vi minify/hooks/start-commit
then insert
#!/bin/sh USER="$2" if [ "$USER" = "svnroot" ]; then exit 0; fi echo "Only the svnroot user may commit new revisions" >&2 exit 1
if you don't want to use a specific user, simply leave the svn start-commit hook empty
#!/bin/sh
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.
chmod +x minify/hooks/start-commit chmod +x minify/hooks/pre-revprop-change
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`
svnsync init svn+ssh://svnroot@svnserver.local/repos/minify http://minify.googlecode.com/svn
If everything is ok you'll see
Copied properties for revision 0.
You can check mirror repository by using command
svn proplist --revprop -r 0 -v svn+ssh://svnroot@svnserver.local/repos/minify Unversioned properties on revision 0: svn:sync-from-uuid : c230a260-702f-0410-900f-efd535441baf svn:sync-last-merged-rev : 412 svn:date : 2007-05-01T22:46:50.958069Z svn:sync-from-url : http://minify.googlecode.com/svn
svn:sync-last-merged-rev and svn:sync-from-url are ok
Synchronize the repository
Command usage is `svnsync sync DEST_URL`
svnsync sync svn+ssh://svnroot@svnserver.local/repos/minify
Every revision and properties from source repository will be mirrored.
Committed revision 1. Copied properties for revision 1. Transmitting file data .. Committed revision 2. Copied properties for revision 2. Transmitting file data .
This could be long, very long, apache.org 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 :
Copied properties for revision 625. Killed by signal 2. svnsync: Caught signal svnsync sync svn+ssh://svnroot@svnserver.local/repos/log4php Failed to get lock on destination repos, currently held by 'svnserver.local:16655307-acde-47f1-b392-15e547cc99e1' Failed to get lock on destination repos, currently held by 'svnserver.local:16655307-acde-47f1-b392-15e547cc99e1'
Execute this command to be able to resume the sync process
svn propdel svn:sync-lock --revprop -r 0 svn+ssh://svnroot@svnserver.local/repos/log4php
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.
Resources
http://svn.apache.org/repos/asf/subversion/trunk/notes/svnsync.txt