Subversion: move, migrate, split

Common problems: a repository in on server A and needs to be migrated onto server B; a single repository needs to be spit into few separate ones; what to do with local working copies after server migration; the repository storage method needs to be changes e.g. from berkleyDB to file-system.

In some simple cases the repository can be moved directly on file system level. However, the following steps describes a more complex case, in a generally applicable way: a migration and split of repositories from one server to another, fixing the local working copies. Assume this situation:

ServerA, repository: projects  path: /proj1
                            path: /proj2


ServerB: repository: proj1     path: /
ServerB: repository: proj2     path: /

For example: ->

1. Export the repository on ServerA
svnadmin dump /path/to/repos/projects > projects.dump

2. Split / filter out repositories
svndumpfilter include proj1 < projects.dump > proj1.dump
svndumpfilter include proj2 < projects.dump > proj2.dump

3. Fix the paths
As the dump is in a text format you can easily edit it to change prune the projects root directory. You do it:

  1. by renaming the paths:
    sed -e "s/Node-path: projects//Node-path: /" < proj1.dump > proj1-fixed.dump
    The same for proj2.dump
  2. and removing the section that creates the root directory, i.e. delete the following lines form somewhere at the beginning of both dumps proj1-fix.dump and proj2-fix.dump:
    Node-path: projects
    Node-action: add
    Node-kind: dir
    Prop-content-length: 10
    Content-length: 10


4. Import the repositories on Server
Create a new repository for each project and import the dumps. (A detailed description of how to setup a Subversion (and friends) is in my previous post)

svnadmin create /path/to/repos/proj1
svnadmin load /path/to/repos/proj1 < proj1-fixed.dump

Do it analogically also for proj2.

Happy checkout :) After migration you'd rather check/modify/recreate the hooks, users for authentication (if you used some of those). And again, read the official SVNBook for details.

Fixing existing working copies
If you don't want to checkout but rather continue using existing working copies you can (cannot be done in case of some repository splits).

First of all, use --force-uuid option for svnadmin load (step 4). Then you can tweak the local copy by running (in the root of the local repo):
svn switch --relocate http://ServerA/testproject https://ServerB/project .

Installation of Subversion on Ubuntu, with Apache, SSL, and BasicAuth.

I did it again! Yet another installation of Subversion for “standard” project development purposes, i.e. using Apache2, WebDAV, SSL, Basic Authentication. In case I do it again … and soon again, I recorded the installation howto logs.

NOTE: The target OS is Ubuntu Edgy 6.10, and Feisty. I use $NAME notation to refer to places to be substituted by the installation specific values

1. Install packages:
sudo apt-get install subversion libapache2-svn libapache-mod-dav apache2

2. Enable SSL:
sudo a2enmod ssl
sudo sh -c "echo 'Listen 443' >> /etc/apache2/ports.conf"

3. Generate Certificate:
Ubuntu < Feisty:
sudo apache2-ssl-certificate
Use the server name to be used for access the web server.

Ubuntu >= Feisty: (thanx Roderik)
sudo apt-get install ssl-cert
sudo mkdir /etc/apache2/ssl
sudo /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem

4. Create Virtual Host:
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/$SITENAME
sudo vim /etc/apache2/sites-available/$SITENAME

NameVirtualHost *:443
<VirtualHost *:443>

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem
SSLProtocol all

5. Enable the site:
sudo a2ensite $SITENAME
sudo /etc/init.d/apache2 restart

A warning that complaints about failure of server name determination can be fixed by adding ServerName $SERVERNAME to the main Apache config /etc/apache2/apache2.conf

6. Adding repository(ies):
The following setup assumes we want to host multiple repositories.
sudo mkdir /var/svn
sudo svnadmin create /var/svn/$REPOS
sudo chown -R www-data:www-data /var/svn/$REPOS
sudo chmod -R g+ws /var/svn/$REPOS

7. Adding Basic Authentication:
sudo htpasswd2 -c -m /etc/apache2/dav_svn.passwd $AUTH_USER

8. Enable and configure WebDAV and SVN:
Add to /etc/apache2/mods-available/dav_svn.conf
DAV svn
SVNParentPath /var/svn
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user

and for non-anonymous access comment out:

(optionally the same configuration can be set for particular virtual host only, i.e. /etc/apache2/sites-available/$SITENAME)

9. Finalization: (guess what?)
sudo /etc/init.d/apache2 restart

Web access:
lynx https://localhost/svn/$REPOS exposes the repository.
lynx http://localhost/svn/$REPOS says: eat my shorts , i.e. 403-forbidden.

An initial import:
svn import --username $AUTH_USER $A_FILE https://localhost/svn/$REPOS/testdir -m "Testing"

… and check-out:
svn co --username $AUTH_USER https://localhost/svn/$REPOS

To add a new repository just repeat the step 6 (without making the root directory of course).
If you wish to configure a single repository only, instead of point 6:
sudo svnadmin create /var/svn
sudo chown -R www-data:www-data /var/svn
sudo chmod -R g+ws /var/svn

and in /etc/apache2/mods-available/dav_svn.conf (step 8) use this instead of SVNParentPath:
SVNPath /var/svn

Above all, check the great SVN Book.