Best way to do Subversion backups?
Solution 1:
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
Solution 2:
Have you seen the documentation on this?
Basically, you have two options:
- Perform incremental backups using
svnadmin dump
- Backup your entire repository using
svnadmin hotcopy
Simply making a copy of the directory is not an option because your repository might change while the copy is being made.
Whether you are into incremental or full backups depends on your amount of paranoia, the size of your repository, your needs and your infrastructure.