美文网首页
自动清理ES索引脚本

自动清理ES索引脚本

作者: Anson前行 | 来源:发表于2018-09-30 10:26 被阅读54次
#/bin/bash

#指定日期(3个月前)
DATA=`date -d "3 month ago" +%Y-%m-%d`

#当前日期
time=`date`

#删除3个月前的日志
curl -XDELETE http://127.0.0.1:9200/*-${DATA}

if [ $? -eq 0 ];then
echo $time"-->del $DATA log success.." >> /data/elk/logs/es-index-clear.log
else
echo $time"-->del $DATA log fail.." >> /tmp/es-index-clear.log
fi

加入crontab 每天检查3个月前的日志并删除

50 23 * * * /bin/bash /data/shell/es-index-clear.sh > /dev/null 2>&1

命令删除12月份的索引

curl -XDELETE http://localhost:9200/*-2017.12*

相关文章

网友评论

      本文标题:自动清理ES索引脚本

      本文链接:https://www.haomeiwen.com/subject/jzoioftx.html