恢复已归档的对象 - Amazon Simple Storage Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

恢复已归档的对象

无法立即访问存储在 S3 Glacier Flexible Retrieval 或 S3 Glacier Deep Archive 存储类中的 Amazon S3 对象。要访问这些存储类中的对象,您必须在指定的持续时间(天数)内将该对象的临时副本还原到 S3 存储桶。有关使用这些存储类的信息,请参阅 使用 Amazon S3 存储类管理存储生命周期

从 S3 Glacier Flexible Retrieval 或 S3 Glacier Deep Archive 还原的对象仅在您指定的天数内存储。如果您想获得对象的永久拷贝,可在 Amazon S3 存储桶中创建该对象的拷贝。除非您制作副本,否则对象仍将存储在 S3 Glacier Flexible Retrieval 或 S3 Glacier Deep Archive 存储类中。

Amazon S3 将您指定的天数与您请求还原对象的时间相加来计算过期日期,然后四舍五入至 UTC 时间第二天的午夜。该计算方法既适用于对象的初始恢复,也适用于您请求的所有可用时间延期。例如,如果对象的恢复时间为 2012 年 10 月 15 日 10:30 AM UTC 且您指定的天数为 3 天,则该对象在 2012 年 10 月 19 日 00:00 UTC 前均可用。如果您在 2012 年 10 月 16 日 11:00 AM UTC 将您希望的可访问天数更改为 1,则 Amazon S3 会将还原对象的可用截止日期更改为 2012 年 10 月 18 日 00:00 UTC。

还原某个归档对象时,您需要同时为归档和临时还原的副本付费。有关定价的信息,请参阅 Amazon S3 定价

您可以使用 Amazon S3 控制台、REST API、Amazon SDK 和 Amazon Command Line Interface (Amazon CLI) 还原归档的对象。

使用以下步骤还原已归档到 S3 Glacier Flexible Retrieval 或 S3 Glacier Deep Archive 存储类的对象,来检查状态并对正在进行的还原进行升级。(控制台使用 S3 Glacier Flexible RetrievalGlacier Deep Archive 作为这些存储类的名称。)

还原已归档的对象
  1. 登录到 Amazon Web Services Management Console,然后通过以下网址打开 Amazon S3 控制台:https://console.aws.amazon.com/s3/

  2. Buckets (存储桶) 列表中,选择包含您想要还原的对象的存储桶的名称。

  3. Objects(对象)列表中,选择要还原的一个或多个对象,再选择 Actions(操作),然后选择 Initiate restore(启动还原)。

  4. 如果要从 S3 Glacier Flexible Retrieval 或 S3 Glacier Deep Archive 进行还原,请在 Initiate restore(启动还原)对话框中输入您希望可访问归档数据的天数。

  5. Retrieval options(检索选项)中,执行以下操作之一:

    • 选择批量检索标准检索l,然后选择还原

    • 选择 Expedited retrieval(加急检索)(仅适用于 S3 Glacier Flexible Retrieval 或 S3 Intelligent-Tiering 归档访问)。

  6. 预置容量仅适用于 S3 Glacier Flexible Retrieval 中的对象。如果您有预配置容量,请选择 还原以开始进行预配置检索。

    如果您有预配置容量,则您的预配置容量可处理您的所有加速检索。有关更多信息,请参阅预配置容量

    • 如果您没有预配置容量并且不想购买,请选择还原

    • 如果您没有预配置容量但是想要购买,请选择添加容量单位,然后选择购买。在收到购买成功消息后,选择还原开始预配置检索。

在还原过程中,您可以升级还原的速度。

将正在进行的还原升级到更快的层级
  1. 通过以下网址打开 Amazon S3 控制台:https://console.aws.amazon.com/s3/

  2. 存储桶名称列表中,选择包含您想要还原的对象的存储桶的名称。

  3. Objects(对象)列表中,选择正在还原的一个或多个对象,再选择 Actions(操作),然后选择 Restore from S3 Glacier Flexible Retrieval(从 S3 Glacier Flexible Retrieval 还原)。有关检查对象还原状态的信息,请参阅检查还原状态和到期日期

  4. 选择要升级到的层级,然后选择 Restore(还原)。

    有关升级到更快的还原层的信息,请参阅 升级正在进行的还原的速度

    注意

    S3 Intelligent-Tiering 的标准和批量还原是免费的。但是,在已恢复的对象上调用的后续恢复请求将按 GET 请求计费。

检查还原状态和到期日期

可以通过对象概述页面来查看还原进度。有关更多信息,请参阅在 Amazon S3 控制台中查看对象概述。此页面将显示还原正在进行中

如果您要从 S3 Glacier Flexible Retrieval 或 S3 Glacier Deep Archive 进行还原,则 Object overview(对象概述)的临时副本将显示 Restoration expiry date(还原到期日期)。此时 Amazon S3 将删除您的归档的已还原副本。

从 S3 Glacier Flexible Retrieval 或 S3 Glacier Deep Archive 还原的对象仅在您指定的天数内存储。如果您想获得对象的永久拷贝,可在 Amazon S3 存储桶中创建该对象的拷贝。

对象还原后,您可以从 Overview 页面中下载。有关更多信息,请参阅在 Amazon S3 控制台中查看对象概述

Java

以下示例使用 Amazon SDK for Java 还原了已归档对象的副本。该示例为指定的归档对象启动还原请求并检查其还原状态。

有关创建和测试有效示例的说明,请参阅测试 Amazon S3 Java 代码示例

import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.regions.Regions; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.RestoreObjectRequest; import java.io.IOException; public class RestoreArchivedObject { public static void main(String[] args) throws IOException { Regions clientRegion = Regions.DEFAULT_REGION; String bucketName = "*** Bucket name ***"; String keyName = "*** Object key ***"; try { AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withCredentials(new ProfileCredentialsProvider()) .withRegion(clientRegion) .build(); // Create and submit a request to restore an object from Glacier for two days. RestoreObjectRequest requestRestore = new RestoreObjectRequest(bucketName, keyName, 2); s3Client.restoreObjectV2(requestRestore); // Check the restoration status of the object. ObjectMetadata response = s3Client.getObjectMetadata(bucketName, keyName); Boolean restoreFlag = response.getOngoingRestore(); System.out.format("Restoration status: %s.\n", restoreFlag ? "in progress" : "not in progress (finished or failed)"); } catch (AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 couldn't process // it, so it returned an error response. e.printStackTrace(); } catch (SdkClientException e) { // Amazon S3 couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3. e.printStackTrace(); } } }
.NET

以下 C# 示例启动将归档对象还原 2 天的请求。Amazon S3 将保持对象元数据中的恢复状态。在启动此请求后,示例将检索对象元数据并检查 RestoreInProgress 属性的值。

有关创建和测试有效示例的说明,请参阅运行 Amazon S3 .NET 代码示例

using Amazon; using Amazon.S3; using Amazon.S3.Model; using System; using System.Threading.Tasks; namespace Amazon.DocSamples.S3 { class RestoreArchivedObjectTest { private const string bucketName = "*** bucket name ***"; private const string objectKey = "** archived object key name ***"; // Specify your bucket region (an example region is shown). private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2; private static IAmazonS3 client; public static void Main() { client = new AmazonS3Client(bucketRegion); RestoreObjectAsync(client, bucketName, objectKey).Wait(); } static async Task RestoreObjectAsync(IAmazonS3 client, string bucketName, string objectKey) { try { var restoreRequest = new RestoreObjectRequest { BucketName = bucketName, Key = objectKey, Days = 2 }; RestoreObjectResponse response = await client.RestoreObjectAsync(restoreRequest); // Check the status of the restoration. await CheckRestorationStatusAsync(client, bucketName, objectKey); } catch (AmazonS3Exception amazonS3Exception) { Console.WriteLine("An AmazonS3Exception was thrown. Exception: " + amazonS3Exception.ToString()); } catch (Exception e) { Console.WriteLine("Exception: " + e.ToString()); } } static async Task CheckRestorationStatusAsync(IAmazonS3 client, string bucketName, string objectKey) { GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest { BucketName = bucketName, Key = objectKey }; GetObjectMetadataResponse response = await client.GetObjectMetadataAsync(metadataRequest); Console.WriteLine("restoration status: {0}", response.RestoreInProgress ? "in-progress" : "finished or failed"); } } }

Amazon S3 向您提供了用于启动归档还原的 API。有关更多信息,请参阅 Amazon Simple Storage Service API 参考中的 RestoreObject

使用 restore-object 命令从 S3 Glacier Flexible Retrieval 还原对象。

在以下示例中,将 awsexamplebucket 中的对象 dir1/example.obj 还原 25 天。

aws s3api restore-object --bucket awsexamplebucket --key dir1/example.obj --restore-request '{"Days":25,"GlacierJobParameters":{"Tier":"Standard"}}'

如果示例中使用的 JSON 句法导致 Windows 客户端错误,则使用如下句法替换还原请求:

--restore-request Days=25,GlacierJobParameters={"Tier"="Standard"}

您可以使用以下命令以监控 restore-object 请求的状态:

aws s3api head-object --bucket awsexamplebucket --key dir1/example.obj

有关更多信息,请参阅《Amazon CLI 命令参考》中的 restore-object