AWS Storage Gateway User Guide
Deleting Snapshots
catch (AmazonEC2Exception ex)
{
Console.WriteLine(ex.Message);
}
}
/*
* Checks if the snapshot creation date is past the retention period.
*/
private static Boolean IsSnapshotPastRetentionPeriod(int daysBack, DateTime
snapshotDate)
{
DateTime cutoffDate = DateTime.Now.Add(new TimeSpan(-daysBack, 0, 0, 0));
return (DateTime.Compare(snapshotDate, cutoffDate) < 0) ? true : false;
}
/*
* Displays information related to a volume.
*/
private static String OutputVolumeInfo(VolumeInfo vi)
{
String volumeInfo = String.Format(
"Volume Info:\n" +
" ARN: {0}\n" +
" Type: {1}\n",
vi.VolumeARN,
vi.VolumeType);
return volumeInfo;
}
}
}
Deleting Snapshots by Using the AWS Tools for Windows
PowerShell
To delete many snapshots associated with a volume, you can use a programmatic approach. The example
following demonstrates how to delete snapshots using the AWS Tools for Windows PowerShell. To use
the example script, you should be familiar with running a PowerShell script. For more information, see
AWS Tools for Windows PowerShell
. If you need to delete just a few snapshots, use
.
Example : Deleting Snapshots by Using the AWS Tools for Windows PowerShell
The following PowerShell script example lists the snapshots for each volume of a gateway and whether
the snapshot start time is before or after a specified date. It uses the AWS Tools for Windows PowerShell
cmdlets for AWS Storage Gateway and Amazon EC2. The Amazon EC2 API includes operations for
working with snapshots.
You need to update the script and provide your gateway Amazon Resource Name (ARN) and the number
of days back you want to save snapshots. Snapshots taken before this cutoff are deleted. You also need
to specify the Boolean value
viewOnly
, which indicates whether you want to view the snapshots to be
deleted or to actually perform the snapshot deletions. Run the code first with just the view option (that
is, with
viewOnly
set to
true
) to see what the code deletes.
<#
.DESCRIPTION
Delete snapshots of a specified volume that match given criteria.
.NOTES
PREREQUISITES:
1) AWS Tools for PowerShell from http://console.amazonaws.cn/powershell/
API Version 2013-06-30
170