0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS CLIでS3 Glacierのオブジェクトを日付指定して一括で復元する

Last updated at Posted at 2025-03-27

コマンド

aws s3api list-objects-v2 \
  --bucket <bucket_name> \
  --prefix <prefix> \
  --query 'Contents[?(LastModified >= `開始日時` && LastModified <= `終了日時` && StorageClass==`ストレージクラス`)].[Key]' \
  --output text | \
  xargs -I {} sh -c \
  "aws s3api restore-object --bucket <bucket_name> --key \"{}\" --restore-request Days=5,GlacierJobParameters={Tier=Standard} || true"

使い方

  • 開始日時, 終了日時2025-01-01, 2025-01-01T10:00:00, 2025-01-01T10:00:00+00:00のようにISO 8601形式のUTCで記述
  • <bucket_name>を対象のバケット名で置き換え
  • <prefix>を対象のオブジェクトで共通のプレフィックスで置き換える
  • ストレージクラスを対象オブジェクトに合わせてGLACIERまたはDEEP_ARCHIVEに置き換える
  • Days=5, Tier=Standardも適宜変えてください

解説

Tier (BulkとStandard)

違いはトレードオフになっている復元の料金と時間です。

  • Standard (デフォルト)
  • Bulk
    • ペタバイト級のデータを安く復元させるユースケースで使います
    • 最大48時間かかりますが、Standardに比べて8割ほど安いです

--queryで使うJMESPath

リファレンスを見る限り、文字列で解釈されるLastModifiedで順序演算子(>, <など)を使うと結果はnullになると書いてますが、動作確認する限りはちゃんと使えていました。

JMESPathとか詳しくなりたくないので、よく分からないです :stuck_out_tongue:

一応、AWS CLI v2ユーザーガイドでも別のケースで日付をフィルターする例が紹介されています。

指定した作成日より後のスナップショットを表示するには - AWS Command Line Interface バージョン 2 用ユーザーガイド Filtering output in the AWS CLI

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?