Debian – Best way to do Subversion backups

backupdebiansvn

What is the best way to do Subversion backups (on a Debian based server).

Is it to use svnadmin?

svnadmin dump /path/to/reponame > reponame.dump

Or maybe just to tar the dir where the repositories are?

tar -cvzf svn.backup.tar.gz /var/subversion/

What are the pros and cons of the above?

Thanks
Johan


Update:
This is a small server with only a handful of repos.
So incremental backups are probably not needed,
I think it is better to focus on keeping it simple.

Update:
I used packs wrapper script (that in turn was a wrapper for svn-hot-backup) to do a full backup and then did a full recovery on another clean computer.
However I removed that "SVN_HOTBACKUP_NUM_BACKUPS=10" part since it was not working for me.

Please note that I feel it was kind of simple and the result was very close to just tar the dir.
But as Manni pointed out here to use svn-hot-backup/"svnadmin hotcopy" is a more reliable method,
since tar could create corrupt backups from time to time if you are unlucky.

Best Answer

Look for the svn-hot-backup script. It should ship with subversion, and contains all the logic to do what you want, plus automagic rolling out of old backups. I have written the following wrapper script that uses svn-hot-backup to run as a nightly cronjob to backup a single server with multiple repositories, slightly modified to be generalized.

#!/bin/bash

#
# Dumps the svn repos to a file and backs it up
# to a local directory.

#Keeps the last 10 revisions
REPODIR="/var/repos"
BAKDIR="/data/backup/svn"
PROG="/usr/local/sbin/svn-hot-backup"
REPOLIST='repo1 repo2 repo3'

if [ ! -x "${PROG}" ]
then
        echo "svnbak: Could not execute \`${PROG}\`"
        exit 1
fi

for repo in ${REPOLIST}
do
    # Dump the database to a backup file
    echo "svnbak: Dumping subversion repository:  ${repo}"
    SVN_HOTBACKUP_NUM_BACKUPS=10 nice ${PROG} --archive-type=gz ${REPODIR}/${repo} ${BAKDIR}/${repo} &> /tmp/svnbak.$$

    if [ "$?" -eq "1" ]
    then
        echo "svnbak: Hot backup on '${repo}' failed with message:"
        /bin/cat /tmp/svnbak.$$
    fi

    /bin/rm /tmp/svnbak.$$
done

exit 0