Recently we were given a task to create a readonly Git mirror of a Subversion repository. We’ve used SubGit and svnsync to accomplish this task, all went pretty smooth and I’ve decided to publish a small HOWTO on that topic.
1. Create empty Subversion repository. This will be a readonly “slave” of the original Subversion repository:
$ svnadmin create slave
2. Enable pre-revprop-change hook in the slave repository. This is needed to make svnsync work:
$ nano slave/hooks/pre-revprop-change
Do not forget to make hook script executable:
$ chmod +x slave/hooks/pre-revprop-change
3. Synchronize slave repository with the master one using svnsync (see topic on replication with svnsync in Subversion Book):
$ svnsync initialize file://home/user/slave http://host/svn/master
$ svnsync synchronize file://home/user/slave
4. Install SubGit into the slave repository, to add Git part (see SubGit Book for more details):
$ subgit configure slave
At this point you may increase idleTimeout setting for SubGit background translation process.
Edit slave/conf/subgit.conf file:
# value is in seconds
idleTimeout = 300
Higher timeout value will allow subgit translation process to be reused between svnsync scheduled invocations.
$ subgit install slave
At this point, Git repository (or multiple repositories) is created. User may access it, e.g. over SSH:
$ git clone ssh://user@slave-host/home/user/slave slave
5. Schedule svnsync runs to enable replication of the new revisions. SubGit will ensure that these revisions are translated to the Git repository too!
$ crontab -e
# m h dom mon dow command
3 * * * * svnsync file:///home/user/slave
svnsync will fetch new revision from the remote repository and SubGit will translate them into Git.
If you’ve followed the steps above you have created a readonly Subversion and Git mirrors of Subversion repository at http://host/repos/master
Both Subversion and Git mirrors resides at /home/user/slave directory.