#!/bin/bash
# Desc: Close the index 3 days ago and delete the index 30 days ago
# Date: 2022-07-19
# Author: herlly
# Define variables
DEFUALT_ELASTIC_URL=192.168.20.11
DEFUALT_DELETE_DAY=$(date -d "30 days ago" +%Y.%m.%d)
DATE_FORMAT=$(echo "
$(date +"%Y.%m.%d")$
|$(date -d "1 day ago" +"%Y.%m.%d")$
|$(date -d "2 day ago" +"%Y.%m.%d")$
|$(date -d "3 day ago" +"%Y.%m.%d")$
"|sed 's" ""g')
# Index 3 days before closing
INDEX_LIST=$(curl -s -XGET http://${DEFUALT_ELASTIC_URL}:9200/_cat/indices?v| awk '{print $3}' |egrep -v "${DATE_FORMAT}" |egrep -v '.kibana|elastichq' |grep "..*..*\.*[0-9]$")
# echo ${INDEX_LIST}
for index_list in ${INDEX_LIST}
do
curl -s -XPOST http://${DEFUALT_ELASTIC_URL}:9200/${index_list}/_close >/dev/null/ 2>&1
# echo ${index_list}
done
# Delete 30 day old index
curl -XDELETE http://${DEFUALT_ELASTIC_URL}:9200/*-${DEFUALT_DELETE_DAY}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net