删除elasticsearch 30天前的所有索引
我的索引格式为
xxx-xxx-xxx-2019.06.27
xxx-xxxx-2019.06.27
脚本思路:
获取目前 es上所有索引,以日期进行拆分,然后用索引时间对比一个月前的日期,日期小于一个月的直接删除
- #!/bin/bash
- # Remove the index of one month old in elasticserch
- CMD_ECHO='echo'
- SCRIPT_NAME=`basename $`
- LOG_PRINT="eval $CMD_ECHO \"[$SCRIPT_NAME]\" @$(date +"%Y%m%d %T") [INFO] :"
- time_ago=
- es_cluster_ip=127.0.0.1
- function delete_index(){
- comp_date=`date -d "${time_ago} day ago" +"%Y-%m-%d"`
- date1="${1} 00:00:00"
- date2="${comp_date} 00:00:00"
- index_date=`date -d "${date1}" +%s`
- limit_date=`date -d "${date2}" +%s`
- if [ $index_date -le $limit_date ];then
- $LOG_PRINT "$1 will perform the delete task earlier than ${time_ago} days ago" >> tmp.txt
- del_date=`echo $ | awk -F "-" '{print $1"."$2"."$3}'`
- curl -XDELETE http://${es_cluster_ip}:9200/*$del_date >> tmp.txt
- fi
- }
- # get the date in all index
- curl -XGET http://${es_cluster_ip}:9200/_cat/indices|awk -F " " '{print $3}' | egrep "[0-9]*\.[0-9]*\.[0-9]*" |awk -F "-" '{print $NF}' | awk -F "." '{print $((NF-2))"-"$((NF-1))"-"$NF}' | sort | uniq | while read LINE
- do
- delete_index ${LINE}
- done
删除elasticsearch 30天前的所有索引的更多相关文章
- 定时删除10天前的Es索引
说明 主要用在索引名为 xxxx-yyyy.MM.dd 这种,可以自定义修改下边的脚本 删除索引shell 创建 delete_es_indices_over_10_day.sh #!/bin/bas ...
- linux自动删除30天前的日志文件
linux应用总结: 自动删除n天前的日志文件: . 使用的命令格式如下: find 对应目录 -mtime +天数 -name "文件名" -exec -rm -rf -name ...
- Linux实现定时备份MySQL数据库并删除30天前的备份文件
1. MySQL5.6以上版本 2. 修改 /etc/my.cnf 文件 # vim /etc/my.cnf [client] host=localhost user=你的数据库用户 password ...
- Windows环境下Oracle数据库的自动备份脚本自动删除30天前的备份
@echo off echo ================================================ echo Windows环境下Oracle数据库的自动备份脚本 echo ...
- Elasticsearch从入门到放弃:索引基本使用方法
前文我们提到,Elasticsearch的数据都存储在索引中,也就是说,索引相当于是MySQL中的数据库.是最基础的概念.今天分享的也是关于索引的一些常用的操作. 创建索引 curl -X PUT & ...
- 自动删除超过30天文件的vbs脚本【转发】
利用代码制作自动删除超过30天的文件及文件夹的vbs脚本,定期清理文件夹中长时间无用文件. 1.首先在新建一个文本文档,粘贴代码(代码可通过添加微信公众号vbs_edit(VBS脚本之家)回复018获 ...
- elasticsearch java和_head插件对索引文档的增删改查
利用head插件: 1,创建索引并添加一条数据(yananindex:索引名称,yanantype:索引类型,1:索引id) 2.修改索引数据(索引id1不变,_version是对该索引数据执行了几次 ...
- ELK学习总结(4-1)elasticsearch更改mapping(不停服务重建索引)
elasticsearch更改mapping(不停服务重建索引)原文 http://donlianli.iteye.com/blog/1924721Elasticsearch的mapping一旦创建, ...
- ElasticSearch入门 第三篇:索引
这是ElasticSearch 2.4 版本系列的第三篇: ElasticSearch入门 第一篇:Windows下安装ElasticSearch ElasticSearch入门 第二篇:集群配置 E ...
随机推荐
- 【CF1225E Rock Is Push】推岩石
题目描述 你现在在一个\(n×m\)的迷宫的左上角(即点\((1,1)\)),你的目标是到达迷宫的右下角(即点\((n,m)\)).一次移动你只能向右或者是向下移动一个单位.比如在点\((x,y)\) ...
- js字符串连接
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> ...
- 矩阵的五种分解的matlab实现
由于这学期修了矩阵分析这门课,课程要求用matlab实现矩阵的5种分解,仅仅是实现了分解,上传到博客存档,万一哪天某位同学就需要了呢.. 1.矩阵的满秩分解 代码实现 %矩阵的满秩分解 clear % ...
- [Gamma]Scrum Meeting#3
github 本次会议项目由PM召开,时间为5月28日晚上10点30分 时长10分钟 任务表格 人员 昨日工作 下一步工作 木鬼 撰写博客,组织例会 撰写博客,组织例会 swoip 前端显示屏幕,翻译 ...
- 为什么需要cookie和session
为什么需要cookie和session 在Web发展史中,我们知道浏览器与服务器间采用的是 http协议,而这种协议是无状态的,所以这就导致了服务器无法知道是谁在浏览网页,但很明显,一些网页需要知 ...
- C++ 中的 inline 用法
1.引入 inline 关键字的原因 在 c/c++ 中,为了解决一些频繁调用的小函数大量消耗栈空间(栈内存)的问题,特别的引入了 inline 修饰符,表示为内联函数. 栈空间就是指放置程序的局部数 ...
- 解析prototxt文件的python库 prototxt-parser(使用parsy自定义文件格式解析)
解析prototxt文件的python库 prototxt-parser https://github.com/yogin16/prototxt_parser https://test.pypi.or ...
- 真机调试No target device的解决(android studio)3.4.1
驱动等都正常,手机连接正常.但是还是报错 搜索到如下办法成功解决:adb未启动或启动失败,这时候选择android studio界面底端的logcat,会自动重启adb.
- 2019t1_sumdoc_list.txt aa.docx acc baidu v2 sbb.docx Acc jindon v2 sbb.docx assetsList.html Atiitt 日本刑法典读后笔记.docx Atiti 遇到说花心的时候赞美应对.docx Atitit lesson.docx Atitit malye主义、mzd思想和dsp理论的区别和联系.docx Ati
2019t1_sumdoc_list.txtaa.docxacc baidu v2 sbb.docxAcc jindon v2 sbb.docxassetsList.htmlAtiitt 日本刑法典读 ...
- shell 备份mysql
shell脚本备份mysql,放在crontab中,可以作为每日测试用数据库备份 #!/bin/bash string_time=`date +%Y%m%d%H%M`; file_path=`date ...