0
0

More than 3 years have passed since last update.

AWS S3 で複数条件で特定ディレクトリ以下のファイルをコピーするときの exclude & include オプション

Last updated at Posted at 2021-02-16

S3 にあげたログを調査したい時に、一部のログだけを、DLしたい場合があります。
その時に、exclude & include オプションでコピーします。

参考: AWS CLI での高レベル (S3) コマンドの使用::s3 コマンドでよく使用されるオプション
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-services-s3-commands.html#using-s3-commands-managing-objects-param

例: my-bucket/path に保存した Nginx ログの中から、特定の月(YYYY-MM)のログファイルを今のディレクトリにコピーしたい場合

ターミナルだと

$ cp /var/log/nginx/access_log_YYYY-MM-*.gz ./

とかシンプルに条件をつけられますが、S3 の CLI は単純なワイルドカードが使えないようです。

Nginx ログは access_log_[YYYY]-[MM]-[DD].gz と言うフォーマットで保存されているとする。

$ aws s3 cp s3://my-bucket/path  ./ --recursive --exclude "*.gz"--include "access_log_YYYY-MM-*.gz"

これで、SSH の例文のようなアクションを起こすことができます。

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