EasyManua.ls Logo

AWS Storage Gateway - Page 175

AWS Storage Gateway
438 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
AWS Storage Gateway User Guide
Deleting Snapshots
static void Main(string[] args)
{
// Create an EC2 client.
ec2Config = new AmazonEC2Config();
ec2Config.ServiceURL = "https://ec2." + AwsRegion + ".amazonaws.com";
ec2Client = new AmazonEC2Client(AwsAccessKey, AwsSecretKey, ec2Config);
// Create a Storage Gateway client.
sgConfig = new AmazonStorageGatewayConfig();
sgConfig.ServiceURL = "https://storagegateway." + AwsRegion +
".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

Table of Contents