In order to ensure your SVN repository is fully backed up you should schedule regular backups and store them on a remote machine. This document shows how to use svnadmin to backup your repository, rsync to copy it to a remote server, and cron to automate the process (so you don't have to remember to run the backup yourself).
First, use the svnadmin dump function to dump a copy of your repository to the local machine using a command like this:
svnadmin dump /path/to/repository/location >/path/to/backup/file
e.g.,
svnadmin dump ~/webapps/svn/ >~/svn.backup.bak
This would create a new file in your home directory called svn.backup.bak containing all the information needed to recreate the SVN repository stored in ~/webapps/svn/
In order to automate this process you should use a scheduler like cron, which this tutorial does.
First you will need to ensure that your machine is running cron, rsync, and ssh. You will also need to know the following:
~/webapps/svn/)automated_backups to store this file, i.e., ~/automated_backups)www.example.com)/backups). This directory must be writable by the rsync process
You will need to create a new script containing the commands needed to make your backup. Create a new file in the backup directory called svn.backup.sh. Make sure it is executable:
cd ~/automated_backups touch svn.backup.sh chmod +x svn.backup.sh
Now edit the new script and enter the following:
LOGFILE=’rsync.backups.log’ SVN_BACKUP_FILENAME=~/automated_backups/svn.backup.`date +%Y.%m.%d`.bak echo $’\n\n’ >> $LOGFILE svnadmin dump ~/webapps/svn/ > $SVN_BACKUP_FILENAME /usr/bin/rsync --delete --rsync-path='nice -n 19 rsync' -avz -e ssh $SVN_BACKUP_FILENAME example.com:/backups 2>&1 >> $LOGFILE
Now you should be able to execute this script which will dump a copy of your SVN repository and rsync it to your remote server. Unfortunately it will ask for a username/password every time this is run which is not acceptable for an automated script. To overcome this you will need to set up a new ssh key to allow you to log into the server without a password.
Edit your crontab now with the following command:
crontab -e
And add the following line:
49 1 * * * cd ~/automated_backups;./svn.backup.sh
This will execute the backup script automatically at 1:49am every day.