Replicate a foreign Subversion repository

If you want to replicate/mirror an existing repository which you do not own (i. e. svnadmin dump cannot be used), you can use the svnsync command.

At first: Create a new and empty destination repository on your server:

svnadmin create mirror

Next, create a so called “pre-revprop-change hook script”. This is needed for the subsequent steps.

nano /srv/subversion/mirror/hooks/pre-revprop-change
!/bin/sh
USER="$3"
if [ "$USER" = "yolo" ]; then exit 0; fi
echo "Only the syncuser user may change revision properties" >&2
exit 1

This limits the synchronizing mechanism to the specified user and is executed by Subversion automatically.

Now, initialize and perform the synchronization of the repositories:

svnsync init svn://YOUR_HOST/mirror/ SOURCE_REPOSITORY
svnsync sync svn://YOUR_HOST/mirror/

If the process comes to a halt, you can abort it using Ctrl+C and restart it without breaking anything. The process will continue were it was aborted (as everything is versioned this is not a problem).

For details: Chapter “Replication with svnsync” in the Subversion book.

Installing a Subversion server on CentOS 8

We are going to use the server “svnserve” which is contained in the subversion package of CentOS. This package contains also the svnadmin tool for creating a subversion repositories.

Installation

dnf install subversion

Service configuration

The default location for Subversion (SVN) repositories is /var/svn. We are going to change it to /srv/subversion like this (as root):

mkdir /srv/subversion
nano /etc/sysconfig/svnserve
OPTIONS="-r /srv/subversion"

By default, svnserve is executed as root – holy cow! For security reasons, we’re going to change it to a different user. We edit the systemd unit file and add the following lines under the section “[Service]”:

nano /usr/lib/systemd/system/svnserve.service
[Service]
User=yolo
Group=yolo

You can create the user e. g. with useradd -m yolo.

Make sure that our “yolo” user can access /srv/subversion properly:

chown -R yolo:yolo /srv/subversion

Furthermore, another change is necessary due to the new user which executes the service: The directory /run/svnserve/ contains a file where the service stores its process ID. But the directory is only accessible by the root owner. Changing the file permissions with chown is NOT a good solution because this folder will be recreated after reboot and thus the old permissions will be restored. We have to change the entry in the appropriate configuration file which is responsible for the recreation of this folder (see man tmpfiles.d for details):

nano /usr/lib/tmpfiles.d/svnserve.conf
D /run/svnserve 0700 yolo yolo -

Now, we can start the service (and enable it if you want to start it automatically):

systemctl start svnserve
systemctl status svnserve
systemctl enable svnserve

Create a test repository

Use our “yolo” user which also runs the svnserve process for the following commands:

cd /srv/subversion
svnadmin create repo1

Configure user authentication:

cd repo1
nano conf/svnserve.conf
anon-access = none # disallow anonymous access completely
password-db = passwd # file with credetials

Add some credetials:

nano conf/passwd
user = pw

Check it out

The repository set-up is complete. Now, we should be able to check it out with a Subversion client on a remote computer:

svn co svn://HOST/repo1 --username USER