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
1 |
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
1 |
vi minify/hooks/pre-revprop-change |
then insert
1 |
<span style="color: #808080; font-style: italic;">#!/bin/sh </span> <span style="color: #007800;">USER=</span><span style="color: #ff0000;">"$3"</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #ff0000;">"$USER"</span> = <span style="color: #ff0000;">"svnroot"</span> <span style="color: #7a0874; font-weight: bold;">]</span>; <span style="color: #000000; font-weight: bold;">then</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>; <span style="color: #000000; font-weight: bold;">fi</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Only the svnroot user may change revision properties"</span> <span style="color: #000000; font-weight: bold;">>&</span><span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span> |
if you don’t want to use a specific user, simply leave the svn pre-revprop-change hook empty.
1 |
<span style="color: #808080; font-style: italic;">#!/bin/sh</span> |
Enable the start-commit hook
1 |
vi minify/hooks/start-commit |
then insert
1 |
<span style="color: #808080; font-style: italic;">#!/bin/sh </span> <span style="color: #007800;">USER=</span><span style="color: #ff0000;">"$2"</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #ff0000;">"$USER"</span> = <span style="color: #ff0000;">"svnroot"</span> <span style="color: #7a0874; font-weight: bold;">]</span>; <span style="color: #000000; font-weight: bold;">then</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>; <span style="color: #000000; font-weight: bold;">fi</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">"Only the svnroot user may commit new revisions"</span> <span style="color: #000000; font-weight: bold;">>&</span><span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span> |
if you don’t want to use a specific user, simply leave the svn start-commit hook empty
1 |
<span style="color: #808080; font-style: italic;">#!/bin/sh</span> |
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.
1 |
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
1 |
svnsync init svn+ssh://svnroot@svnserver.local/repos/minify http://minify.googlecode.com/svn |
If everything is ok you’ll see
1 |
Copied properties for revision 0. |
You can check mirror repository by using command
1 |
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
1 |
svnsync sync svn+ssh://svnroot@svnserver.local/repos/minify |
Every revision and properties from source repository will be mirrored.
1 |
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 :
1 |
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
1 |
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