svnsync is the Subversion remote repository mirroring tool. Put simply, it allows you to replay the revisions of one repository into another one.

In any mirroring scenario, there are two repositories: the source repository, and the mirror (or “sink”) repository. The source repository is the repository from which svnsync pulls revisions. The mirror repository is the destination for the revisions pulled from the source repository. Each of the repositories may be local or remote—they are only ever addressed by their URLs.

Lab Schema

Source repo URL: svn+ssh://subversion@svnmaster/svn/original

Destination repo URL: svn+ssh://subversion@svnslave/svn/mirror

svn+ssh config

1. Create keys for subversion@svnserver. Public key will be imported into authorized_keys on svnslave

[subversion@svnmaster ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/subversion/.ssh/id_rsa):
Created directory ‘/home/subversion/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/subversion/.ssh/id_rsa.
Your public key has been saved in /home/subversion/.ssh/
The key fingerprint is:
The key’s randomart image is:
+–[ RSA 2048]—-+
[subversion@svnmaster ~]$ cat ./.ssh/
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+pXxnEaAgeyBjva/IAELtA3SnkCDqnIHCmvlUeK4KfBBAQuFQCkHrgUih6UL5agylIubkfAwGtR66zHaAZMn6VoPW0JAK88eGkE4t0+ECHOP/UDOwtYlQOX5sXeykCLiKcSwcGdKJ4+RUNbsXOPNtjM8cVIwdPqvshHmegOzJJIdAYHzgUGPY9k1LTeX/dA7gOLZnvHxtShk7AUu/SLDO5ka/ojaOISFMPyz7/KWXIjj9bUuzhv9Vr4NNZRFBCifwU0y5bYpj7S6wSg1FBzCEeGu1IK6kdsxT7JA2SJQqLcx0q4fIzceCTPbpNZWU9xDN3a4o8Cm9AGPwbByXtGxj

2. Import public key into ./.authorized_keys file. Add following commands before key:

command=”/bin/svnserve -t –tunnel-user=svnsync”,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty

[subversion@svnslave ~]$ mkdir ./.ssh
[subversion@svnslave ~]$ chmod 700 ./.ssh/
[subversion@svnslave ~]$ touch ./.ssh/authorized_keys
[subversion@svnslave ~]$ chmod 400 ./.ssh/authorized_keys
[subversion@svnslave ~]$ vim ./.ssh/authorized_keys

[subversion@svnslave ~]$ cat ./.ssh/authorized_keys
command=”/bin/svnserve -t –tunnel-user=svnsync”,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+pXxnEaAgeyBjva/IAELtA3SnkCDqnIHCmvlUeK4KfBBAQuFQCkHrgUih6UL5agylIubkfAwGtR66zHaAZMn6VoPW0JAK88eGkE4t0+ECHOP/UDOwtYlQOX5sXeykCLiKcSwcGdKJ4+RUNbsXOPNtjM8cVIwdPqvshHmegOzJJIdAYHzgUGPY9k1LTeX/dA7gOLZnvHxtShk7AUu/SLDO5ka/ojaOISFMPyz7/KWXIjj9bUuzhv9Vr4NNZRFBCifwU0y5bYpj7S6wSg1FBzCEeGu1IK6kdsxT7JA2SJQqLcx0q4fIzceCTPbpNZWU9xDN3a4o8Cm9AGPwbByXtGxj

3. Create empty repo and set access for user svnsync

[subversion@svnslave ~]$ svnadmin create /svn/mirror
[subversion@svnslave ~]$ vim /svn/mirror/conf/authz
[subversion@svnslave ~]$ cat /svn/mirror/conf/authz
svnsync = rw

4. Test connection between svnmaster and svnslave

[subversion@svnmaster ~]$ ssh subversion@svnslave
The authenticity of host ‘svnslave (’ can’t be established.
ECDSA key fingerprint is 88:1b:d3:33:a5:40:51:7e:81:47:a3:ed:a8:ce:51:24.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘svnslave,’ (ECDSA) to the list of known hosts.
PTY allocation request failed on channel 0
( success ( 2 2 ( ) ( edit-pipeline svndiff1 absent-entries commit-revprops depth log-revprops atomic-revprops partial-replay ) ) )
^CKilled by signal 2.
[subversion@svnmaster ~]$


5. Create pre-revprop-change hook on svnslave side:

[subversion@svnslave ~]$ cd /svn/mirror/hooks/
[subversion@svnslave hooks]$ touch pre-revprop-change
[subversion@svnslave hooks]$ chmod +x pre-revprop-change
[subversion@svnslave hooks]$ vim pre-revprop-change
[subversion@svnslave hooks]$ cat pre-revprop-change

if [ “$USER” = “svnsync” ]; then exit 0; fi
echo “Only the svnsync user can change revprops” >&2
exit 1
[subversion@svnslave hooks]$

6. Initialize svn synchronization and provide first manual sync

[subversion@svnmaster svn]$ svnsync init svn+ssh://subversion@svnslave/svn/mirror file:///svn/original/
Copied properties for revision 0.
[subversion@svnmaster svn]$ svnsync sync svn+ssh://subversion@svnslave/svn/mirror
Transmitting file data …
Committed revision 1.
Copied properties for revision 1.
Transmitting file data .
Committed revision 2.
Copied properties for revision 2.

7. Configure automatic sync

[subversion@svnmaster svn]$ cd /svn/original/hooks/
[subversion@svnmaster hooks]$ touch post-commit
[subversion@svnmaster hooks]$ chmod +x post-commit
[subversion@svnmaster hooks]$ vim post-commit
[subversion@svnmaster hooks]$ cat post-commit
svnsync sync   svn+ssh://subversion@svnslave/svn/mirror
[subversion@svnmaster hooks]$ touch post-revprop-change
[subversion@svnmaster hooks]$ chmod +x post-revprop-change
[subversion@svnmaster hooks]$ vim post-revprop-change
[subversion@svnmaster hooks]$ cat post-revprop-change
svnsync copy-revprops  svn+ssh://subversion@svnslave/svn/mirror $REV && exit 0

Test Area