最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2019年03月15日 08:32:40   作者:Scub  
今天小編就為大家分享一篇關(guān)于shell腳本批量刪除es索引的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

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

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

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

先把需要刪除的索引導(dǎo)出到文件

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

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

#!/bin/bash
echo "$1"
esUrl=${esip}:${esport}
indexfile=needDelIndex.txt
#cp -f /dev/null ${indexfile}
#curl -XGET ip:port/_cat/shards | grep UNASSIGNED >> needDelIndex.txt
if [ ! -f ./${indexfile} ]; then
  echo $indexfile not exists
  exit 0
fi
logfile=esindex_del.`date +"%m-%d"`.log
cp -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

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

#!/bin/bash
esUrl=${esip}:${esport}
echo "$1"
if [ $# -ge 1 ]
then
  deleteDate=$1
else
  echo "please inpust detete esindex's date(yyyy-MM-dd)"
  exit 0
fi
indexfile=esindex.info
cp -f /dev/null ${indexfile}
curl '${esUrl}/_cat/indices' >> ${indexfile}
logfile=esindex_del.`date +"%m-%d"`.out
cp -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
  fi
done

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

相關(guān)文章

最新評論

宁化县| 广南县| 廊坊市| 雅江县| 铜梁县| 邵阳市| 昭觉县| 威海市| 莎车县| 吴川市| 莫力| 莲花县| 大理市| 普兰店市| 金秀| 涞源县| 宣恩县| 长武县| 辽宁省| 昭平县| 平乐县| 永靖县| 上犹县| 林州市| 西平县| 柘荣县| 昔阳县| 阿拉善右旗| 绩溪县| 永吉县| 中西区| 自贡市| 竹北市| 常宁市| 长治县| 界首市| 迭部县| 隆回县| 博白县| 确山县| 沛县|