

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

如果您正在寻找归档存储解决方案，建议使用 Amazon S3 中的 Amazon Glacier 存储类别 S3 Glacier Instant Retrieval、S3 Glacier Flexible Retrieval 和 S3 Glacier Deep Archive。要了解有关这些存储选项的更多信息，请参阅 [Amazon Glacier 存储类别](https://aws.amazon.com/s3/storage-classes/glacier/)。

Amazon Glacier（最初基于保管库的独立服务）不再接受新客户。Amazon Glacier 是一项独立的服务 APIs ，拥有自己的服务，可将数据存储在文件库中，不同于亚马逊 S3 和 Amazon S3 Glacier 存储类别。在 Amazon Glacier 中，您现有的数据将确保安全，并且可以无限期地访问。无需进行迁移。对于低成本、长期的存档存储， AWS 建议[使用 Amazon S3 Glacier 存储类别，这些存储类别](https://aws.amazon.com/s3/storage-classes/glacier/)基于S3存储桶 APIs、完全 AWS 区域 可用性、更低的成本和 AWS 服务集成，可提供卓越的客户体验。如果您希望加强功能，可以考虑使用我们的 [AWS 将数据从 Amazon Glacier 文件库传输到 Amazon S3 Glacier 存储类别的解决方案指南](https://aws.amazon.com/solutions/guidance/data-transfer-from-amazon-s3-glacier-vaults-to-amazon-s3/)，迁移到 Amazon S3 Glacier 存储类别。

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

# 步骤 4：在 Amazon Glacier 中从文件库下载档案
<a name="getting-started-download-archive"></a>

在此步骤中，您将下载之前在[步骤 3：在 Amazon Glacier 中将档案上传到文件库](getting-started-upload-archive.md)中上传的示例档案。

 

**重要**  
Amazon Glacier 确实提供了一个控制台。但是，任何存档操作（例如上传、下载或删除）都需要您使用 AWS Command Line Interface (CLI) 或编写代码。存档操作没有控制台支持。例如，要上传数据（例如照片、视频和其他文档），您必须使用 AWS CLI 或编写代码来发出请求，方法是直接使用 REST API 或使用 AWS SDKs。  
要安装 AWS CLI，请参阅[AWS Command Line Interface](https://aws.amazon.com/cli/)。有关将 Amazon Glacier 与配合使用的更多信息 AWS CLI，请参阅 [Amazon Glacier AWS CLI 参考](https://docs.aws.amazon.com/cli/latest/reference/glacier/index.html)资料。有关使用将档案上传 AWS CLI 到 Amazon Glacier 的示例，请参阅将 [Amazon Glacier 与 AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/cli-using-glacier.html) 

通常，从 Amazon Glacier 检索数据是一个分为两个步骤的过程：

1. 启动检索任务。

1. 任务完成后，按字节下载数据。

要从 Amazon Glacier 检索档案，您首先要启动任务。任务完成后，您应下载数据。有关档案检索的更多信息，请参阅[检索 Amazon Glacier 档案](downloading-an-archive-two-steps.md)。

您请求的访问时间取决于所选的检索选项：加速、标准还是批量检索。对于除了最大型档案（250 MB\$1）之外的所有其他档案，使用加速检索访问的档案通常在 1 到 5 分钟内可用。使用标准检索来检索的档案通常在 3 到 5 小时内可用。批量检索通常在 5 到 12 小时内可用。有关各个检索选项的更多信息，请参阅 [Amazon Glacier 常见问题解答](https://aws.amazon.com/glacier/faqs/#Data-retrievals)。有关数据检索费用的更多信息，请参阅 [Amazon Glacier 定价页面](https://aws.amazon.com/s3/glacier/pricing/)。

以下主题中显示的代码示例会启动任务，等待任务完成，然后下载档案的数据。

**Topics**
+ [使用 Amazon Glacier 中的文件库下载档案 适用于 Java 的 AWS SDK](getting-started-download-archive-java.md)
+ [使用 Amazon Glacier 中的文件库下载档案 适用于 .NET 的 AWS SDK](getting-started-download-archive-dotnet.md)

# 使用 Amazon Glacier 中的文件库下载档案 适用于 Java 的 AWS SDK
<a name="getting-started-download-archive-java"></a>

以下 Java 代码示例使用的 适用于 Java 的 AWS SDK 高级别 API 下载您在上一步中上传的档案。在代码示例中，请注意以下情况：
+ 以下示例创建 `AmazonGlacierClient` 类的实例。
+ 该代码使用美国西部（俄勒冈州）区域（`us-west-2`）匹配您之前在[步骤 2：在 Amazon Glacier 中创建文件库](getting-started-create-vault.md)中创建文件库的位置。
+ 该示例使用了 `ArchiveTransferManager` 类的 `download` API 操作，该类属于 适用于 Java 的 AWS SDK高级 API。该示例将创建 Amazon Simple Notification Service（Amazon SNS）主题，以及该主题订阅的 Amazon Simple Queue Service（Amazon SQS）队列。如果您按照中的说明创建了 AWS Identity and Access Management (IAM) 管理员用户[步骤 1：开始使用 Amazon Glacier 之前](getting-started-before-you-begin.md)，则您的用户拥有创建和使用 Amazon SNS 主题和 Amazon SQS 队列所必需的 IAM 权限。

有关如何运行此示例的 step-by-step说明，请参阅[使用 Eclipse 运行 Amazon Glacier 的 Java 示例](using-aws-sdk-for-java.md#setting-up-and-testing-sdk-java)。您需要更新 [步骤 3：在 Amazon Glacier 中将档案上传到文件库](getting-started-upload-archive.md) 中已上传文件的档案 ID 旁显示的代码。

**Example — 使用下载档案 适用于 Java 的 AWS SDK**  <a name="GS_ExampleDownloadArchiveJava"></a>

```
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);
        }
    }
}
```

# 使用 Amazon Glacier 中的文件库下载档案 适用于 .NET 的 AWS SDK
<a name="getting-started-download-archive-dotnet"></a>

以下 C\$1 代码示例使用的高级别 API 下载您之前在中上传的档案[使用 Amazon Glacier 将档案上传到文件库 适用于 .NET 的 AWS SDK](getting-started-upload-archive-dotnet.md)。 适用于 .NET 的 AWS SDK 在代码示例中，请注意以下情况：

 
+ 该示例为指定的 Amazon Glacier 区域端点创建 `ArchiveTransferManager` 类的实例。
+ 该代码示例使用美国西部（俄勒冈州）区域（`us-west-2`）匹配您之前在[步骤 2：在 Amazon Glacier 中创建文件库](getting-started-create-vault.md)中创建文件库的位置。
+ 该示例使用 `Download` 类的 `ArchiveTransferManager` API 操作下载档案。该示例将创建 Amazon Simple Notification Service（Amazon SNS）主题，以及该主题订阅的 Amazon Simple Queue Service（Amazon SQS）队列。如果您按照中的说明创建了 AWS Identity and Access Management (IAM) 管理员用户[步骤 1：开始使用 Amazon Glacier 之前](getting-started-before-you-begin.md)，则您的用户拥有创建和使用 Amazon SNS 主题和 Amazon SQS 队列所必需的 IAM 权限。
+ 此示例启动了档案检索任务，并对队列进行轮询以便找到可用档案。如果档案可用，则开始下载。有关检索时间的详细信息，请参阅[档案检索选项](downloading-an-archive-two-steps.md#api-downloading-an-archive-two-steps-retrieval-options)。

有关如何运行此示例的 step-by-step说明，请参阅[运行代码示例](using-aws-sdk-for-dot-net.md#setting-up-and-testing-sdk-dotnet)。您需要更新 [步骤 3：在 Amazon Glacier 中将档案上传到文件库](getting-started-upload-archive.md) 中已上传文件的档案 ID 旁显示的代码。

**Example — 使用的高级别 API 下载档案 适用于 .NET 的 AWS SDK**  <a name="GS_ExampleDownloadArchiveDotNet"></a>

```
using System;
using Amazon.Glacier;
using Amazon.Glacier.Transfer;
using Amazon.Runtime;

namespace glacier.amazon.com.rproxy.govskope.us.docsamples
{
    class ArchiveDownloadHighLevel_GettingStarted
    {
        static string vaultName = "examplevault";
        static string archiveId = "*** Provide archive ID ***";
        static string downloadFilePath = "*** Provide the file name and path to where to store the download ***";

        public static void Main(string[] args)
        {
            try
            {
                var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USWest2);

                var options = new DownloadOptions();
                options.StreamTransferProgress += ArchiveDownloadHighLevel_GettingStarted.progress;
                // Download an archive.
                Console.WriteLine("Intiating the archive retrieval job and then polling SQS queue for the archive to be available.");
                Console.WriteLine("Once the archive is available, downloading will begin.");
                manager.Download(vaultName, archiveId, downloadFilePath, options);
                Console.WriteLine("To continue, press Enter");
                Console.ReadKey();
            }
            catch (AmazonGlacierException e) { Console.WriteLine(e.Message); }
            catch (AmazonServiceException e) { Console.WriteLine(e.Message); }
            catch (Exception e) { Console.WriteLine(e.Message); }
            Console.WriteLine("To continue, press Enter");
            Console.ReadKey();
        }

        static int currentPercentage = -1;
        static void progress(object sender, StreamTransferProgressArgs args)
        {
            if (args.PercentDone != currentPercentage)
            {
                currentPercentage = args.PercentDone;
                Console.WriteLine("Downloaded {0}%", args.PercentDone);
            }
        }
    }
}
```