如何从 AWS Glacier 永久恢复到 S3?

How do I restore from AWS Glacier back to S3 permanently?

我有大约 50Gb 的文件存储在 S3 中。昨天我愚蠢地添加了一个生命周期规则来将超过 30 天的文件从 S3 传输到 Glacier 没有意识到这将禁用 public link 到原始文件。

我真的需要这些文件保留在 S3 中,因为它们是 link 在我们网站上编辑的图像和绘图。

我已经请求从 Glacier 恢复文件,但据我所知,这对文件在返回 Glacier 之前可用的天数有限制。

我在想我将不得不创建一个新的存储桶,然后将文件复制到它,然后 link 那个新的存储桶到我的网站。

我的问题:

  1. 我想知道是否有无需将我的文件复制到新存储桶即可执行此操作的方法?

  2. 如果我只是在文件返回 S3 后更改存储 class,这会阻止它返回 Glacier 吗?

  3. 如果我必须将文件复制到新存储桶,我假设这些副本不会随机返回到 Glacier?

我是 S3 的新手(你可能会从我愚蠢的错误中看出这一点)所以请尽量保持温和

您不需要新的存储桶。您从冰川(临时)恢复对象,然后使用 COPY 操作覆盖它们,这实际上创建了新对象并且它们将保留下来。不用说,你需要禁用你的 aging-away-to-glacier 生命周期。

临时恢复:

aws s3api restore-object --restore-request Days=7 --bucket <bucketName> --key <keyName>

替换为复制的对象:

aws s3 cp s3://bucketName/keyName s3://bucketName/keyName --force-glacier-transfer --storage-class STANDARD

文档说:

The transition of objects to the GLACIER storage class is one-way.

You cannot use a lifecycle configuration rule to convert the storage class of an object from GLACIER to STANDARD or REDUCED_REDUNDANCY storage classes. If you want to change the storage class of an archived object to either STANDARD or REDUCED_REDUNDANCY, you must use the restore operation to make a temporary copy first. Then use the copy operation to overwrite the object as a STANDARD, STANDARD_IA, ONEZONE_IA, or REDUCED_REDUNDANCY object.

Ref.

...going back to Glacier

暂时迂腐,归档对象不会在 s3 和 glacier 之间移动,它们永久在 glacier 中,临时副本是在 S3 中制作的 - 重要的是请注意,当您临时恢复它们时,您需要同时为 glacier 和 s3 付费。一旦您的保留期到期,S3 副本 将被删除。

为了提供完整的答案,我合并了另外两个 SO 帖子:

第一步暂时恢复一切:

  1. 获取存储桶中所有 GLACIER 文件(密钥)的列表(如果您确定所有文件都在 Glacier 中,则可以跳过此步骤)。

    aws s3api list-objects-v2 --bucket <bucketName> --query "Contents[?StorageClass=='GLACIER']" --output text | awk -F '\t' '{print }' > glacier-restore.txt

  2. 创建一个 shell 脚本并 运行 它,替换你的 "bucketName".

    #!/bin/sh
    
    IFS=$'\n'
    for x in `cat glacier-restore.txt`
      do
        echo "Begin restoring ${x}"
        aws s3api restore-object --restore-request Days=7 --bucket <bucketName> --key "${x}"
        echo "Done restoring ${x}"
      done
    

信用Josh & @domenic-d.

永久恢复的第二步:

aws s3 cp s3://mybucket s3://mybucket --force-glacier-transfer --storage-class

大功告成。

感谢@pete-dermott 的评论

我使用以下命令从 Amazon Glacier 存储恢复 S3 对象 class:

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

此处对象的临时副本在恢复请求中指定的持续时间内可用,例如上述命令中使用的 25 天。

如果示例中使用的 JSON 语法导致 Windows 客户端出错,请将还原请求替换为以下语法:

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

注意:这只会为指定对象创建一个临时副本duration.You必须利用复制操作覆盖作为标准对象的对象。

要将对象的存储 class 更改为 Amazon S3 标准,请使用以下命令:

aws s3 cp s3://bucket_name/dir1 s3://bucket_name/dir1 --storage-class STANDARD --recursive --force-glacier-transfer

这将使用 Amazon S3 标准存储递归复制和覆盖现有对象 class。