Repository Backups

With the repository now housing the most important parts of the project, the documentation and the source code, it is very important that this resource be backed up.

In Subverion there are two types of backup methods:

  • Full - a full backup gathers all the information in the repository required to fully reconstruct the repository should a disaster occur.
  • Incremental - an incremental backup gathers the information that has changed in the repository since the previous backup.

The Moge repository uses the FSFS filesystem implementation and to keep things simple I will use a full backup. A full backup can be performed using the svnadmin subcommand hotcopy.


This just takes a copy of the respository at REPOS_PATH and puts it at REPOS_BACKUP_PATH.

I created a little script to do the hotcopy and create a bzip2 archive with today’s date appended to the name. The script then emails the archive to a gmail account so I have a backup offsite. Archives remain in the backup folder for 30 days after which the script will remove them.

Next thing to do is to automate the backup to happen on a nightly basis, the Unix scheduler cron can be used for this very task. To tell cron to do jobs for you it requires a crontab which is a file that is read by cron and contains lines that define a job or task to be run with attributes defining when the job is to run. This file can be edited with the following command:

$ crontab -e

This will open the file in the default editor. There are 6 fields in a line to define a task, these are shown below:

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
  *  *  *  *  *  command

I want to run the backup daily at 3am, so I’d add a line as follows:
0 3 * * * /usr/local/bin/php /home/amorey/backup/mogeBackup.php

Once you save and exit the editor the crontab will be set.

Comments are closed.