定时 清理 elasticsearch 6.5.4 的 索引 文件

时间:2023-03-08 22:50:55
定时 清理 elasticsearch 6.5.4 的 索引 文件
#!/bin/sh

ip='127.0.0.1'
port='' 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 ];then
echo "Connect $ip:$port error...."
else
echo "Connect $ip:$port Sucess,loading index ..."
fi length=${#indexname[@]}
if [[ -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数据
* * * /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