There are a few ways to create a mirror SVN repository from a master repository.
Some are slower than others but all of the ones mentioned below are reliable.
The standard way:
(All operations below are done on the mirror server)
– Delete the old mirror repository
– svnadmin create {path of repo}
– svnsync init {path of repo} {master URL}
– svnsync sync {path of repo}
– set file permissions of repo
Here is a small crude script which does this job. Please adapt to your needs.
############################################################
# Script to fully recreate a mirror repo from master repo
############################################################
repo="test-repo"
svndir="/home/svnadm/svn"
hooksskeldir="/home/svnadm/etc/skel/hooks_svn"
master="svn.mydomain.com"
repouser="svnadm"
syncuser="syncuser"
syncpass="secret"
# Deleting the old repo ${svndir}/${repo}
rm -rf ${svndir}/${repo}
#--------
# create the new repo
svnadmin create ${svndir}/${repo}
#--------
# replace hooks
rm ${svndir}/${repo}/hooks/*
cp -a ${hooksskeldir}/* ${svndir}/${repo}/hooks/
#--------
# Initialize the mirror repo from the master
svnsync init --source-username ${syncuser} --source-password ${syncpass} file://${svndir}/${repo} http://${master}/${repo}
#--------
# Synchronize the repo .... this can take a while
svnsync sync --source-username ${syncuser} --source-password ${syncpass} file://${svndir}/${repo}
#--------
# Set the file permission on the new created repository.
find ${svndir}/${repo}/ -type d -exec chmod 2775 '{}' \;
find ${svndir}/${repo}/ -type f -exec chmod g+w '{}' \;
chmod 444 ${svndir}/${repo}/format
The fast way:
(All operations below are done on the mirror server)
# Copy method (faster)
==============================
# Steps
– make an rsync to create a replica of the master repo
– do a very small adaptation to a special file in the mirror repo (telling where the master is)
– Replace the hooks scripts/files if needed
– Set the repos access rights
– The verify the mirror repo with svnsync
– If no errors occur, then that’s it.!
Some explanation:
There is absolutely no differences between the master and a mirror repo except!!!
the mirror repo MUST know where the master is (URL).
This information is located in this file in the mirror repo:
{repo-root-dir}/db/revprops/0/0
Each svn information in this file is covered by 2 lines of text:
First line: {Type}{Space}{Value}
Type:V=Value K=key
Space: the space character
Value: the number of characters the Info (located in the line following this one) contains.
Second line: Info needed
Example: Our interest here is to make sure the mirror has the info of URL of the svn master repo which is located on lines 7 and 8.
Line 7: V 38
Line 8: http://svn.example.com/test-repo
This means the URL on line 8 is a Value(V) of 38 characters long.
Adjust these 2 lines appropriately and save the file.
The same principle applies to all of the lines in this file.
I strongly recommend NOT to change any of the other lines unless you really know what you’re doing.
After that you only need to replace the hook scripts and set the repo file access rights(if needed) and then verify that the mirror repo is in sync with the master using svnsync command. If no output or some SVN items are being synchronized (which were committed during the rebuilding of the mirror repo) then all is OK, the mirror repo is healthy and in sync.
Here is a small crude script which does this job. Please adapt to your needs.
############################################################
# Script to fully recreate a mirror repo from master repo
############################################################
repo="test-repo"
svndir="/home/svnadm/svn"
hooksskeldir="/home/svnadm/etc/skel/hooks_svn"
master="svn.mydomain.com"
repouser="svnadm"
syncuser="syncuser"
syncpass="secret"
#--------
# Emptying the existing repo ${svndir}/${repo} on mirror
rm -rf ${svndir}/${repo}
mkdir ${svndir}/${repo}
#--------
# Transfering the repo from master to mirror
rsync -vazu ${repouser}@${master}:${svndir}/${repo}/ ${svndir}/${repo}/
#--------
# Change lines 7 and 8 in file ${svndir}/${repo}/db/revprops/0/0
URL="http://${master}/${repo}"
length=${#URL}
sed -i "7s|.*|V ${length}|" ${svndir}/${repo}/db/revprops/0/0
sed -i "8s|.*|$URL|" ${svndir}/${repo}/db/revprops/0/0
#--------
# replace hooks
rm ${svndir}/${repo}/hooks/*
cp -a ${hooksskeldir}/* ${svndir}/${repo}/hooks/
#--------
# Set the file permission on the new created repository.
find ${svndir}/${repo}/ -type d -exec chmod 2775 '{}' \;
find ${svndir}/${repo}/ -type f -exec chmod g+w '{}' \;
chmod 444 ${svndir}/${repo}/format
#--------
# Verify that the svnsync functions
svnsync sync --source-username ${syncuser} --source-password ${syncpass} file://${svndir}/${repo}