EasyManua.ls Logo

AWS Storage Gateway - Page 171

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
the view option (that is, with viewOnly set to true) to see what the code deletes. For a list of AWS
service endpoints you can use with AWS Storage Gateway, see Regions and Endpoints in the AWS General
Reference.
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.ec2.model.DeleteSnapshotRequest;
import com.amazonaws.services.ec2.model.DescribeSnapshotsRequest;
import com.amazonaws.services.ec2.model.DescribeSnapshotsResult;
import com.amazonaws.services.ec2.model.Filter;
import com.amazonaws.services.ec2.model.Snapshot;
import com.amazonaws.services.storagegateway.AWSStorageGatewayClient;
import com.amazonaws.services.storagegateway.model.ListVolumesRequest;
import com.amazonaws.services.storagegateway.model.ListVolumesResult;
import com.amazonaws.services.storagegateway.model.VolumeInfo;
public class ListDeleteVolumeSnapshotsExample {
public static AWSStorageGatewayClient sgClient;
public static AmazonEC2Client ec2Client;
static String serviceURLSG = "https://storagegateway.us-east-1.amazonaws.com";
static String serviceURLEC2 = "https://ec2.us-east-1.amazonaws.com";
// The gatewayARN
public static String gatewayARN = "*** provide gateway ARN ***";
// The number of days back you want to save snapshots. Snapshots before this cutoff are
deleted
// if viewOnly = false.
public static int daysBack = 10;
// true = show what will be deleted; false = actually delete snapshots that meet the
daysBack criteria
public static boolean viewOnly = true;
public static void main(String[] args) throws IOException {
// Create a storage gateway and amazon ec2 client
sgClient = new AWSStorageGatewayClient(new PropertiesCredentials(
ListDeleteVolumeSnapshotsExample.class.getResourceAsStream("AwsCredentials.properties")));
sgClient.setEndpoint(serviceURLSG);
ec2Client = new AmazonEC2Client(new PropertiesCredentials(
ListDeleteVolumeSnapshotsExample.class.getResourceAsStream("AwsCredentials.properties")));
ec2Client.setEndpoint(serviceURLEC2);
List<VolumeInfo> volumes = ListVolumesForGateway();
DeleteSnapshotsForVolumes(volumes, daysBack);
}
public static List<VolumeInfo> ListVolumesForGateway()
{
List<VolumeInfo> volumes = new ArrayList<VolumeInfo>();
API Version 2013-06-30
164

Table of Contents