I was recently in a situation when I needed to move my Subversion repository from one server to another. One option was to use “svnadmin dump”, but that requires you to have access to the file system on the server where the repository sits as well as knowing what directory the repository is in. It turns out that a much sleeker way to do this is using the svnsync tool because all you need to know for that solution are the URLs of the source and target repositories. Here’s how:
Let’s say we have a SVN repository http://source.com/svn and we want to copy it to http://target.com/svn. The following instructions are specific to Ubuntu. For other distros, the process will be similar, though.
1. CREATE THE TARGET REPOSITORY
First, we’ll create the target repository if it doesn’t exist yet – we’ll call it repo1:
mkdir -p /var/lib/svn/repo1 svnadmin create /var/lib/svn/repo1
Of course, you will need to configure this repository in /etc/apache2/mods-available/dav_svn.conf having DAV installed. Doing that is not the subject of this article, though.
2. ADD PRE-REVPROP-CHANGE HOOK TO THE TARGET REPOSITORY
It is necessary to add the pre-revprop-change hook to the target repository because otherwise the repository copying will fail. In our example, we add the hook like this:
echo '#!/bin/sh' > /var/lib/svn/repo1/hooks/pre-revprop-change
Now, let’s make sure the target repository is read/writable by the user running the Apache2 server:
sudo chown -R www-data:www-data /var/lib/svn/repo1
and that the hook is executable:
sudo chmod +x /var/lib/svn/repo1/hooks/pre-revprop-change
3. INITIALIZE THE REPOSITORY TRANSFER
Now we are ready to start the repository transfer. In your target repository machine (can be the same machine as the source repository machine, actually, as you can copy repositories locally, too), type the following to initialize the target repository for the transfer (notice that the target repository URL comes first, the source repository second in the command):
svnsync init http://target.com/svn http://source.com/svn
And then start the transfer as follows:
svnsync sync http://target.com/svn
Now all the revisions from the source repository will be copied to the target repository, so it might take a while. The beauty of this is that you can even interrupt the copying by CTRL+C and resume it where it left off later by issuing the last command again.
I hope you will find this useful!