Friday, August 3, 2007

SVN Synchronization - How to create mirror repository in Subversion

Hi All,

All of you know subversion is the popular version control system, that suits for a enterprise level development, as it updates revision count for the entire project (i.e., repository) on every commit, unlike CVS, as it keeps individual revision count for each file. So by revision number we can take the old codebase for the entire project on just one click or by single command.

I was trying to create mirror site for main subversion site. I thought it might be helpful for all of us whoever trying the same, So here I am sharing my experience I had on configuring Subversion for Synchronization.

Basically the utility "svnsync" is used to create the mirror repository, and it comes as part of subversion. If you download something from the source-forge site, you will be having the option to download the selected utility either from main server or from any of the mirror site. Most commonly all the major linux distribution, for example debian can be found on so many mirror sites other than the main server.

So what I was trying to achieve was,
-> Create mirror repository
-> Do the periodic sync between the main repository and the mirror repository

Let me explain the operation I tried,


----------------------------------------
Assuming there is svn repository 'main_repo' and the development goes on that. To create the mirror repository in some other system say 'mirror_repo', we need to do the following steps

step1: create a blank repository at the mirror end.
$svnadmin create mirror_repo

NOTE:Repository should be blank at the mirror end. Otherwise sync will not work


step2: create the pre-revprop-change hook
$touch mirror_repo\hook\pre-revprop-change
$cat > mirror_repo\hook\pre-revprop-change
#!/bin/sh
^d
$chmod u+x mirror_repo\hook\pre-revprop-change


step3: initialize synchronization.
$svnsync init --username 'sync_user' file:///path_to/mirror_repo http://site_name/svn_parent_dir/main_repo
Copied properties for revision 0

NOTE:sync_user is the user available in main as well as mirror repository with 'rw' permission.


step4: create cron job to get synchronization done as it should happen periodically. This sync operation replays the commit happened in the main repository to the mirror repository.
$svnsync sync file:///path_to/mirror_repo
Committed revision 1.
Copied properties for revision 1.
Committed revision 2.
Copied properties for revision 2.
Committed revision 3.
Copied properties for revision 3.
...

NOTE: If you break the operation in mid. The repository at the mirror end might get locked and when you do 'sync' again you may get error "Failed to get lock on destination repos". To rectify this you have to run the following command "svn propdel svn:sync-lock --revprop -r 0 ${TOREPO}"

So as per our example the command will be,
$svn propdel svn:sync-lock --revprop -r 0 file:///path_to/mirror_repo
property 'svn:sync-lock' deleted from repository revision 0
----------------------------------------



Points to be noted:

1)Both main and mirror repository can be specified by any of the supported protocol

http
https
svn
svn+ssh
file

NOTE:If you use protocol other than 'file', at the mirror end there sould be 'ra' layer (repository access layer),For this 'subversion-devel' package should be installed in the mirror end, because this package only contains "ra" layer.

2)It is not mandatory to run the 'svnsync' utility in mirror site. You can even run the utility in any system which has access to the main and mirror site repoistory.


Hope this helps...

--
You can reach me at anand.sadasivam@googlemail.com

No comments: