Here you will find ideas and code straight from the Software Development Team at SportsEngine. Our focus is on building great software products for the world of youth and amateur sports. We are fortunate to be able to combine our love of sports with our passion for writing code.
The SportsEngine application originated in 2006 as a single Ruby on Rails 1.2 application. Today the SportsEngine Platform is composed of more than 20 applications built on Rails and Node.js, forming a service oriented architecture that is poised to scale for the future.
We found we needed a Windows batch script that could create EBS snapshots for a specific volume and clean up the old ones. This is a gist of the script we ended up using to schedule our daily snapshots.
Before you can even successfully run this script, you need to install the Amazon EC2 Command Line Tools
Important steps to note:
ec2:CreateSnapshot
, ec2:DeleteSnapshot
, ec2:DescribeSnapshots
%JAVA_HOME%\bin
and %EC2_HOME%\bin
get added to your PATH
system variable. It's easy to miss those steps.us-east-1
, make sure you follow Task 5: Set the Region (Optional)Once you are able to successfully run ec2-describe-snapshots
from a cmd prompt, you should be set to schedule this script.
AWS_HOME
variable to a directory that can hold temporary text files that the script needs to create.AWS_VOLUME
variable to the volume-id of the volume that you want to snapshot.AWS_SNAPSHOT_KEEP
variable to the number of snapshots you want to keep.Just open up Scheduled Tasks, set the Action to be the location of the batch file, ex: C:\ec2_snapshot.bat
Once scheduled, the batch script will take care of creating snapshots and rotating out old ones. Here's the script in its entirety: