定時 清理 elasticsearch 6.5.4 的 索引 文件
阿新 • • 發佈:2018-12-27
rep com name bsp shell time pan delete sin
#!/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 "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
定時 清理 elasticsearch 6.5.4 的 索引 文件