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?

S3 Glacier Deep Archiveをまとめてrestoreする

Last updated at Posted at 2024-08-09

費用をおさえるためとおもって、ファイル資産をS3 Glacier Deep Archiveにクラス変更すると、restoreするのに、バケット毎とか、フォルダ毎ができず、ファイルごとにrestoreリクエストを出さないといけず、コンソール画面からだと、めんどくさすぎたので、shを組んでCLIで一括にリクエストをする。

s3は、バケット毎、フォルダ毎に何かするときに、いちいち手間を感じるので、ある程度は圧縮してファイル数をへらして管理する方が運用工数は減ります。

image.png

(参考 5万ファイル・リクエストで6ドル)

#!/bin/sh

aws s3 ls --profile (profile-name) -recursive  s3://(backet-name)/ | awk '{print $4}' | while read file
do
  echo $file
  aws s3api restore-object --bucket (backetname) --key $file --restore-request '{"Days":14,"GlacierJobParameters":{"Tier":"Standard"}}' --profile  (profile-name)
done

restore がcomeleteしたはずなのに、s3 sync や、 s3 cp --recursive でエラーになるため、同じくスクリプトでaws cp

reita@antares:/mnt/k/mail$ aws s3 sync s3://(backetname)/ /mnt/k/mail/ --recursive --profile=(profile-name)
(backetname)

warning: Skipping file s3://(backetname)/tsutaya/tsutaya201210.txt. Object is of storage class GLACIER. Unable to perform download operations on GLACIER objects. You must restore the object to be able to perform the operation. See aws s3 download help for additional parameter options to ignore or force these transfers.
Completed 0 file(s) with ~0 file(s) remaining (calculatinfatal error:
reita@antares:/mnt/k/mail$ aws s3 sync s3://(backetname)/ /mnt/k/mail/  --profile=(profile-name)

warning: Skipping file s3://(backetname)/$$$sharing.$$$. Object is of storage class GLACIER. Unable to perform download operations on GLACIER objects. You must restore the object to be able to perform the operation. See aws s3 download help for additional parameter options to ignore or force these transfers.

1ファイルごとに、aws cpする。

#!/bin/sh

aws s3 ls --profile (profile-name) --recursive  s3://backetname)/ | awk '{print $4}' | while read file
do
        echo $file
        aws s3 cp s3://backetname)/$file ./$file  --profile tan
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?