How to limit the size of a subversion repository

Subversion allows you to run a script before a commit is made (pre-commit). If this script exits with a non-zero exit status then the commit is not allowed.

If our repository was located here:

/var/lib/svn/repos

Then we need to create a pre-commit hook file here:

/var/lib/svn/repos/hooks/pre-commit

This file needs to be executable and readable by the subversion (or apache user if using webDAV).

Any message that the script prints to STDERR will sent to the client committing.

The first argument passed to the script is the location of the repository.

The second is the revision number.

Here is an example script that will limit a repository size to 100 Megs:

#!/bin/bash
#commit hook to limit the size of a repos
REPOS="$1"
TXN="$2"

#max size for repos
QUOTA="100"

MEGS=`du -sm $REPOS | sed -r "s/^([0-9\\.]+).+/\\1/"`

if [ "$MEGS" -gt "$QUOTA" ]; then
        #send error message to stderr
        echo "Repository is over ${QUOTA}M in size" 1>&2
        exit 1;
fi
exit 0;

Last updated: 25/09/2006