elasticdump:es批量索引迁移心得

目录

1.方法介绍

1.1一行代码看懂用法

1.2导出源数据的 settings、mapping 、data

1.3将导出的数据文件导入至目标索引

1.4从数据源直接导入到目标集群


1.方法介绍

1.1一行代码看懂用法

elasticdump --input <源数据> --output <目标数据> --type=<数据类型>

1.2导出源数据的 settings、mapping 、data

1.2.1:导出源数据索引的 settings文件

elasticdump --input http://账号:密码@localhost:9213/test_index 
--output /Users/wu/Desktop/test_index_settings.json --type=settings

2:导出源数据索引的 mapping文件

elasticdump --input http://账号:密码@localhost:9213/test_index 
--output /Users/wu/Desktop/test_index_mapping.json --type=mapping

3:导出源数据索引的 data文件

elasticdump --input http://账号:密码@localhost:9213/test_index 
--output /Users/wu/Desktop/test_index.json --type=data

1.3将导出的数据文件导入至目标索引

1:导入 settings 至目标索引

elasticdump --input /Users/wu/Desktop/test_index_mapping.json 
--output http://账号:密码@localhost:9200/ --type=settings

2:导入mapping至目标索引

elasticdump --input /Users/wu/Desktop/test_index_mapping.json
--output http://localhost:9200/ --type=mapping

3:导入data至目标索引

elasticdump --input /Users/wu/Desktop/test_index_mapping.json 
--output http://账号:密码@localhost:9200/ --type=data

1.4从数据源直接导入到目标集群

1:迁移settings

elasticdump --input http://账号:密码@localhost:9213/test_index 
--output http://账号:密码@localhost:9200/ --type=settings

2:迁移mapping

elasticdump --input http://账号:密码@localhost:9213/test_index 
--output http://账号:密码@localhost:9200/ --type=mapping

3:迁移data

elasticdump --input http://账号:密码@localhost:9213/test_index 
--output http://账号:密码@localhost:9200/ --type=data

1.5elasticdump导入导出批量索引

事情是这样的,一开始使用正常到elasticdump导入索引。命令如下:

elasticdump --input http://账号:密码@localhost:9213/test_index 
--output http://账号:密码@localhost:9200/

索引导入了一部分报错。504 Gateway Time-out错误。无法继续导入,es库查询也很有问题。应该是压力过大导致。

然后通过正常elasticdump导入导出单个索引,通过shell命令去循环遍历原库所有索引进行操作。

#! /bin/bash

#txt_sy=`cat /opt/es_data/ba/abcd |awk -F 'log-' '{print $2}' |awk -F ' ' '{print $1}' |tr -s '\n'|awk -F '.' '{print $1}'`
txt_sy=`cat /opt/es_data/ba/abc`
for sy in $txt_sy ; do


elasticdump --limit=10000 --type=settings  --input=http://admin:aLi_esPassadm356@elasticsearch.20191217074602572gtsj6s1.cn-langfang-mps22s-d01-inner.odps.ops.yun.ga:9200/idx_bus_request_service_log-$sy --output=http://elastic:aLi_esPassadm356@gxpt.kexinju-shehuichu-gxpt.ops.yun.ga:9200/idx_bus_request_service_log-$sy 

elasticdump --limit=10000 --type=mapping --input=http://admin:aLi_esPassadm356@elasticsearch.20191217074602572gtsj6s1.cn-langfang-mps22s-d01-inner.odps.ops.yun.ga:9200/idx_bus_request_service_log-$sy --output=http://elastic:aLi_esPassadm356@gxpt.kexinju-shehuichu-gxpt.ops.yun.ga:9200/idx_bus_request_service_log-$sy 


elasticdump --limit=1000 --input=http://admin:aLi_esPassadm356@elasticsearch.20191217074602572gtsj6s1.cn-langfang-mps22s-d01-inner.odps.ops.yun.ga:9200/idx_bus_request_service_log-$sy --type=data --output=http://elastic:aLi_esPassadm356@gxpt.kexinju-shehuichu-gxpt.ops.yun.ga:9200/idx_bus_request_service_log-$sy 

done

注:--type=settings 不要写在变量后面。否则有问题

abc文件内容

2020-12-31
2021-01-02
2021-01-03
2021-01-04
2021-01-05
2021-01-06
2021-01-07
2021-01-08
2021-01-09
2021-01-10
2021-01-11
2021-01-12
2021-01-13
2021-01-14
2021-01-15
2021-01-16
2021-01-17
2021-01-18

注:abc文件里面内容一般会用 /R或者/WR这些,使用如下图命令进行转换。具体介绍

批量将目录下所有文件进行 dos/unix 格式转换_LeocenaY的博客-CSDN博客_set ff=dos

vim 文件
:set ff=uninx

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值