定時清理elasticsearch


索引這種格式

 

 以下腳本加入crontab

#每天清理es數據
0 1 * * * /data/sh/rm_esindex.sh >> /data/logs/crontab/rm_esindex.log 

  

#!/bin/sh

ip='192.168.0.57'
port='9200'
day=`date -d "1 month ago" +%Y.%m.%d`
echo ""
echo `date`
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

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])"`
   if [ -n "$time" ];then   #
        if [ "$time" = "$day" ];then
            echo "Delete $i"
            curl -XDELETE http://$ip:$port/$i
        fi
    fi
done

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM