Friday, October 4, 2013

Subversion Mirror Repository Using Svnsync


How to Set up a Subversion Mirror Repository Using Svnsync...


Starting subversion 1.4 you have a new tool called svnsync with which you can maintain mirror repositories quite easily. What I like about this is commit base synchronization.

Say you have your SVN on server'A' and you want to backup on server 'B'. Every time the developer makes a commit to main server 'A' ..it automatically gets commited to 'B'. Isn't that wonderful !!!

Time to say goodbye to shell scripts and cron jobs and welcome svnsync..

Create the svn repository and a user to sync commits on to remote server

Steps to follow:

Logon to remote server -->cd to repositories-->create a repository

How to create a repository?

svnadmin create test-repo

svn info repopath --> This is to verify that your repository is at version zero or else you will have problems setting up svnsync

Now create a user called 'syncuser' to do the sync. Remember only this user or any user you want to setup to do this sync can only do this operation.
I have created the user on GUI and it was simple

Now, we need to set up a hook to let svnsync change the properties.
You will create this in hooks folder
File name: pre-revprop-change

#!/bin/sh
USER="$3"
if [[ "$USER" = "syncuser" || "$USER" = "toolsuser" ]]; then exit 0; fi
echo "Only the sync user may commit new revisions as this is a read-only, mirror repository." >&2

exit 1

We should grant access to the user running svnsync on the main machine 'A' by copying its ssh key to .ssh/authorized_keys

Now move to server 'A' 

Steps to follow:

Step1:

svnsync init Dest-url source-url

Step2:

svnsync sync Dest url

step3:

Set up the hook in hooks folder
File Name: post-commit

#!/bin/sh
svnsync synchronize repopath --username =syncuser --password= pwd
exit 0

REPOS="$1"
REV="$2"

commit-email.pl "$REPOS" "$REV" commit-watchers@example.org

log-commit.py --repository "$REPOS" --revision "$REV"

Dont forget to gtrant 775 permission to the hooks files you have created or else it wont work :(

Thats it...you are all set 

you can always check if the repo on both sides on server is at same revision using svn info


Thanks
Bhargavi











No comments:

Post a Comment