amazon-web-servicesamazon-s3versioningversions

How do I download all the versions of a file with 100,000+ versions from Amazon S3?


I'm using the AWS command line on Windows and all methods I have found till now seem to suggest I need to get a list of version-ids for all the objects. Is there some sort of wildcard like * that I can use?


Solution

  • This Python code using boto will download all versions of files found in a bucket. It's possible that a large number of versions will require paging through the result set.

    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)