简体   繁体   English

如何使用 python 将对象从 amazon glacier 永久恢复到 s3 存储桶中的标准层?

[英]How to restore objects from amazon glacier to standard tier permanently in a s3 bucket using python?

I am trying to restore some objects in a s3 bucket from glacier to standard tier permanently below is my code我正在尝试将 s3 存储桶中的一些对象从冰川恢复到标准层,下面是我的代码

def restoreObject(latest_object):
    #s3_resource=boto3.resource('s3')
    s3 = boto3.client('s3')
    my_bucket = s3.Bucket('bucket_name')
    for bucket_object in my_bucket.objects.all():
        object_key=bucket_object.key  
        if(bucket_object.storage_class == "Glacier_Deep_Archive"):
            if object_key in latest_object:
                my_bucket.restore_object(Bucket="bucket_name",Key=object_key,RestoreRequest={'Days': 30,'Tier': 'Standard'})

But this restores the bundle for a particular time only (30 days in my case) Is there a way to restore bundles permanently from Glacier_Deep_Archive to standard tier?但这只会在特定时间恢复捆绑包(在我的情况下为 30 天)有没有办法将捆绑包从 Glacier_Deep_Archive 永久恢复到标准层?

To permanently change the Storage Class of an object in Amazon S3, either:永久更改Amazon S3 中 object 的存储 Class,可以:

However, Lifecycle policies do not seem to support going from Glacier to Standard tiers.但是,生命周期策略似乎支持从 Glacier 升级到标准层。

Therefore, you would need to copy the object to itself to change the storage class:因此,您需要将 object 复制到自身以更改存储 class:

  copy_source = {'Bucket': 'bucket_name', 'Key': object_key}
  my_bucket.copy(copy_source, object_key, ExtraArgs = {'StorageClass': 'STANDARD','MetadataDirective': 'COPY'})

Here's a nice example: aws s3 bucket change storage class by object size · GitHub这是一个很好的例子: aws s3 bucket change storage class by object size · GitHub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将文件夹(或整个存储桶)从 Glacier 恢复到 Amazon S3? - How to restore folders (or entire buckets) to Amazon S3 from Glacier? 如何使用 cURL 从 Amazon S3 存储桶中删除文件 - How to delete a file from amazon S3 bucket using cURL 如何从 amazon s3 存储桶中删除文件? - how to delete files from amazon s3 bucket? 如何使用 python 列出 S3 存储桶文件夹中的文件 - how to list files from a S3 bucket folder using python 亚马逊 s3 将桶与桶策略 - Amazon s3 put bucket with bucket policy 如何使用 postdata preSigned Url 调用 Amazon S3 存储桶以使用空手道上传文件 - How to call Amazon S3 bucket using postdata preSigned Url to upload a file using Karate 使用 Node.js Vue.js 在前端显示来自 Amazon S3 私有存储桶的图像 - Show images from Amazon S3 private bucket in frontend using Node js Vue js 使用 Java (Amazon S3) 将 all.txt 文件从一个 object 复制到另一个但在同一个存储桶中 - Copy all .txt files from one object to another but in the same bucket using Java (Amazon S3) 如何使用 Python 中的 Pandas 从 s3 存储桶中读取 csv 文件 - How to read a csv file from an s3 bucket using Pandas in Python 从 Angular 应用程序将图像上传到 Amazon S3 Bucket 时出现问题 - Issue with uploading Image to Amazon S3 Bucket from Angular app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM