定时 清理 elasticsearch 6.5.4 的 索引 文件

 

#!/bin/sh

ip='127.0.0.1'
port='9200'

day=`date -d "2 days ago" +%Y%m%d`
#day=`date -d "5 hour ago" +%Y.%m.%d`

echo ""
echo "================================================="
echo `date +"%Y-%m-%d %H:%M.%S"`

indexname=`curl -XGET -s $ip:$port/_cat/indices|awk '{print $3}'`
if [ $? -ne 0 ];then
    echo "Connect $ip:$port error...."
else
    echo "Connect $ip:$port Sucess,loading index ..."
fi

length=${#indexname[@]}
if [[ 0 -eq "$lenqth" ]];then
    echo "Nothings to do!"
fi

for i in $indexname
do
    time=`echo $i|awk -F"-" '{print $NF}'|egrep "([0-9][0-9][0-9][0-9]).(0[1-9]|[1][0-2]).(0[1-9]|[1-2][0-9]|3[0-1])"`
    time=${time//./}

    if [ -n "$time" ];then
        if [ "$time" -lt "$day" ];then
            echo ""
            echo "Delete $i"
            curl -XDELETE http://$ip:$port/$i
        fi
    fi
done

echo ""

 

以上脚本加入crontab

#每天清理es数据
0 1 * * * /data/shell/rm_esindex.sh >> /data/logs/rm_esindex.log

 

 

PS:

https://www.cnblogs.com/shiyiwen/p/8311014.html

https://www.cnblogs.com/yxwkf/p/5196016.html

 

posted @ 2018-12-26 22:58  phpdragon  阅读(733)  评论(0编辑  收藏  举报