Mirror SVN Repository – For 1.8.x

If you are using older version, refer.

Mirror SVN Repository can be useful to offload server or If you have developers at different location OR you have requirement to keep offsite mirror ready for recovery.
I have used svn proxy. It works fine, but this can not be used for developers sitting in different location as this will not forward commit requests to master server.

Here
Master server 192.168.1.10
Slave server 192.168.222.10

On Master
Start svnserve as read only.

/bin/svnserve -d -R --log-file /var/log/svnserve.log

Master httpd.conf

LoadModule dav_svn_module     /usr/lib/httpd/modules/mod_dav_svn.so
LoadModule authz_svn_module   /usr/lib/httpd/modules/mod_authz_svn.so
 
<Location /svn/repos>
AuthType Basic
AuthName "SVN Authorization Realm"
AuthUserFile /etc/httpd/svn.passwd
Require valid-user
AuthzSVNAccessFile /etc/httpd/svn.authz
DAV svn
SVNParentPath /storage/svnroot/
SVNListParentPath On
SVNIndexXSLT "/repos-web/view/repos.xsl"
#SVNIndexXSLT "/svnindex.xsl"
SVNPathAuthz off
</Location>

On Master create post-commit & post-revprop-change hooks under every repository. Here you can either use following script or replace MYREPO with repository names.
Create hooks

cat svnrepo/hooks/post-commit
#!/bin/bash
REPOS="$1"
MYREPO=`echo "$REPOS" |/bin/gawk -F"/" '{ print $4}'`
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"
/bin/svnsync sync --non-interactive --username svnsync --password 1234 svn://192.168.222.10/storage/svnroot/"$MYREPO" &
 
exit 0
cat svnrepo/hooks/post-revprop-change
#!/bin/bash
REPOS="$1"
MYREPO=`echo "$REPOS" |/bin/gawk -F"/" '{ print $4}'`
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"
/bin/svnsync --non-interactive copy-revprops --username svnsync --password 1234 svn://192.168.222.10/storage/svnroot/"$MYREPO" "$REV" &

On Slave

Slave httpd.conf

LoadModule dav_svn_module   modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
 
<Location /svn/repos>
AuthType Basic
AuthName "SVN Authorization Realm"
AuthUserFile /etc/httpd/svn.passwd
Require valid-user
AuthzSVNAccessFile /etc/httpd/svn.authz
   DAV svn
   SVNParentPath /storage/svnroot/
SVNListParentPath On
SVNIndexXSLT "/repos-web/view/repos.xsl"
SVNPathAuthz off
SVNMasterURI http://192.168.1.10/svn/repos/
</Location>

Slave svnserve Configuration,
Configure svnserve

cat /etc/httpd/svnserve.conf
[general]
password-db = svnsync.passwd
authz-db = svn.authz
 
[sasl]
cat /etc/httpd/svnsync.passwd 
[users]
svnsync = 1234

Start svnserve

/bin/svnserve -d --log-file /var/log/svnserve.log --config-file /etc/httpd/svnserve.conf

Create blank repository

svnadmin create /storage/svnroot/project1
chown apache: /storage/svnroot/project1 -R

Configure svnsync

svnsync init --username svnsync --password mypassword file:///storage/svnroot/project1 svn://192.168.1.10/storage/svnroot/project1
svnsync sync --username svnsync --password mypassword file:///storage/svnroot/project1

create hook

cat svnrepo/hooks/pre-revprop-change 
#!/bin/sh
USER="$3"
if [ "$USER" = "svnsync" ]; then exit 0; fi
echo "Only the svnsync user can change revprops" >&2
exit 1

With the above setup. Slave can be used as svn server for users located in remote office, their commit requests will be proxy to Master server. Once commit on master is complete, post-commit hook will start svnsync for Slave server.
Slave server can be useful to reduce load on master server by providing dedicated resource to check out code.

if you find any missing point in here, please let us know in comment section or tweet us at @linuxreaders. To get more articles like this, subscribe to our RSS feeds / Mails.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trending Posts