AWS Storage Gateway User Guide
Deleting Snapshots
static void Main(string[] args)
{
// Create an EC2 client.
ec2Config = new AmazonEC2Config();
ec2Config.ServiceURL = "https://ec2." + Aws ".amazonaws.com";
ec2Client = new AmazonEC2Client(AwsAccessKey, AwsSecretKey, ec2Config);
// Create a Storage Gateway client.
sgConfig = new AmazonStorageGatewayConfig();
sgConfig.ServiceURL = "https://storagegateway." + Aws
".amazonaws.com";
sgClient = new AmazonStorageGatewayClient(AwsAccessKey, AwsSecretKey,
sgConfig);
List<VolumeInfo> StorageGatewayVolumes = ListVolumesForGateway();
List<Snapshot> StorageGatewaySnapshots =
ListSnapshotsForVolumes(StorageGatewayVolumes,
daysBack);
DeleteSnapshots(StorageGatewaySnapshots);
}
/*
* List all volumes for your gateway
* returns: A list of VolumeInfos, or null.
*/
private static List<VolumeInfo> ListVolumesForGateway()
{
ListVolumesResponse response = new ListVolumesResponse();
try
{
ListVolumesRequest request = new ListVolumesRequest();
request.GatewayARN = GatewayARN;
response = sgClient.ListVolumes(request);
foreach (VolumeInfo vi in response.VolumeInfos)
{
Console.WriteLine(OutputVolumeInfo(vi));
}
}
catch (AmazonStorageGatewayException ex)
{
Console.WriteLine(ex.Message);
}
return response.VolumeInfos;
}
/*
* Gets the list of snapshots that match the requested volumes
* and cutoff period.
*/
private static List<Snapshot> ListSnapshotsForVolumes(List<VolumeInfo> volumes, int
snapshotAge)
{
List<Snapshot> SelectedSnapshots = new List<Snapshot>();
try
{
foreach (VolumeInfo vi in volumes)
{
String volumeARN = vi.VolumeARN;
String volumeID = volumeARN.Substring(volumeARN.LastIndexOf("/") +
1).ToLower();
DescribeSnapshotsRequest describeSnapshotsRequest = new
DescribeSnapshotsRequest();
API Version 2013-06-30
168