0

I have versioning enabled in my S3 bucket, how do I restore a deleted file with a command line S3 client, such as s3cmd? How do I browse the different versions of the files? So far, I have regressed to Freeware Cloudberry Windows Client to achieve this. I know I could use also Boto Python library, but I would prefer a common command line tool.

John Mayor
  • 577
  • 6
  • 13

2 Answers2

2

s3cmd 1.5.0-rc1 has very little support for versioned files at this point. I believe it can do a full bucket delete, including versioned files, but that's the extent of its support for versioned files.

Matt Domsch
  • 486
  • 2
  • 5
1

Use this AWS CLI command: (docs here):

aws s3api list-object-versions --bucket mybucket

This returns the list of objects, eg.:

{
    "DeleteMarkers": [
        ...
    ],
    "Versions": [
        {
            "LastModified": "2015-11-17T12:25:01.000Z",
            "VersionId": "Mj1.PcWG8e.C._7LhvFU131pXJ98abIl",
            "ETag": "\"b76b2b775023e60be16bc332496f8409\"",
            "StorageClass": "STANDARD",
            "Key": "file1.txt",
            "Owner": {
                "DisplayName": "aws03005",
                "ID": "b09   0e41acbdf98bc34ef4781f10e4aeebb7a495b8be78da0db884af2980ed38d"
            },
            "IsLatest": true,
            "Size": 30318
        },
    ...
}

Use Key (file name) and VersionId to download a previous version:

aws s3api get-object --bucket mybucket --key file1.txt --version-id Mj1.PcWG8e.C._7LhvFU131pXJ98abIl foo.txt

If you are trying to get a deleted file, please note that you have to get-object the latest version listed in Versions, not the one listed in DeleteMarkers.

To do this in a script, --query and/or jq might help.

tuomassalo
  • 8,717
  • 6
  • 48
  • 50
  • You are right, better approach is to use the [official tool developed by Amazon](https://aws.amazon.com/cli/). The development of [s3cmd](https://sourceforge.net/projects/s3tools/files/s3cmd/) seems to have dried up anyway. – John Mayor Oct 10 '16 at 18:50