skip navigation

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.

About Us

Scheduling EBS Snapshots on AWS for Windows EC2 Instances

09/19/2013, 2:00pm CDT
By Ian Ehlert

Get automatic EBS snapshots going on your Windows EC2 instances with minimal headaches.


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.

How to

Before you can even successfully run this script, you need to install the Amazon EC2 Command Line Tools

Important steps to note:

  • Make sure that the IAM user whose keys you are using has these permissions: ec2:CreateSnapshot, ec2:DeleteSnapshot, ec2:DescribeSnapshots
  • Make sure that %JAVA_HOME%\bin and %EC2_HOME%\bin get added to your PATH system variable. It's easy to miss those steps.
  • If the volumes that you want to snapshot are not in 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.

Configure the script

  1. Change the AWS_HOME variable to a directory that can hold temporary text files that the script needs to create.
  2. Change the AWS_VOLUME variable to the volume-id of the volume that you want to snapshot.
  3. Change the AWS_SNAPSHOT_KEEP variable to the number of snapshots you want to keep.

Schedule the script

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:

Tag(s): Home  DevOps