使用 Amazon Glacier 中的文件库下载档案 适用于 Java 的 Amazon SDK - Amazon Glacier
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

此页面仅适用于使用 Vaults 和 2012 年原始 REST API 的 Amazon Glacier 服务的现有客户。

如果您正在寻找档案存储解决方案,我们建议您在亚马逊 S3、S3 Glacier 即时检索、S3 Glacier 灵活检索和 S3 Glacier Deep Archive Deep Archive 中使用 Amazon Glacier 存储类。要了解有关这些存储选项的更多信息,请参阅 Amazon Glacier 存储类别

从 2025 年 12 月 15 日起,Amazon Glacier(最初基于保管库的独立服务)将不再接受新客户,对现有客户不产生任何影响。Amazon Glacier 是一项独立的服务 APIs ,拥有自己的服务,可将数据存储在文件库中,不同于亚马逊 S3 和 Amazon S3 Glacier 存储类别。在 Amazon Glacier 中,您的现有数据将保持安全且可以无限期地访问。无需迁移。对于低成本、长期的存档存储, Amazon 建议使用 Amazon S3 Glacier 存储类别,这些存储类别基于S3存储桶 APIs、完全 Amazon Web Services 区域 可用性、更低的成本和 Amazon 服务集成,可提供卓越的客户体验。如果您想要增强功能,可以考虑使用我们的Amazon 解决方案指南迁移到 Amazon S3 Glacier 存储类别,将数据从 Amazon Glacier 文件库传输到 Amazon S3 Glacier 存储类

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Amazon Glacier 中的文件库下载档案 适用于 Java 的 Amazon SDK

以下 Java 代码示例使用的 适用于 Java 的 Amazon SDK 高级别 API 下载您在上一步中上传的档案。在代码示例中,请注意以下情况:

  • 以下示例创建 AmazonGlacierClient 类的实例。

  • 该代码使用美国西部(俄勒冈州)区域 (us-west-2) 匹配您之前在第 2 步:在 Amazon Glacier 中创建文件库中创建文件库的位置。

  • 该示例使用了 ArchiveTransferManager 类的 download API 操作,该类属于 适用于 Java 的 Amazon SDK高级 API。该示例将创建 Amazon Simple Notification Service (Amazon SNS) 主题,以及该主题订阅的 Amazon Simple Queue Service (Amazon SQS) 队列。如果您按照中的说明创建了 Amazon Identity and Access Management (IAM) 管理员用户第 1 步:开始使用 Amazon Glacier 之前,则您的用户拥有创建和使用 Amazon SNS 主题和 Amazon SQS 队列所必需的 IAM 权限。

有关如何运行此示例的 step-by-step说明,请参阅使用 Eclipse 为亚马逊 Glacier 运行 Java 示例。您需要更新 步骤 3:将档案上传到 Amazon Glacier 中的文件库 中已上传文件的档案 ID 旁显示的代码。

例 使用 适用于 Java 的 Amazon SDK下载档案
import java.io.File; import java.io.IOException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.glacier.AmazonGlacierClient; import com.amazonaws.services.glacier.transfer.ArchiveTransferManager; import com.amazonaws.services.sns.AmazonSNSClient; import com.amazonaws.services.sqs.AmazonSQSClient; public class AmazonGlacierDownloadArchive_GettingStarted { public static String vaultName = "examplevault"; public static String archiveId = "*** provide archive ID ***"; public static String downloadFilePath = "*** provide location to download archive ***"; public static AmazonGlacierClient glacierClient; public static AmazonSQSClient sqsClient; public static AmazonSNSClient snsClient; public static void main(String[] args) throws IOException { ProfileCredentialsProvider credentials = new ProfileCredentialsProvider(); glacierClient = new AmazonGlacierClient(credentials); sqsClient = new AmazonSQSClient(credentials); snsClient = new AmazonSNSClient(credentials); glacierClient.setEndpoint("glacier.us-west-2.amazonaws.com"); sqsClient.setEndpoint("sqs.us-west-2.amazonaws.com"); snsClient.setEndpoint("sns.us-west-2.amazonaws.com"); try { ArchiveTransferManager atm = new ArchiveTransferManager(glacierClient, sqsClient, snsClient); atm.download(vaultName, archiveId, new File(downloadFilePath)); } catch (Exception e) { System.err.println(e); } } }