Subversion Maintenance Scripts

September 27, 2006 - 3 minute read -
subversion apache shell-scripting version-control

With the recent release of Subversion 1.4 I'm going through the process of updating repositories. I often like to use multiple repositories because Subversion versions the entire repository with each checkin (Atomic commits rule!). When I do that, I group all of the repositories in the same directory. It makes it really easy to configure Apache with the SVNParentPath directive. And if you're using svn+ssh or something like that, then it's just easier to remember where they are.

SVNParentPath Example

With this configuration it's very easy to bring new repositories up because it doesn't require any configuration change in Apache.

<Location /svn>
    DAV svn
    SVNParentPath s:/svn
    SVNListParentPath on
    SVNAutoversioning on</p>
    # authentication
    AuthType Basic
    AuthName "Subversion Access"
    AuthUserFile s:/logins.txt
    # Access is configured in the access file.
    AuthzSVNAccessFile s:/access.txt
    Require valid-user
</Location>

The one obvious downside to having multiple repositories is managing things like backups and upgrades. You have a lot more to do than just dump and load a single repository. So to help handle that task, I created some simple shell scripts.

Dump All Repositories

This script will dump all of the SVN repositories in a given directory.

#!/bin/sh</p>
# Assumes each directory is an SVN repository
# and creates a dump file for each of them.</p>
for i in *; do
    svnadmin dump $i > ${i}.dump;
done;

Recreate/Load All Dump Files

This script will take all of the dump files and create new repositories and then load the dump file into them. This is good for major revision changes such as to 1.4 where they have changed some structures and improved the efficiency of storing binary files for example.

#!/bin/sh</p>
<p># Assumes a directory full of dump files
# Creates a new SVN repository and loads the dump file into it</p>
<p>for i in *.dump; do
    # The %% syntax is a substring command in bash to strip off the
    # last occurrence of the string that follows so Foo.dump -> Foo
    repos=${i%%.dump};
    svnadmin create $repos;
    svnadmin load $repos < $i;
done

Create New Repository Script

This is a handy one I keep around to make it easy to help enforce best practices. This creates a repository and then automatically creates the trunk/ branches/ and tags/ directories.

#!/bin/sh</p>
<p>if [ -z "$1" ]
then
    echo "Usage: $0 <repository>";
    exit 1;
fi</p>
<p># set up directories
cur_dir=`pwd`
# use these 2 if you're running on Cygwin under Windows
# cur_cyg_dir=`pwd`
# cur_dir=`cygpath -m $cur_cyg_dir`
svn_dir=${cur_dir}/${1}</p>
<p>svnadmin create "$1"
svn -m "Create default structure." mkdir file:///${svn_dir}/trunk file:///${svn_dir}/tags file:///${svn_dir}/branches</p>
<p>echo "done"

Not that these are incredibly complex shell scripts, but they can do a lot of work while you do other things (like post to your blog). I hope they'll help someone out there.

And just to be warned, if you're doing this on a bunch of big repositories it can take some time!