LoginSignup
2
1

More than 5 years have passed since last update.

3ヶ月前のElasticsearchのログを自動で削除

Posted at

Elasticsearchのログを以前は手作業で定期的に削除していたが
スクリプトにしてcronで自動実行するように変更

ログの名前を
item名-日付としている(例.item1-2017.01.10)ため
item名-(90日前の日付)をcurlコマンドで削除

#!/bin/bash

items=(
    "item1"
    "item2"
    "item3"
    "item4"
    "item5"
    "item6"
)

DATE=`date +"%Y.%m.%d" --date="90 days ago"`

for item in "${items[@]}" ; do
    INDEX=$item-$DATE
    echo $INDEX
    curl -XDELETE http://localhost:9200/$INDEX
    echo -e "\n"
done

これで90日前のログを自動で削除する

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