February 17, 2008 - Tags:

Synchronizing Subversion Repositories

Since Subversion 1.4 you can synchronize repositories easily. This way you can have a local copy which works when you’re offline. Great to keep a copy of your code + history on your laptop. The only thing to watch out for is that you can only synchronize it one-way, so don’t commit anything. Here’s how to do it on Windows:

To save some typing:
set FROM=http://yourserver/svn/repo
set TO=file:///d:/svn/repo

Create a local repository:
svnadmin create %TO%

Svnsync creates properties in the target respository’s revision 0 to track the sync status. To make this work you need to have a rev-prop-change hook (at least an empty one):

echo. > d:\svn\repo\hooks\pre-revprop-change.bat

Call svnsync init to create the properties:

svnsync init %TO% %FROM% --username <USER>

To look at the property we just created type:
svn proplist --verbose --revprop -r 0 %TO%

Not versioned property in Revision 0:
svn:sync-from-uuid : 94eeecdd-d4ee-0310-9089-7d9f06c0e571
svn:sync-last-merged-rev : 165
svn:date : 2005-01-29T18:22:33.902123Z
svn:sync-from-url : http://yourserver/svn/repo

To finally start synchronization call svnsync:

svnsync --non-interactive sync %TO%

If anything goes wrong the target repository may get locked if you call svnsync the next time. You’ll see an error message like this:

Failed to get lock on destination repos, currently held by 'xxxxxx'

To get rid of the lock you can delete the sync-lock property in revision 0:

svn propdel svn:sync-lock --revprop -r 0 %TO%

Now you could also create a post-commit hook which starts a sync everytime something gets commited (or just create a script to run via cron).

1 Comment »

  1. Using SVK you can keep a local copy of your repository locally and be able to commit to it while offline. When you go back online your commits are synchronised back to the source repository.

    Comment by Paul Campbell — August 28, 2008 @ 5:14 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

(C) 2008 - Stephan Brosinski - All Rights Reserved