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

首頁 > 開發(fā) > Linux Shell > 正文

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

2020-07-27 18:45:39
字體:
供稿:網(wǎng)友

發(fā)現(xiàn)elasticsearch集群的狀態(tài)是red,unassign的分片數(shù)很多,看了下都是些舊的日期的索引(應(yīng)該是定時(shí)任務(wù)刪除失敗導(dǎo)致的)。

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

數(shù)量有幾百個(gè),寫個(gè)腳本處理下,先恢復(fù)成green。red狀態(tài)好像會(huì)影響索引創(chuàng)建和數(shù)據(jù)遷移

先把需要?jiǎng)h除的索引導(dǎo)出到文件

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

確認(rèn)下要?jiǎng)h除的索引列表。沒問題就執(zhí)行下面刪除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

因?yàn)槲覀兊乃饕前刺靹?chuàng)建的,索引名前綴是yyyy-MM-dd, 保留一段時(shí)間后需要批量刪除。shell的第一個(gè)參數(shù)為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

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)武林網(wǎng)的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 子洲县| 大石桥市| 兖州市| 将乐县| 祁阳县| 怀柔区| 黑龙江省| 潜江市| 开化县| 江口县| 梓潼县| 石景山区| 茌平县| 嘉鱼县| 锡林浩特市| 永靖县| 连南| 日土县| 柳江县| 安义县| 斗六市| 上林县| 同心县| 汝州市| 江孜县| 云林县| 新源县| 繁昌县| 吉首市| 聊城市| 潮安县| 景洪市| 洞口县| 晋江市| 连南| 鲁甸县| 呼伦贝尔市| 甘泉县| 惠水县| 锡林浩特市| 台北市|