Home | Subversion DIY write-through-proxy

Subversion DIY write-through-proxy

Posted on Thursday, February 21st, 2008 | Filed under subversion

A lot of people seem to be eagerly awaiting the SVN 1.5 release so they can start implementing write-through-proxy. Not a lot of people seem to know that this is nothing more than a thin wrapper around existing Apache configuration capabilities. Here’s how you do it the old-fashioned way:

On your local mirror server(s):

<VirtualHost *:80>
  ServerName mirror

  <Location /repo>
    DAV svn
    SVNPath /path/to/mirrored/repo

    RewriteEngine on

    RewriteCond %{REQUEST_METHOD} !^GET$
    RewriteCond %{REQUEST_METHOD} !^PROPFIND$
    RewriteCond %{REQUEST_METHOD} !^OPTIONS$
    RewriteCond %{REQUEST_METHOD} !^REPORT$

    RewriteRule ^(.*)$ http://master%{REQUEST_URI} [P]
    ProxyPassReverse http://master/repo
  </Location>

  <Location /repo-internal>
    DAV svn
    SVNPath /path/to/mirrored/repo
  </Location>
</VirtualHost>

On your (remote) master server:

<VirtualHost *:80>
  ServerName master

  <Location /repo>
    DAV svn
    SVNPath /path/to/master/repo
  </Location>
</VirtualHost>

Next, you need to initialize svnsync between the master and all its mirror repositories:

  1. Create the pre-revprop-change hook on each mirror repository. For now, just have it always exit 0.
  2. For each mirror, run:

    svnsync init http://mirror/repo-internal http://master/repo

To make the synchronization from master to mirror(s) work, you need to setup a number of hook scripts on both sides:

  1. Create the post-commit hook on the master repository, and for each mirror add a line like this:

    /usr/bin/svnsync sync --non-interactive http://mirror/repo-internal

  2. Create the post-revprop-change hook on the master repository, and for each mirror add a line like this:

    /usr/bin/svnsync copy-revprops http://mirror/repo-internal $REV

Next, if you’re planning on using this configuration in a production environment, you’ll want to add some security:

  1. Create an internal user (i.e. ’subversion’) to use for this configuration. You’ll need this account on both master and mirror(s).
  2. Edit the pre-revprop-change hook on each mirror repository to restrict revision property changes. Make sure your internal user is allowed here. E.g.:


    if [ "$USER" = "[internal user]" ]; then exit 0; fi
    exit 1

  3. Add --username [internal user] --password [password of internal user] to the svnsync commands in the post-commit hook on the master repository.

Comments

3 Responses to “Subversion DIY write-through-proxy”

  1. RvO on January 2nd, 2010 2:07 PM

    With SVN >1.5 just use the provided Apache directives for write-through proxy instead:

    http://subversion.tigris.org/svn_1.5_releasenotes.html#webdav-proxy

  2. Nick on July 21st, 2009 11:27 AM

    SVN move and rename not working for files and folders in slave repository

    Apache : 2.2.11
    Subversion server : 6.2

    While rename a file it gives the following error
    svn: Commit failed (details follow):
    svn: Server sent unexpected return value (405 Method Not Allowed) in response to COPY request for ‘/slave/qa1/helloiamthe_masteronqa1/!svn/bc/17/branches’

    Similarly while moving the folder gives the following error
    svn: Server sent unexpected return value (405 Method Not Allowed)

    Please let me know if anyone has any clues on this.

    Thanks
    Nick

  3. Replication / Mirroring as Master-master with Subversion using svnsync | GS Design on June 26th, 2009 4:30 PM

    [...] about implementing it in this articles: Subversion transparent proxy with svnsync + webdav proxy subversion diy write through proxy Subversion on-the-fly [...]

Leave a Reply