Moving Your SVN Repositories to a New Server

Created by josh
August 27, 2017 12:26:44 PM PDT


If you're looking to migrate your SVN repositories to another server, here is an easy step-by-step guide (as root user).

 

1) Back up your working copies on each of the clients before you begin

$ mkdir ~/svn-backup/ && cp -rf ~/working-copy-dir/ ~/svn-backup/

2) On the current SVN server (Server A), backup each SVN repo. Replace "/usr/local/svn/repositories" with the location of your svn repos

for repo_dir in /usr/local/svn/repositories/*; do
    repo=${repo_dir##*/}
    cd /tmp/svn_dump/ && svnadmin dump ${repo_dir} > ${repo}.dump
done;

cd /tmp && tar -cf - svn_dump | bzip2 > svn_dumps.tar.bz2

 

3) If Server A has network and SCP access to the new SVN server (Server B), you can simply run this:

$ scp /tmp/svn_dumps.tar.bz2 server_b.io:/tmp/svn_dumps.tar.bz2

 

Otherwise, up to you to figure out a different way to transfer the dumps from Server A to Server B (shared network mount, USB stick, several thousand floppy disks, etc).

 

4) On Server B, make sure SVN is installed. I prefer to compile subversion from source, but Debian users may run this:

$ apt-update && apt-get install subversion

$ mkdir -p /usr/local/svn/repositories && cd /usr/local/svn/repositories

 

5) I recommend you control the access to your repos by creating a specific user and group, if you don't yet have one.

$ addgroup svnusers
$ adduser svn --no-create-home --system

 

For each client that will use the "svn+ssh" protocol and has a key pair for that user, run this command, replacing {user1} with the correct user name. If your clients are using the http/https protocol, then the web server user will need to be added here:

$ usermod -a -G svnusers {user1}

 

6) Double-check which version of SVN server you have on Server B. This is important for the next step

$ svn --version

 

7) On Server B, for each of your repos, create a repository (named identically as your dumped repository) from the previous server. If your repositories were orinally created in svn 1.4 or below, replace {version} with 1.4. If any later, replace {version} with the respective version. You'll end up seeing a nasty error like "Expected FS format between 'x' and 'y'; found format 'z'" when you try to update or checkout at the end of all this migration.

$ cd /usr/local/svn/repositories && svnadmin create --compatible-version {version} {repo-name}

 

8) Untar that compressed dump that you sent over to Server B

$ cd /tmp && tar xjf svn_exports.tar.bz2 && cd svn_exports

 

9) For each of your repositories, run this (replacing {your-repo} with the actual repository name) 

$ svnadmin load /usr/local/svn/repositories/{your-repo} < {your-repo}.dump

 

10) Change permissions of your repositories to the user/group combo you created earlier. 

$ cd /usr/local/svn/repositories && chown svn:svnusers -R . && chmod 770 -R .

 

11) Test locally as any user who belongs to the svnusers group and running (replace {your-repo} of course):

$ mkdir /tmp/test_co && cd /tmp/test_co

$ svn co file:///usr/local/svn/repositories/{your-repo}

 

You can even take the testing a litter further by touching a new file, adding/committing it and see if it all goes well. If everything above works, just be sure to properly point your clients over to the new server, including new key pairs if necessary