Posts tagged ‘backup’

February 10th, 2009

Gmail as a backup storage solution

In a previous post I mentioned that I was using Gmail for backups. I have an automated script that mails an archive of my backed up files to a 2nd gmail account that I setup specially. I’ve added to the backup script so it now also backs up the databases for this blog and my bugs database, and finally also backups up the files for this website.

Gmail provides a generous ~7GB of storage space which should not fill up too quickly, however managing all the backups and removing older backups would add more work to my list of things to do. So I’ll take advantage of some of Gmails features to ease my work load.

Gmail has the ability to set up filters on incoming mail, these filters let you specify critera for emails that when matched certain actions can be taken like applying labels, marking as read, forwarding etc. So I’ve created a filter that ‘Skips the Inbox and applies the label ‘MogeBackup‘ to all mail that comes from my backups. I’ve also marked the mail as ‘Read‘ and selected the ‘Delete it‘ action as well. Now you may be asking why would I want to delete my backup after receiving it? Well, Gmail doesn’t delete mail right away, it moves it to the Trash folder, now here’s the convienient part, Gmail will only delete messages in the Trash folder if they have been in there for more than 30 days. By filtering into the Trash, I let Gmail manage my cleanup my removing backups that are 30 days old or older.

To find all my backups I can put into the search box “in:trash in:MogeBackup

Tags: ,
February 8th, 2009

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.