es索引定期删除脚本
#/bin/bash
#指定日期(30天前)
Clear_Time=`date -d "30 days ago" +%Y.%m.%d`
Today=`date`
#拿到15天以前的索引,输出到以15天为时间命名的文件中 如:index.2021.10.12
curl -s -XGET -u elastic:t1Nc9SSHBiFOQK01R44l 'http://172.16.30.247:9200/_cat/indices' |awk '{print $3}'|grep $Clear_Time > /opt/clear_index/index.$Clear_Time
#声明清理动作 (最终会在crontab定义的/opt/ES_Timing_Clear/es_clear.log日志中看到操作)
echo "In $Today start to clear "$Clear_Time" 's old indices>>>>>>>>"
#对新输出到index文件内的索引 进行删除
for i in `cat /opt/clear_index/index.$Clear_Time`
do
sleep 3
curl -s -XDELETE -u elastic:xxxxx http://172.16.30.247:9200/$i
done
echo "======================="
echo "清理完成"
echo "======================="
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
上次更新: 2023/04/21, 08:57:47