Amazon EBS Snapshot Backups with LVM and XFS

I’m working on setting up a server to host email accounts on Amazon EC2 using the newly released Elastic Block Storage.  My benchmarking has shown XFS to be better than ReiserFS for this task – and presumably EXT3, but I ran out of patience.

Since I will need to grow the filesystem in the future, I am using LVM.  This also allows me to break up the logical volume into separate EBS volumes, which should increase random access performance.  

Right now for testing, I have a single LVM volume group and logical volume comprised of three “physical” EBS volumes of 100GB each. 

Although EBS’s snapshot command completes quickly and the snapshots are consistent as of the time the command is run (there is a pause in access to the filesystem while the snapshot starts), the use of multiple EBS volumes complicates matters.  In order to get a consistent snapshot, the whole filesystem needs to be stopped while a snapshot is begun on each of the underlying EBS volumes.  Conveniently XFS has a “freeze” command to flush the whole filesystem and prevent writes until it is unfrozen.

Here’s my current snapshot script:

#!/bin/bash

SNAP_CMD=/usr/local/ec2/bin/ec2-create-snapshot
MOUNT_POINT=/mail
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.06
export EC2_CERT=/mnt/aws-config/cert-XXXX.pem
export EC2_HOME=/usr/local/ec2
export EC2_PRIVATE_KEY=/mnt/aws-config/pk-XXXX.pem

vols=("vol-xxxx" "vol-xxxx" "vol-xxxx")
i=0
xfs_freeze -f $MOUNT_POINT

for vol in ${vols[@]}
do
        $SNAP_CMD $vol &
        pids[i]=$!
        let i+=1
done

for pid in ${pids[@]}
do
        wait $pid
done

xfs_freeze -u $MOUNT_POINT

This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

2 Responses to Amazon EBS Snapshot Backups with LVM and XFS

  1. Pingback: kb.hurricane-ridge.com / Bookmarks for February 11, 2009

  2. Pingback: Amazon EBS Snapshot Backups with LVM and XFS - Ext3 Ext4 Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *