定时清理elasticsearch中的历史数据

定时清理elasticsearch中的历史数据

创建清理脚本

  • 创建脚本目录
mkdir -p /opt/server/cron
  • 创建脚本

    vim delete_elasticsearch_data.sh

#!/bin/bash

his_date=$(date -d "-30 day" +"%Y.%m.%d")

curl -XDELETE "http://localhost:9200/*-$his_date?pretty"

索引名称根据实际情况填写

  • 授予脚本可执行权限
chmod +x delete_elasticsearch_data.sh

创建定时任务

crontab -e命令打开crontab文件

0 0 * * * sh /opt/server/cron/delete_elasticsearch_data.sh > /dev/null 2>&1

写完后保存退出

输入命令:crontab -l 可以查看任务

[root@es1 cron]# crontab -l
0 0 * * * sh /opt/server/cron/delete_elasticsearch_data.sh > /dev/null 2>&1
发布了30 篇原创文章 · 获赞 7 · 访问量 3899

猜你喜欢

转载自blog.csdn.net/huchao_lingo/article/details/103859938
今日推荐