LoginSignup
0
2

More than 1 year has passed since last update.

【AWS CLI】s3 rmでdryrunを使って削除対象を確認

Last updated at Posted at 2022-07-04

S3でファイルを一括で削除したいが必要なファイルは絶対に消したくない!

awscliのs3のrmコマンドで --recursive オプションを使ってファイルを一括削除したいが、includeやexcludeの指定を失敗して削除しては行けないファイルを削除してしまうことを防ぎたいと思いました。

aws s3 rm --recursive s3://example-backet/aiueo/12345/ --include "*foo*" --exclude "*bar*"

例えば上記コマンドを実行したいと思っても本当に削除対象が自分が削除したいものなのかは実行してみないとわかりません。
実行してからファイルの復活はできませんし、削除前にコピーしておいて…とかはよっぽど出ない限りやりたくありません。

--dryrunオプションを使う

そういうときにdryrunオプションを使うと、実行はしないが、実行したかのようなcli上の確認が取れます

Checks whether you have the required permissions for the action,
without actually making the request, and provides an error response.
If you have the required permissions, the error response is DryRun-
Operation . Otherwise, it is UnauthorizedOperation .

なので

aws s3 rm --recursive s3://example-backet/aiueo/12345/ --include "*foo*" --exclude "*bar*" --dryrun

このように実行すると、本当に削除したいファイルが対象かがわかります。
このdryrunはs3に限らないので、他のコマンドも同じように実行が不安であれば試してみるといいと思います。

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