Help us understand the problem. What is going on with this article?

S3でDeleteMarkerの付いたファイルを取得する

More than 3 years have passed since last update.

S3のVersioningを有効にしていると,aws s3 rmとかやっても実体は削除されておらず,削除済みという目印(DeleteMarker)が付いた状態になります.

この状態で当該ファイルを取ろうとしても

uraura@rosemary$ aws s3api get-object --bucket target-bucket --key db.dump.gz ./db.dump.gz

A client error (NoSuchKey) occurred when calling the GetObject operation: The specified key does not exist.

と,悲しい思いをします.(まぁ削除したんだから当然ですね...)

そこで,DeleteMarkersの付いてないバージョンを調べます.

uraura@rosemary$ aws s3api list-object-versions --bucket target-bucket --prefix db.dump.gz
{
    "DeleteMarkers": [
        {
            "Owner": {
                "DisplayName": "admin",
                "ID": "87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7"
            },
            "IsLatest": true,
            "VersionId": "uZALiONs1lXzsJBvjv.jgnLSdBrHfCox",
            "Key": "db.dump.gz",
            "LastModified": "2015-10-30T17:55:38.000Z"
        }
    ],
    "CommonPrefixes": [],
    "Versions": [
        {
            "LastModified": "2015-09-30T17:55:30.000Z",
            "VersionId": "b8O0kCjQYrPvtMNXTGRayqRe.U11dxzx",
            "ETag": "\"712fe04afa2e31dee3583dc6586bf74a-11\"",
            "StorageClass": "STANDARD",
            "Key": "db.dump.gz",
            "Owner": {
                "DisplayName": "admin",
                "ID": "87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7"
            },
            "IsLatest": false,
            "Size": 80885743
        }
    ]
}

この場合は"VersionId": "b8O0kCjQYrPvtMNXTGRayqRe.U11dxzx"でよさそうですのでバージョンまで指定して呼びだしてやりましょう.

uraura@rosemary$ aws s3api get-object --bucket target-bucket --key db.dump.gz --version-id b8O0kCjQYrPvtMNXTGRayqRe.U11dxzx ./db.dump.gz
{
    "AcceptRanges": "bytes",
    "ContentType": "binary/octet-stream",
    "LastModified": "Wed, 30 Sep 2015 17:55:30 GMT",
    "ContentLength": 80885743,
    "VersionId": "b8O0kCjQYrPvtMNXTGRayqRe.U11dxzx",
    "ETag": "\"712fe04afa2e31dee3583dc6586bf74a-11\"",
    "Metadata": {}
}

まとめ

aws s3apiってあんまり使ってなかったけど便利やん

cluster-inc
clusterは、誰でも手軽にバーチャルイベントに参加したり、開催したりすることができるサービスを運営するスタートアップです。利用用途はあなた次第。音楽ライブやミーティングなど、様々な「集まるシチュエーション」に活用可能です。
https://cluster.mu
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした