Backing up Subversion Repositories using 8

Posted by Ben Reubenstein Tue, 24 Apr 2007 13:12:00 GMT

Subversion is an excellent tool for versioning your code and projects. Backing up this data is crucial in case of a catastrophic failure. Subversion has several ways to create backups, this tutorial will focus on using to accomplish the task. For more information on the various methods for backing up subversion consult the documentation.

This tutorial assumes you have an existing repository and focuses on a *nix environment interacting with the shell as root.

1. Get the latest version of the script.

# wget

2. On my system (gentoo) I moved the script into /usr/sbin so that the file is in my path.

# mv ~/ /usr/sbin/

3. Open the file in your favorite text editor adjusting the paths to svnadmin and svnlook. Be sure to give the full path or the script will fail even if those executables are in your path (at least it did for me).

# vi /usr/sbin/
# Path to svnlook utility
svnlook = "/your/path/to/svnlook"

# Path to svnadmin utility
svnadmin = "/your/path/to/svnadmin"

4. In order to automate the task, we'll create a simple cron script to call the for each one of our repositories. In order to save disk space, we'll pass the script an option to compress the files. Valid archive types include gz, bz2, and zip. Be sure that the directory you are backing up to exists, or the script will fail.

# vi /etc/cron.daily/backup_subversion
# backup_subversion v.1 --archive-type=gz /my/repository1 /my/backup/location1
# if you have more than 1 repository, simply
# add a new line for each one
# --archive-type=gz /my/repository2 /my/backup/location2
# chmod +x /etc/cron.daily/backup_subversion

5. Test the script.

# /etc/cron.daily/backup_subversion
Beginning hot backup of '/my/repository1'.
Youngest revision is XX
Backing up repository to '/my/backup/location1/repository1-XX'...
Archiving backup to '/my/backup/location1/repository1-XX.tar.gz'...
Archive created, removing backup '/my/backup/location1/repository1-XX'...

That's it. Feel free to post questions or corrections in the comments.