elasticsearch在線遷移備份

項目地址:https://github.com/elasticsearch-dump/elasticsearch-dump

1.安裝nodejs (略)
2.安裝elasticdump (注意需要將node的bin目錄放置在PATH中)
npm install elasticdump -g
3.遷移數據
elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=settings
elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=analyzer
elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=mapping
elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=data

####備註###########
S_ES: 源ES
D_ES: 目標ES
index:索引名
遷移整個集羣腳本示例
#!/bin/bash
S_ES="https://search-hifive-open-test-pnmiylftgjjccopkfeowpo7yue.cn-northwest-1.es.amazonaws.com.cn"

D_ES="http://172.27.29.137:9200"
for index in `curl -s $S_ES/_cat/indices|cut -d " " -f 3`;do
    echo $index
    elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=settings
    elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=analyzer
    elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=mapping
    elasticdump --input=$S_ES/$index --output=$D_ES/$index --type=data
done

刪除ES所有索引
#!/bin/bash

ES_HOST="http://172.27.29.137:9200"

read -p "刪除數據不可逆,確定Y/N:" action
case $action in
    "Y" | "y")
        curl -s $ES_HOST/_cat/indices |awk '{print $3}' |grep -v kibana |xargs -i curl -XDELETE $ES_HOST/{}
        ;;
    "N" | "n")
        echo "no"
        ;;
    *)
        echo "識別Y N失敗"
esac


我的技術站
https://www.iyunw.cn/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章