Svnsync is a one way replication system for Subversion. It allows you to create a read-only replica of a repository over any RA layer (including http, https, svn, svn+ssh).
First, lets setup the initial sync. We have two repositories, the source and the destination (which should be empty). Because the svnsync is allowed to rewrite anything on the destination repos, we need to make sure the commit hooks are configured to allow our svnsync user to do anything it wants. Modified the pre-revprop-change and start-commit in the repository hooks directory (/dir/path/REPOS_NAME/hooks) of the destination server.
pre-revprop-change
#!/bin/sh
......
USER="$3"
if [ "$USER" = "svn" ]; then exit 0; fi
echo "Only the svn user may change revision properties" >&2
exit 1
start-commit
#!/bin/sh
......
USER="$2"
if [ "$USER" = "svn" ]; then exit 0; fi
echo "Only the svn user may change revision properties" >&2
exit 1
Now we are ready to setup the sync using svnsync init DESTINATION_REPOS SOURCE_REPOS
bash$ svnsync init svn+ssh://svn@remote.server.com/dir/path/REPOS_NAME file:///dir/path/REPOS_NAME
To list the properties that it created, run:
bash$ svn proplist --revprop -r 0 svn+ssh://svn@remote.server.com/dir/path/REPOS_NAME
So all the knowledge about what we are syncing from is stored at the destination repository. No state about this sync is stored in the source repository. We are now ready to begin copying data:
bash$ svnsync --non-interactive sync svn+ssh://svn@remote.server.com/dir/path/REPOS_NAME
And if everything is setup correctly, you will start replicating data. Except that everything may not go as plan and if you hit control+c by accident, the sync would break.
bash$ svnsync --non-interactive sync svn+ssh://svn@remote.server.com/dir/path/REPOS_NAME
Failed to get lock on destination repos, currently held by 'svn.example.com:0e4e0d98-631d-0410-9a00-9320a90920b3'
Failed to get lock on destination repos, currently held by 'svn.example.com:0e4e0d98-631d-0410-9a00-9320a90920b3'
...
svnsync: Couldn't get lock on destination repos after 10 attempts
I started debugging, and found that svnsync kept its lock state in a special property in revision zero again. So, To fix this, we can safely just delete this lock:
bash$ svn propdel svn:sync-lock --revprop -r 0 svn+ssh://svn@remote.server.com/dir/path/REPOS_NAME
After the sync finishes, we will want to keep the replica up to date by modifying the post-revprop-change and post-commit to the source repository server hooks directory.
post-revprop-change
#!/bin/sh
.......
REPOS="$1"
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"
# If you are using the svn+ssh, use this line below
svnsync copy-revprops svn+ssh://svn@remote.server.com/$REPOS $REV
# If you are using svnserve, use this line below
svnsync copy-revprops svn://remote.server.com/$REPOS $REV --sync-username svnusername --sync-password svnpassword
post-commit
#!/bin/sh
.......
REPOS="$1"
REV="$2"
# If you are using the svn+ssh, use this line below
svnsync sync svn+ssh://svn@remote.server.com/${REPOS}
# If you are using svnserve, use this line below
svnsync sync svn://remote.server.com/${REPOS} --sync-username svnusername --sync-password svnpassword