Articles » A (Linux) Server for Software Developers » Setting up and Using a Secure Trac and Subversion Server » Backup and Restore of Trac and Subversion

Backup and Restore of Trac and Subversion

Whilst the SubVersioN (SVN) repository acts as a backup in many ways, it is still worth making a backup. The repository holds more than just a backup of the developer files, it holds a record of every change that anyone has ever made to the source files.The Trac project pages can also hold important information. Given that keeping this data is critical to a software project's existence (and possibly the livelihood of the company/induviduals that own it), it is worth protecting.

Procedures to backup and restore data from projects are given below. However, it is highly recommended that the provided scripts are used instead. These scripts reduce the whole process to single commands. It is also an idea to schedule automatic daily, weekly, and/or monthly backups via crontab, or to use an online backup service (I will be examining those in more detail later).

IMPORTANT: Those performing a backup to a remote server may prefer to use the scripts presented here.

Backup and Restore Scripts

These scripts backup/restore to/from *.tgz archives. It does require some disk space in the /tmp directory in order to temporarily store intermediate files. The scripts are:

  • Backup a project: devserver-backupproject.sh. Backs up a single Trac project and its SVN repository. The project name (i.e., base-directory name) to back up must be specified; optionally, an output directory can be given too, or the backup will be saved to the current directory, e.g.:
devserver-backupproject.sh TestProject
< or >
devserver-backupproject.sh TestProject /home/user/backups
  • Backup all projects: devserver-backupall.sh. Performs a backup of all projects on a Trac server and their SVN repositories. The output directory can optionally be specified, or the backup will be saved. This will create a time-stamped directory containing *.tgz archives of each project. This makes it easy to restore individual projects as necessary. Example usage:
devserver-backupall.sh
< or >
devserver-backupall.sh /home/user/backups
  • Restore a project: devserver-restoreproject.sh. Restores a project from the specified backup archive that was produced by devserver-backupproject.sh, e.g.:
devserver-restoreproject.sh TestProject_200812311105.tgz
  • Restore all projects: devserver-restoreall.sh. This will restore all Trac projects and SVN repositories from a backup. Either run this from within the directory containing all the *.tgz files created by devserver-backupall.sh, or specify the directory containing the backups, e.g.:
devserver-restoreall.sh /home/user/backups/tracsvn_200812311105.tgz

NOTES:

  • Devserver-backupall.sh and devserver-restoreall.sh require the other two scripts to be present in the same directory; be sure to download them all. 
  • 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/devserver-backupproject.sh
wget https://hdrlab.org.nz/assets/Articles/TracSVNUse/devserver-backupall.sh
wget https://hdrlab.org.nz/assets/Articles/TracSVNUse/devserver-restoreproject.sh
wget https://hdrlab.org.nz/assets/Articles/TracSVNUse/devserver-restoreall.sh
chmod 766 devserver-*

Backup of a Trac Project and It's SVN Repository

Since the Trac and SVN servers are functionally separate, a combined backup is, in fact, two separate backup operations. This can be achieved as follows (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>
  • Create a temporary backup directory:
mkdir /tmp/tracsvn_backup
  • Backup the SVN repository:
svnadmin dump -q home/svn/proj_dirname >/tmp/tracsvn_backup/proj_dirname_$(date +"%Y%m%d%H").svn
  • Backup the Trac repository:
trac-admin /home/trac/proj_dirname hotcopy /tmp/tracsvn_backup/proj_dirname_$(date +"%Y%m%d%H")
  • Put all the files into a *.tgz file (replace output_path with the directory that the archive should be put in):
cd /tmp/tracsvn_backup
tar -czvf output_path/proj_dirname_$(date +"%Y%m%d%H").tgz *
  • Delete the temporary directory:
rm -R /tmp/tracsvn_backup

NOTE: $(date +"%Y%m%d%H") will insert a timestamp formatted as: YYYYMMDDHH, where YYYY is the year, MM is the month, DD is the day, and HH is the hour. It is advisable to insert the date in this format for two reasons: it indicates when the backup was made, and, the backups will appear in order of date when sorted "alphabetically."

Restoring a Trac Project and 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 archive_basename, with the basename (i.e, minus the .tgz) of the archive created using the procedure above, and 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:
/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
  • Create a temporary directory:
mkdir /tmp/tracsvn_backup
  • Decompress the archive (replace archive_path with the full path to the archive, e.g., /home/user/backups/tracsvn_backup_200812311205.tgz):
cd /tmp/tracsvn_backup
tar xvzf archive_path
  • Copy the Trac project files and set appropriate permissions:
mv archive_basename/* /home/trac/project_name
chown -R www-data /home/trac/project_name
  • Recreate and restore the SVN repository:
su www-data -c "svnadmin create /home/svn/project_name"
sudo svnadmin load /home/svn/$project_name < archive_basename.svn
  • Delete the temporary directory:
rm -R /tmp/tracsvn_backup
  • 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 and Restore of Trac and Subversion