LoginSignup
27
23

More than 5 years have passed since last update.

まとめてGlacierからS3に戻すためのワンライナー

Last updated at Posted at 2014-03-11

用途

ライフサイクルの設定でS3からGlacierに移すことは簡単に出来ますが、
逆にGlacierからS3に戻すのは1ファイルずつ行う必要があります。

Glacierファイルがたくさんあると、AWSの管理画面から1つずつ行うのが面倒なので、
まとめて復旧させたい時に使います。

準備

前提として、aws-cli のセットアップと、jqのインストールが完了している必要があります。

コマンド

{バケット名}, {パス} のところを書き換えて実行してください。

$ for key in `aws s3api list-objects --bucket {バケット名} --prefix {パス} --output json | jq -r '.Contents[].Key'`; do echo $key; aws s3api restore-object --bucket {バケット名} --key $key --restore-request '{"Days": 1}'; done

既に設定済みだと以下のようなメッセージが出ます

A client error (RestoreAlreadyInProgress) occurred: Object restore is already in progress

そもそもGlacierじゃない場合、以下のようなメッセージが出ます

A client error (InvalidObjectState) occurred: Restore is not allowed, as object's storage class is not GLACIER

3~5時間待った後

下記コマンド復旧しているかどうか確認します。

$ for key in `aws s3api list-objects --bucket {バケット名} --prefix {パス} --output json | jq -r '.Contents[].Key'`; do echo "\n$key"; aws s3api head-object --bucket {バケット名} --key $key --output json | jq -r .Restore; done

下記のような出力となっていればOKです。
後は普通にS3の操作で取得出来ます。

ongoing-request="false", expiry-date="Thu, 13 Mar 2014 00:00:00 GMT"
27
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
23