0

大量のレガシー ファイルを含む S3 バケットがあります。バージョン管理をオンにしたばかりで、切り替え後にアップロードされた新しいファイルと比較して、レガシーファイルに対してどのような削除保護が提供されるかを理解しようとしています。サンプルコードは次のとおりです。

import boto
c = boto.connect_s3()
bucket = c.get_bucket('my-bucket')
pfx='myfolder/subfolder/'
i = 0
for k in bucket.list_versions(prefix=pfx):
    if type(k) == boto.s3.deletemarker.DeleteMarker:
        print "DM %s %s" % (k.name, k.version_id)
    else:
        s = k.get_contents_as_string()
        print "REG %s %s %d" % (k.name, k.version_id, len(s))

これにpfxはいくつかのレガシーファイルが含まれているため、これを初めて実行したときは次のようになりました。

REG myfolder/subfolder/ null 0
REG myfolder/subfolder/f1 null 369
REG myfolder/subfolder/f2 null 427
REG myfolder/subfolder/f3 null 141

その後、ツールf2を使用して削除しました。S3Browser上記のコードを再実行すると、次のようになりました。

REG myfolder/subfolder/ null 0
REG myfolder/subfolder/f1 null 369
DM myfolder/subfolder/f2 KPNaxqBeIrCGKUx3tYUsRDwWzKbX06
REG myfolder/subfolder/f2 null 427
REG myfolder/subfolder/f3 null 141

質問: 削除したばかりの (唯一の) バージョンを取得/復元する方法はありf2ますか?

4

2 に答える 2

1

Enabling versioning on a previously-unversioned bucket gives exactly the same deletion protection on existing objects as on new objects, with only one minor difference... and this difference is visible in your output, though it's hard to make sense of, at first.

Each version of a versioned object in versioned buckets has a version id, and when you delete the latest version, it's replaced by a delete marker, which gets a new version id. To access the old version, you access it by its version id, or remove the delete marker. All of this, you already know.

The difference is that when you enable versioning, all of the existing non-versioned objects actually get a version id, and that version id is, literally, "null." Not "null" as in "value is absent" in the three-valued-logic sense, but actually the 4 bytes, n u l l. You can use this version id to access the object the same way you access any versioned object by its key and version id.

于 2015-02-05T01:59:52.340 に答える