elasticsearch 인덱스 제2판 삭제

1323 단어
이 버전은 이전 버전에 대해 업그레이드되었습니다.호환성이 더욱 좋아졌다.
#!/bin/bash
#######################################################
# $Name:        clean_index.sh
# $Version:     v2.0
# $Function:    delete es index
# $Author:      dongjiaxiao
# $Create Date: 2019-12-31
# $Description: shell
######################################################
# 
CLEAN_LOG="/home/djx/scripts/clean_index.log"
#es 
SERVER_PORT=172.17.1.212:9200
# , 
DELTIME=45
SECONDS=$(date -d  "$(date  +%F) -${DELTIME} days" +%s)
INDEXS=$(curl -s -u  elastic:changeme  "${SERVER_PORT}/_cat/indices?v"|awk '{print $3}')
echo "-------------------$(date +%F_%T)---------------"  >>${CLEAN_LOG}
for del_index in ${INDEXS}
do 
     timeString=$( echo ${del_index} |awk -F"-" '{print $NF}'|egrep "[0-9]*\.[0-9]*\.[0-9]*")
     if [ -n "$timeString" ]
     then
         indexDate=${timeString//./-}
         indexSecond=$( date -d ${indexDate} +%s )
         if [ $(( $SECONDS- $indexSecond )) -gt 0 ]
         then
             delResult=`curl -s -u elastic:changeme  -XDELETE "${SERVER_PORT}/"${del_index}"?pretty" |sed -n '2p'`
             echo "delete index:$del_index result:$delResult" >>${CLEAN_LOG}
         fi
     fi
     
done 

좋은 웹페이지 즐겨찾기