#!/bin/bash
#
# BackupSVN.sh
# 
# Performs a hotcopy of all repositories on an SVN server.
# Set BASE and HOTCOPY to your repository locations. If you
# change BASE then you will also have to change "/home/svn/"
# in the line starting with DIR to your BASE directory.
#
# Copyright 2009 by Hans de Ruiter, all rights reserved.

BASE="/home/svn/"
HOTCOPY="/home/backup/svn/"

FIND=/usr/bin/find
GREP=/bin/grep
RM=/bin/rm
SED=/bin/sed
SVNADMIN=/usr/bin/svnadmin

DIRS=`find ${BASE} -name uuid | $GREP 'db/uuid$' | $SED 's:/db/uuid$::' | $SED 's:^/home/svn/::'`

for DIR in ${DIRS}
do  
    echo "svnadmin hotcopy ${BASE}${DIR} to ${HOTCOPY}${DIR}"

    if ! test -d ${HOTCOPY}${DIR}
    then
        mkdir -p ${HOTCOPY}${DIR}
    fi

    $RM -r ${HOTCOPY}${DIR}
    $SVNADMIN hotcopy ${BASE}${DIR} ${HOTCOPY}${DIR}
done
