国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

shell腳本批量刪除es索引的方法

2019-10-26 18:59:01
字體:
來源:轉載
供稿:網友

發現elasticsearch集群的狀態是red,unassign的分片數很多,看了下都是些舊的日期的索引(應該是定時任務刪除失敗導致的)。

curl -XGET ip:port/_cat/shards | grep UNASSIGNED

數量有幾百個,寫個腳本處理下,先恢復成green。red狀態好像會影響索引創建和數據遷移

先把需要刪除的索引導出到文件

curl -XGET ip:port/_cat/shards | grep UNASSIGNED >> needDelIndex.txt

確認下要刪除的索引列表。沒問題就執行下面刪除shell(es的ip和端口需要修改下)

#!/bin/bashecho "$1"esUrl=${esip}:${esport}indexfile=needDelIndex.txt#cp -f /dev/null ${indexfile}#curl -XGET ip:port/_cat/shards | grep UNASSIGNED >> needDelIndex.txtif [ ! -f ./${indexfile} ]; then  echo $indexfile not exists  exit 0filogfile=esindex_del.`date +"%m-%d"`.logcp -f /dev/null ${logfile}lastIndexName="test"for item in `cat ${indexfile} | awk '{print $1}'`do  if [ "$item" = "error" ]  then    continue  fi  if [ "$item" != "$lastIndexName" ]  then    curl -XDELETE ${esUrl}/${item} >> ${logfile}    echo ---------${item} `date` >> ${logfile}    sleep 5  fi  lastIndexName=${item}done

因為我們的索引是按天創建的,索引名前綴是yyyy-MM-dd, 保留一段時間后需要批量刪除。shell的第一個參數為yyyy-MM-dd,將刪除該天及以前的舊索引

#!/bin/bashesUrl=${esip}:${esport}echo "$1"if [ $# -ge 1 ]then  deleteDate=$1else  echo "please inpust detete esindex's date(yyyy-MM-dd)"  exit 0fiindexfile=esindex.infocp -f /dev/null ${indexfile}curl '${esUrl}/_cat/indices' >> ${indexfile}logfile=esindex_del.`date +"%m-%d"`.outcp -f /dev/null ${logfile}for item in `cat ${indexfile} | awk '{print $3}'`do  if [ "$item" = "error" ]  then    continue  fi  parameter=${esUrl}/${item}  indexdate=${item:0:10}  if [ "$indexdate" = "$deleteDate" ]  then    curl -XDELETE ${parameter} >> ${logfile}    echo ---------${item} >> ${logfile}    sleep 5  elif [[ "$indexdate" < "$deleteDate" ]]  then    curl -XDELETE ${parameter} >> ${logfile}    echo ---------${item} >> ${logfile}    sleep 5  fidone

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林站長站的支持。如果你想了解更多相關內容請查看下面相關鏈接

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 三门峡市| 普兰县| 长顺县| 麻江县| 凌云县| 清远市| 桦南县| 六枝特区| 蒲城县| 介休市| 遵义市| 淮北市| 高尔夫| 息烽县| 贺兰县| 遂溪县| 庆城县| 利辛县| 威宁| 潞西市| 大竹县| 依兰县| 定州市| 沈丘县| 白水县| 榆林市| 辰溪县| 绵阳市| 襄城县| 海阳市| 四平市| 商都县| 四子王旗| 嘉义市| 和政县| 中卫市| 松阳县| 团风县| 镇巴县| 屯门区| 镇安县|