AWS Developer Tools Blog
Archiving and Backing-up Data with the AWS SDK for Java
Do you or your company have important data that you need to archive? Have you explored Amazon Glacier yet? Amazon Glacier is an extremely low-cost storage service that provides secure and durable storage for data archiving and backup. Just like with other AWS offerings, you pay only for what you use. You don’t have to pay large upfront infrastructure costs or predict capacity requirements like you do with on-premise solutions. Simply use what you need, when you need it, and pay only for what you use.
There are two easy ways to leverage Amazon Glacier for data archives and backups using the AWS SDK for Java. The first option is to interact with the Amazon Glacier service directly. The AWS SDK for Java includes a high-level API called ArchiveTransferManager for easily working with transfers into and out of Amazon Glacier.
ArchiveTransferManager atm = new ArchiveTransferManager(myCredentials); UploadResult uploadResult = atm.upload("myVaultName", "old logs", new File("/logs/oldLogs.zip")); // later, when you need to retrieve your data atm.download("myVaultName", uploadResult.getArchiveId(), new File("/download/logs.zip"));
The second easy way of getting your data into Amazon Glacier using the SDK is to get your data into Amazon S3 first, and use a bucket lifecycle to automatically archive your objects into Amazon Glacier after a certain period.
It’s easy to configure an Amazon S3 bucket’s lifecycle using the AWS Management Console or the AWS SDKs. Here’s how to create a bucket lifecycle that will copy objects under the “logs/” key prefix to Amazon Glacier after 365 days, and will remove them completely from your Amazon S3 bucket a few days later at the 370 day mark.
AmazonS3 s3 = new AmazonS3Client(myCredentials); Transition transition = new Transition() .withDays(365).withStorageClass(StorageClass.Glacier); BucketLifecycleConfiguration config = new BucketLifecycleConfiguration() .withRules(new Rule() .withId("log-archival-rule") .withKeyPrefix("logs/") .withExpirationInDays(370) .withStatus(ENABLED) .withTransition(transition)); s3.setBucketLifecycleConfiguration(myBucketName, config);
Are you using Amazon Glacier yet? Let know how you’re using it and how it’s working for you!