【问题标题】:How do I download all the versions of a file with 100,000+ versions from Amazon S3?如何从 Amazon S3 下载具有 100,000 多个版本的文件的所有版本?
【发布时间】:2015-12-04 08:27:30
【问题描述】:

我在 Windows 上使用 AWS 命令​​行,到目前为止我发现的所有方法似乎都表明我需要获取所有对象的版本 ID 列表。有没有像 * 这样的通配符可以使用?

【问题讨论】:

  • 这是一次性需求(jamod 建议使用 Cloudberry Explorer 之类的工具更好),还是重复需求(需要脚本/编程)?您将如何处理 100,000 多个版本的文件?您可以提供的任何额外信息都将帮助我们提供有用的答案。
  • @JohnRotenstein 我正在运行暗物质模拟,每个时间步长对应一个新版本的文件。一次性下载是我想要做的。

标签: amazon-web-services amazon-s3 versioning versions


【解决方案1】:

使用 Boto3,John 的解决方案需要更新如下。我正在使用修改后的 ts 保存文件。

import boto3
client = boto3.client('s3')

_bucket = '<s3Bucket>'
_file   = '<fileName>'
_key    = '<the s3 prefix>' + _file
_local  = '<local path>' + _file

response = client.list_object_versions(
    Bucket=_bucket,
    Prefix=_key
)

for v in response['Versions']:
    client.download_file(_bucket, _key,
                         _local + '_' + v['LastModified'].strftime('%Y%m%d%H%M%S'),
                         ExtraArgs={"VersionId": v["VersionId"]})
    print(v['LastModified'])

【讨论】:

    【解决方案2】:

    此 Python 代码使用 boto 将下载在存储桶中找到的所有文件版本。大量版本可能需要对结果集进行分页。

    import boto
    conn = boto.connect_s3()
    bucket = conn.get_bucket('BUCKET')
    
    # Get a list of all versions contained in the bucket
    versions = bucket.list_versions(prefix='FILENAME')
    
    for v in versions:
      # Save the version to a filename based on the Last Modified date
      v.get_contents_to_filename(v.last_modified)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 1970-01-01
      • 2018-02-22
      • 2015-08-14
      相关资源
      最近更新 更多