HowtoForge

Creating a read-only mirror of your SVN repository with SVK

Creating a read-only mirror of your SVN repository with SVK 

Say, you've got an SVN for your OpenSource project and would like to mirror it to some remote location that hosts opensource projects (such as SourceForge.net or dev.java.net). I'll skip the phase of an account and project registration and assume you've already got your credentials and SVN repo url. I also assume you are on Debian or Ubuntu and your SVN is up and running under Apache httpd.

There's a tool called svnsync that comes with SVN 1.4 by default that is designed for exactly the same purpose, but there's one thing that prevents us from using it in this case. It requires a custom svn hook to present on the target repository and that's impossible to customize anything in our case.

What you do is install SVK first:

# aptitude install svk

Roughly saying, SVK is a superset over SVN and thus allows some advanced tricks such as repo synchronization. There's a Version Control with SVK book you may refer as a in-depth SVK guide. I'll stay brief. The concept is that you create an SVK repository (the "depot") that would contain a copy of all SVN repos involved (your primary repo and those you dump info to) and then sync these copies.

As we want repos to be synced every time a commit is made, SVN hooks procedure would be utilized and in our case that would happen under apache httpd user.

So, to make things simple let's log under that account and perform the required routine.

# su www-data

Now what we need is to do is initialize the default depot.

$ svk depotmap

Edit the path to specify where you'd like to store depot. I'd choose /var/opt/svk/local.

Now you are able to create at least 2 mirrors: one for the local repo and one for the remote (nothing prevents you from having multiple mirrors):

$ svk mirror //local file:///var/opt/svn

That's how we mapped repo location (named "local") directly to the file system location where svn repository resides.

$ svk mirror //remote https://myproject.svn.sourceforge.net/svnroot/myproject

The same goes for remote repo, in this case hosted on SourceForge.net. You'll need to permanently accept certificate and provide you user name and password to get cached.
As the remote repo will be read-only, we'll sync it only once

$ svk sync //remote

and then perform the actions that will be later performed by post-commit script.

$ svk sync //local
$ svk smerge --baseless --incremental --verbatim //local //remote

The latter command will sync local repo with the remote one preserving all commit details.
For this to be done automatically after a commit to the local repo is done, create a file named post-commit in the hooks dir of you local SVN repo and put those commands into it. Make it executable by

$ chmod +x ./post-commit #considering you are in the ''hooks'' dir

That's it, check it out.

 

<please note that the tutorial has been created by> 

Alex Yanchenko, www.centricware.org

Creating a read-only mirror of your SVN repository with SVK