记elasticdump 备份数据导出导入

原创
2018/07/16 16:39
阅读数 9.6K

版本:

elasticsearch 5.5.2

elasticdump 2.2

系统 CentOS7.3

因项目需求 从生产导出一份索引到测试

帮助文档 https://github.com/taskrabbit/elasticsearch-dump?utm_source=dbweekly&utm_medium=email

安装 yum install elasticdump

elasticdump --input=http://localhost:9200 --output=abc.json --type=data Sun, 25 Sep 2016 13:07:15 GMT | starting dump Sun, 25 Sep 2016 13:07:15 GMT | Error Emitted => {"error":{"root_cause":[{"type":"parsing_exception","reason":"The field [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored","line":1,"col":36}],"type":"parsing_exception","reason":"The field [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored","line":1,"col":36},"status":400} Sun, 25 Sep 2016 13:07:15 GMT | Total Writes: 0 Sun, 25 Sep 2016 13:07:15 GMT | dump ended with error (get phase) => Error: {"error":{"root_cause":[{"type":"parsing_exception","reason":"The field [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored","line":1,"col":36}],"type":"parsing_exception","reason":"The field [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored","line":1,"col":36},"status":400}

As a workaround, the following works:

elasticdump --input=http://9.11.8.51:9200/apm --output=apm.json --type=data --searchBody '{"query": { "match_all": {} }, "stored_fields": ["*"], "_source": true }'

elasticdump --input=apm.json --output=http://9.1.8.234:9200/apm --type=data --searchBody '{"query": { "match_all": {} }, "stored_fields": ["*"], "_source": true }'

elasticdump --input=http://9.11.8.52:9200/metric --output=/data/metric.json --type=data --limit=1000 --searchBody '{"query":{"term":{"timestamp": "2018-09-28"}}}' https://github.com/taskrabbit/elasticsearch-dump

 

按时间导出 先导出mapping 在导出数据

#导出mapping
elasticdump --input="http://9.11.8.52:9200/database" --output=/tmp/database/database__mapping.json --type=mapping

#在导出数据  导出7月28号数据
elasticdump   --input=http://9.11.8.52:9200/database --output=/tmp/database/database.json --type=data --limit=1000 --searchBody '{"query":{"term":{"timestamp": "2019-07-28"}}}'

导入

先创建索引

导入mapping

root@ *node* @node3:/root/database# elasticdump --input /root/database/database__mapping.json --output http://9.1.8.234:9200/database --type=mapping
Mon, 29 Jul 2019 09:12:24 GMT | starting dump
Mon, 29 Jul 2019 09:12:24 GMT | got 1 objects from source file (offset: 0)
Mon, 29 Jul 2019 09:12:24 GMT | sent 1 objects to destination elasticsearch, wrote 5
Mon, 29 Jul 2019 09:12:24 GMT | got 0 objects from source file (offset: 1)
Mon, 29 Jul 2019 09:12:24 GMT | Total Writes: 5
Mon, 29 Jul 2019 09:12:24 GMT | dump complete

查看mapping

导入数据

elasticdump --input /root/database/database.json --output http://9.1.8.234:9200/database --type=data --limit=1000

查看数据

elasticdump --input=http://9.11.8.52:9200/metric --output=http://8.10.201.37:9200/metric --type=data --limit=5000 --searchBody '{"query":{"bool":{"must":[{"range":{"timestamp":{"gt":"2019-09-01T00:00:00.000+0800","lt":"2019-10-01T00:00:00.000+0800"}}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"aggs":{}}'

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部