2

So I am tasked with creating a Batch script to handle creating and deleting snapshots of one of our servers. Well I have most of it working but the problem I am having is trying to list out more than 11 snapshots. We have well over 200 snapshots on one volume.

I've tried ec2-describe-snapshots -F "volume-id=vol-12345" -F "status=completed"|sort /R /+49 where vol-12345 is my volume id of course. That does do the proper sorting by date that I need but it still only returns 11 snapshots. I also tried to throw a -a at the end in case there were any private snapshots but I was still getting only 11.

I did see this post: how to list all the snapshots created from a single volume ID EC2 instance but that doesnt quite answer my question on how to display more than 11 snapshots. Any help on this would be greatly appreciated! Thanks.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Tomas
  • 1,392
  • 2
  • 9
  • 13
  • You can use python boto. Which is easy and simple. – Sailesh Kotha May 01 '15 at 18:44
  • I would but I have to specifically use a batch file. Its my bosses request. We're running it on a windows server and we wanna keep the installed things to a minimum. – Tomas May 01 '15 at 18:50
  • 1
    @tec4 Since you're running on windows, would AWS CLI or AWS Tools for PowerShell be an option? If you're using an AMI that Amazon created, one or both of those may already be installed. – Anthony Neace May 01 '15 at 19:51
  • @HyperAnthony That is an option! Just checked and I think it comes on the AMI. I think I'll look more into the AWS Tools for PowerShell then. The EC2 CLI seems to be kinda limiting. Thanks! – Tomas May 01 '15 at 20:04
  • 1
    Sure. Here's a good place to start, for listing snapshots: http://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2Snapshot.html – Anthony Neace May 01 '15 at 20:07

1 Answers1

2

Here's an alternative, using the AWS Tools for PowerShell. This utility should already be installed if your Windows EC2 is based off of an AMI that Amazon provided.

This example describes a collection of snapshots that you created, and is filtered by status "completed" and by your provided volumeId. It is sorted by StartTime.

# Create a filter to limit by status = completed
$filterByStatusCompleted = New-Object Amazon.EC2.Model.Filter -Property @{Name = "status"; Value = "completed"}
# Create a filter to limit by specific volume ID
$filterByVolumeId = New-Object Amazon.EC2.Model.Filter -Property @{Name = "volume-id"; Value = "vol-11111111"}

# Describe the collection of snapshots, sorted by StartTime
Get-EC2Snapshot -OwnerIds self -Filter $filterByStatusCompleted, $filterByVolumeId | Sort -Property StartTime

Documentation:

Anthony Neace
  • 25,013
  • 7
  • 114
  • 129