Articles » A (Linux) Server for Software Developers » Setting up and Using a Secure Trac and Subversion Server » Backup Multiple Trac and Subversion Projects to an Off-Site Backup Service

Backup Multiple Trac and Subversion Projects to an Off-Site Backup Service

The previous article on backing up and restoring Trac and SubVersioN (SVN) saves the result to an archive. If one is using an off-site backup, using this method would mean that a new backup copy would be transferred to the remote server every time. As the repositories grow, this will mean more and more data is transferred, most of which would likely be unchanged. This article presents an alternative method of backing up a multi-project Trac and SVN server.

Using Hotcopy to Clone Trac and Subversion Files

Ideally the remote backup software would simply scan the Trac and SVN files and upload only changed files to the server. Unfortunately some of those files could be in use by the server, making the backup fail. One could shut down the server during the backup and restart it afterward, but such down time is likely to be unacceptable. Instead, a feature called "hotcopy" can be used to clone the files whilst the server is active, and then backup the copy.

Cloning a Trac project is achieved as follows:

trac-admin /path/to/project hotcopy /path/to/copy

where "/path/to/project" is the directory containing the project files and "/path/to/copy" is the copy.

Likewise, an SVN repository can be copied whilst the server is running using svnadmin:

svnadmin hotcopy /path/to/repo /path/to/copy

where "/path/to/repo" is the directory containing the repository.

Backing Up Trac and SVN to an Off-Site Backup Service

The basic procedure to backup all projects is:

  • Clone all the Trac projects and SVN repositories to a working directory, and
  • Run the remote backup software with the working directory as source.

This will ensure that the remote backup maintains a copy of the Trac and SVN files with minimal data transfer to the remote server. Most remote backup tools have an option to run a script before performing the backup, allowing this process to be fully automated. The following scripts can be used to perform the task of cloning the Trac and SVN files:

  • BackupSVNTrac.sh: The master script. This script simply calls the other two in turn so that a complete backup is performed. Set the backup server to execute this script before performing the backup, and the whole procedure will be automated.
  • BackupSVN.sh: Clones all of the SVN repositories found in a single directory. Unmodified, this script assumes that the repositories are held at /home/svn, and places backups in /home/backup/svn. Modify the BASE and HOTCOPY variables in the script to suit (if your server is set up as per the instructions on this page then no modifications should be necessary). This script is pretty much identical to the script presented here.
  • BackupTrac.sh: Clones all Trac projects within a single directory. Unmodified, this script assumes that the repositories are held at /home/trac, and places backups in /home/backup/trac. Modify the BASE and HOTCOPY variables in the script to suit (if your server is set up as per the instructions on this page then no modifications should be necessary).

To install these scripts, simply download all three to a directory on the server, and then set the remote backup software to execute BackupSVNTrac.sh before every backup. Alternatively the backup command could be inserted into BackupSVNTrac.sh, and then run on a schedule using Cron.

NOTES:

  • All of the scripts above should be in the same directory. 
  • The scripts must all be marked as executable. This can be achieved via the chmod command. Thus, downloading and installing these scripts would be achieved as follows:
su
<it will prompt for your root (administrator) password>
wget https://hdrlab.org.nz/assets/Articles/TracSVNUse/BackupSVN.sh
wget https://hdrlab.org.nz/assets/Articles/TracSVNUse/BackupTrac.sh
wget https://hdrlab.org.nz/assets/Articles/TracSVNUse/BackupSVNTrac.sh
chmod 766 *.sh

Restoring a Trac Project and its SVN Repository

Restoring is almost the reverse of the backup process. Additionally, it is necessary to temporarily shut down the server and to delete any old files. In the instructions below, replace proj_dirname with the directory name of the project:

  • Make sure that you have administrator privileges:
su
<it will prompt for your root (administrator) password>
  • Shut down the server (this assumes that you are serving both Trac and SVN using Apache 2):
/etc/init.d/apache2 stop
  • Delete any old files on the Trac and SVN server that belong to the project:
rm -R /home/svn/project_dirname
rm -R /home/trac/project_dirname
  • Copy the Trac project files and set appropriate permissions:
mv archive_basename/* /home/trac/project_name
chown -R www-data /home/trac/project_name
  • Copy the SVN repository:
sudo svnadmin hotcopy /home/backup/svn/project_name /home/svn/project_name
chown -R www-data /home/svn/project_name
  • Restart the server:
/etc/init.d/apache2 start

 





Articles » A (Linux) Server for Software Developers » Setting up and Using a Secure Trac and Subversion Server » Backup Multiple Trac and Subversion Projects to an Off-Site Backup Service