Day 69: Using PowerShell to Automate AWS Backups with Snapshots

Welcome to Day 69 of the “100 Days of DevOps with PowerShell”! For background on our goals in this series, see Announcing the “100 Days of Devops with PowerShell” Series here at SCC.

In our previous articles (Day 59  & Day 64) we looked into how snapshots can be used to create a copy of a known state of an environment, restore that environment and also how to increase the size of a volume.  In this final article on snapshots we are going to  take it one step further and see how snapshots can be used provide continuous backups of our AWS instances.

One of the duties that befalls IT Operations is the support and management of reliable backups.  When developers are actively coding and delivering a product that the company will sell or supports a business critical process the stakes are raised to a point that if there’s an outage it directly impacts the bottom line.  Therefore a backup strategy that is reliable and automated shouldn’t be seen as a nice to have, but absolutely mandatory.

When managing infrastructure in the cloud there is a certain amount of redundancy built into the instances and the storage to support them.  This however, does not negate the need for a backup strategy and also requires a rethink of how to manage backups in a cloud environment.

Using snapshots for your backups

A snapshot in AWS is a point in time copy of a volume that (as we saw in Day 59) can easily be restored.  Because of the speed in which they can be taken and restored we don’t need to worry about incremental or differential backups as we would in a more traditional process.

Using PowerShell to automate AWS backups

In the example below we rely on tags to keep track of our volumes and when they were backed up.  At a high level the following steps are done:

  1. Search for any volumes without a tag called BackupEnabled – at this point we could provide filters and exclude volumes not needed for backup
  2. Apply the tag to any volume missing it.
  3. Get a list of volumes with the tag BackupEnabled and a value of True.  Volumes not required for backup could be set to False
  4. Create snapshots of each the volumes and apply some meta data in tags.  At this point we are also retrieving the instance the volume is connected to.  This is useful if we wanted to retrieve a list of volumes for a specific instance or restore all volumes of an instance.
  5. Delete any snapshots that were created older than the specified retention period (14 days)

Running the backups

To run our backups simply run the script as scheduled task on an instance.  The instance itself can be granted the appropriate rights by applying a role to an instance.  Read more of how to do that here.


We’ve shown how we can create a backup of all in-scope AWS volumes and also shown the extensible power of tags in how they can keep track of which volumes are backed up.  This is by no means a complete solution and some of the next steps to consider would be differing backup schedules, retention periods and also notifications through your own email system or AWS’s Simple Email Service (SES).  To restore our backups simply follow the steps discussed in Day 64, where we looked at restoring a volume by snapshots.

Previous Installments

To see the previous installments in this series, visit “100 Days of DevOps with PowerShell”.

4 thoughts on “Day 69: Using PowerShell to Automate AWS Backups with Snapshots

  1. WAI

    Has anybody been able to get this to work?  It has a lot of errors in it, but this is what I need for my backups

  2. Pingback: Creating and Managing AWS Snapshots in Powershell | Syndeo Technologies Blog

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.