如何在带有Boto3的S3中使用版本控制? [英] How can I use versioning in S3 with boto3?

查看:59
本文介绍了如何在带有Boto3的S3中使用版本控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有boto3的版本化S3存储桶.如何检索给定密钥的所有版本(甚至所有密钥的所有版本)?我可以这样做:

I am using a versioned S3 bucket, with boto3. How can I retrieve all versions for a given key (or even all versions for all keys) ? I can do this:

for os in b.objects.filter(Prefix=pref):
    print("os.key")

但是每个键只有最新版本.

but that gives me only the most recent version for each key.

非常感谢,

推荐答案

import boto3

bucket = 'bucket name'
key = 'key'
s3 = boto3.resource('s3')
versions = s3.Bucket(bucket).object_versions.filter(Prefix=key)

for version in versions:
    obj = version.get()
    print(obj.get('VersionId'), obj.get('ContentLength'), obj.get('LastModified'))

我无法回答,因为我有同样的问题,但是我发现了这个

I can't take credit as I had the same question but I found this here

这篇关于如何在带有Boto3的S3中使用版本控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆