I’ve been running several VMs on Amazon’s EC2 through their AWS services and need to run automated backups just in case something happens. Luckily, they have a nice API to make this really easy.
EBS snapshots are incremental, so they don’t take a ton of space if you’re doing daily snapshots. Root snapshots should only be made while the host is down, but user data should be partitioned off of the root filesystem anyway.
We just have two volumes to snapshot – /home and /data. One of those does house MySQL database files, so we want to have that flushed while the snapshot is running. I found a tool called ec2-consistent-snapshot that makes it easy to freeze the filesystems, flush the DB, and take the snapshot.
Step 1: Install the tool
Step 2: Gather your data
Gather your volume IDs from the AWS console and inventory any database instances, usernames, passwords, etc. Create your .awscredentials file and .my.cnf with your credentials for AWS and MySQL.
Step 3: Create the scripts
1 2 3 4 5 6 7 8 9 10 11 12
Step 4: Put it in a script and schedule it in cron