AWS Storage Gateway User Guide
Deleting Snapshots
Filter ownerFilter = new Filter();
List<String> ownerValues = new List<String>();
ownerValues.Add(OwnerID);
ownerFilter.Name = "owner-id";
ownerFilter.Values = ownerValues;
describeSnapshotsRequest.Filters.Add(ownerFilter);
Filter statusFilter = new Filter();
List<String> statusValues = new List<String>();
statusValues.Add(SnapshotStatus);
statusFilter.Name = "status";
statusFilter.Values = statusValues;
describeSnapshotsRequest.Filters.Add(statusFilter);
Filter volumeFilter = new Filter();
List<String> volumeValues = new List<String>();
volumeValues.Add(volumeID);
volumeFilter.Name = "volume-id";
volumeFilter.Values = volumeValues;
describeSnapshotsRequest.Filters.Add(volumeFilter);
DescribeSnapshotsResponse describeSnapshotsResponse =
ec2Client.DescribeSnapshots(describeSnapshotsRequest);
List<Snapshot> snapshots = describeSnapshotsResponse.Snapshots;
Console.WriteLine("volume-id = " + volumeID);
foreach (Snapshot s in snapshots)
{
if (IsSnapshotPastRetentionPeriod(snapshotAge, s.StartTime))
{
Console.WriteLine(s.SnapshotId + ", " + s.VolumeId + ",
" + s.StartTime + ", " + s.Description);
SelectedSnapshots.Add(s);
}
}
}
}
catch (AmazonEC2Exception ex)
{
Console.WriteLine(ex.Message);
}
return SelectedSnapshots;
}
/*
* Deletes a list of snapshots.
*/
private static void DeleteSnapshots(List<Snapshot> snapshots)
{
try
{
foreach (Snapshot s in snapshots)
{
DeleteSnapshotRequest deleteSnapshotRequest = new
DeleteSnapshotRequest(s.SnapshotId);
DeleteSnapshotResponse response =
ec2Client.DeleteSnapshot(deleteSnapshotRequest);
Console.WriteLine("Volume: " +
s.VolumeId +
" => Snapshot: " +
s.SnapshotId +
" Response: "
+ response.HttpStatusCode.ToString());
}
}
API Version 2013-06-30
169