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.
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: