美文网首页程序员
elasticsearch在线迁移备份

elasticsearch在线迁移备份

作者: lyy910203 | 来源:发表于2020-10-20 09:07 被阅读0次

    项目地址: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/

    相关文章

      网友评论

        本文标题:elasticsearch在线迁移备份

        本文链接:https://www.haomeiwen.com/subject/yomrmktx.html