Blog moved to Amazon EC2
I decided to move my blog, and some other services I run, to Amazon EC2. I have had nothing but excellent service from the current hosting company, Rimu Hosting where I have a VPS, however I want to see how reliable EC2 really is in practice.
I don’t yet have access to persistent storage on EC2, so I cobbled together a quick paranoid hourly data dump of critical files to my S3 account. Investigated a few different S3 backup options, settled on a quick and dirty.
I really wanted to use s3fs to simply mount my S3 bucket using FUSE and then use rsync to manage my backups. However, I am running Debian Etch in EC2 and even with the backports version of the FUSE libs, and the Amazon supplied 2.6.16 kernel, I was unable to load the kernel fuse module as it appears to be compiling a module version which doesn’t like the running kernel.
So I simplified it and wrote my own script in a few minutes. I don’t have much data at all to backup, if you have any meaningful amount of data then you need a more intelligent system than this.
Here is my EC2 -> S3 backup script. Ugly, but works (for me).
You need s3sync for this to work.
#!/bin/bash
#SETTING 1: what directories to backup
BACK_THESE_UP="/root /etc /mnt/backup/apps /mnt/backup/backups /mnt/web"
#SETTING: where to create local tarballs
BACKUP_TO_BASE=/mnt/backup/snapshots
#SETTING: time format used in filenames
THETIME=`/bin/date +%m-%d-%y--%H:%M:%S`
# ACTION: manual, paranoid MySQL dump
mysqldump --all-databases -u YOUUSER --password=YOURPASS > /mnt/backup/backups/mysql/manual/$THETIME.sql
gzip /mnt/backup/backups/mysql/manual/$THETIME.sql
# ACTION: create our backup tarball
tar -zcvf $BACKUP_TO_BASE/$THETIME.tar.gz $BACK_THESE_UP
# ACTION: put that tarball on S3
/mnt/backup/apps/s3sync/s3cmd.rb --ssl put YOURBUCKETNAME:$THETIME.tar.gz $BACKUP_TO_BASE/$THETIME.tar.gz