[Turkce]
In this article, I want to explain creating and maintaining a read-only subversion mirror, which may be used for backup purposes in addition to mirroring.
Let's think a scenario that there are two server machines which run Debian GNU/Linux for O.S. One of them act as the main svn repository, and the other acts as the mirror of it. Thus we talk about two repository:
- Main or source repository. In our example we assign "main-site.x.y.z" to it as domain name.
- Mirror or target repository. In our example we assign "mirror-site.x.y.z" to it as domain name.
[/] svn = rAnd, "conf/svnserve.conf" must give at least read access to authorized logins like below:
auth-access = readAt the mirror site, first, install subversion server:
apt-get install subversionConfigure it to run via inetd superserver, by adding following entry to /etc/inetd.conf:
svn stream tcp nowait svn /usr/bin/svnserve svnserve -i -r /home/svnRestart inetd superserver:
/etc/init.d/inetutils-inetd restartor
/etc/init.d/openbsd-inetd restartCreate a mirror repository:
su - svn svnadmin create mirror-repo cd mirror-repoCreate a hook script to handle syncronization operations:
touch hooks/pre-revprop-change chmod u+x hooks/pre-revprop-changePut following content into the hook script. In this content, "svn" denotes the mirror user which we configured with read-only access at main repository site:
#!/bin/sh if [ "$3" = "svn" ]; then exit 0; fi echo "Only the - svn - user may edit revision properties through svnsync" >&2 exit 1Between main and mirror sites, especially if they both are not in a local secure network, we should prefer using secure connection. For this aim, at the mirror site, we create public and private keys:
su - svn cd ~/.ssh ssh-keygen -t dsa -b 1024 -f mirror-site.keyIn the .ssh directory, this will create the public key named "mirror-site.key.pub". Add this public key into the .ssh/authorized_keys file of the svn user at the main site.
At the mirror site, login as svn user:
su - svnSet the SVN_SSH environment variable like this:
export SVN_SSH="ssh -i /home/svn/.ssh/mirror-site.key"Initialize the mirror repository:
svnsync init file:///home/svn/mirror-repo svn+ssh://svn@main-site.x.y.z/home/svn/main-repoStart first synchronization:
svnsync sync file:///home/svn/mirror-repoEdit crontab to schedule synchronization operations:
crontab -eAdd following entry into crontab (in this example, for every hour):
0 * * * * (export SVN_SSH="ssh -i /home/svn/.ssh/mirror-site.key"; svnsync sync file:///home/svn/mirror-repo)This automation keeps mirror repository synchronized with main repository at most with one hour latency. Sometimes errors occurs because of unfinished synchronization operations. Then following command may help cleaning locks at mirror site:
svn propdel svn:sync-lock --revprop -r 0 file:///home/svn/mirror-repoThat is it.