自动清理ES索引脚本

#/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*
posted @ 2019-08-27 18:03  哈喽哈喽111111  阅读(1019)  评论(0编辑  收藏  举报