How to backup Redmine on Google Storage Oct 27, 2010

If you would like to backup your Redmine database and files, you might to consider Google Storage as your backup location. It comes with a 100 GB free monthly usage.

First, you need to sign up for a Google Storage account if you don’t have an account already.

Once done, download and install GSUtil which is a command line tool, allowing you to manage buckets.

Paste the following script into a file called “backup_redmine.sh”

# required settings 
DB_USERNAME='<redmine db username>'
DB_PASSWORD='<redmine db password>'
DB_NAME='<redmine db name>'
REDMINE_ROOT='<full path to redmine root>' # e.g. /home/peter/rails/redmine.commanigy.com'
BACKUP_ROOT='<full path to backup root>' # e.g. /home/peter/backups (will be created)

# optional settings
GS_ROOT='gs://redmine-backup'
GS_FILENAME='backup_'`date +%Y%m%d`'.tar.gz'

echo 'Setting up directories'
mkdir $BACKUP_ROOT/redmine/db -p
mkdir $BACKUP_ROOT/redmine/files -p

echo 'Backing up database'
/usr/bin/mysqldump -u $DB_USERNAME --password=$DB_PASSWORD $DB_NAME | gzip > $BACKUP_ROOT/redmine/db/`date +%Y%m%d`.gz

echo 'Backing up attachments'
rsync -a $REDMINE_ROOT/files/ $BACKUP_ROOT/redmine/files/

echo 'Packing into single archive'
tar -czPf $GS_FILENAME $BACKUP_ROOT/redmine/

echo 'Creating bucket on Google Storage (if not already created)'
gsutil mb $GS_ROOT

echo 'Copying backup archive to Google Storage'
gsutil cp $GS_FILENAME $GS_ROOT

echo 'Cleanup by removing archive'
rm $GS_FILENAME

echo 'Backup complete'

You might want to apply execute rights to your script using

chmod +x backup_redmine.sh

And maybe even add it to your crontab to get daily backups

crontab -e

Then add this line

@daily FULL_PATH_TO_SCRIPT > /dev/null

That’s it.

Let me know if you improve this script.