【发布时间】:2013-10-15 02:28:05
【问题描述】:
有没有办法创建一个转储文件,其中包含索引的所有数据及其设置和映射?
与 mongoDB 处理 mongodump 的方式类似
或在 Solr its data folder is copied 中复制到备份位置。
干杯!
【问题讨论】:
标签: elasticsearch
有没有办法创建一个转储文件,其中包含索引的所有数据及其设置和映射?
与 mongoDB 处理 mongodump 的方式类似
或在 Solr its data folder is copied 中复制到备份位置。
干杯!
【问题讨论】:
标签: elasticsearch
这是我们一直在为此目的而开发的新工具https://github.com/taskrabbit/elasticsearch-dump。您可以将索引导出到/导出 JSON 文件,或者从一个集群导出到另一个集群。
【讨论】:
Elasticsearch 现在开箱即用地支持这一点:
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html
【讨论】:
我们可以使用 elasticdump 进行备份并恢复它,我们可以将数据从一个服务器/集群移动到另一个服务器/集群。
1.使用elasticdump 将一个索引数据从一台服务器/集群移动到另一台服务器/集群的命令。
# Copy an index from production to staging with analyzer and mapping:
elasticdump \
--input=http://production.es.com:9200/my_index \
--output=http://staging.es.com:9200/my_index \
--type=analyzer
elasticdump \
--input=http://production.es.com:9200/my_index \
--output=http://staging.es.com:9200/my_index \
--type=mapping
elasticdump \
--input=http://production.es.com:9200/my_index \
--output=http://staging.es.com:9200/my_index \
--type=data
2。使用multielasticdump 将所有索引数据从一台服务器/集群移动到另一台服务器/集群的命令。
备份
multielasticdump \
--direction=dump \
--match='^.*$' \
--limit=10000 \
--input=http://production.es.com:9200 \
--output=/tmp
恢复
multielasticdump \
--direction=load \
--match='^.*$' \
--limit=10000 \
--input=/tmp \
--output=http://staging.es.com:9200
注意:
如果 --direction 是默认的 dump, --input 必须是 ElasticSearch 服务器的基本位置的 URL(即http://localhost:9200), --output 必须是目录。每个匹配的索引都会创建一个数据、映射和分析器文件。
要加载您从 multi-elasticsearch 转储的文件,--direction 应设置为 load,--input 必须是 multielasticsearch 转储的目录,--output 必须是 Elasticsearch 服务器 URL。
第二条命令将备份settings、mappings、template 和data 本身作为 JSON 文件。
--limit 不能超过10000,否则会报异常。
【讨论】:
--ignoreChildError=true 添加到multielasticdump 命令。此外,可能需要将--limit 设置为低于 10000(例如,设置为 1000)以防止某些其他类型的模糊错误。后者也适用于elasticdump 命令。
multielasticdump --direction=load,我必须添加--ignoreType='template'。
multielasticdump ... --input=http://production.es.com:9200/ ... 而不仅仅是 multielasticdump ... --input=http://production.es.com:9200 ...。否则它会因一些非常非描述性的错误而失败。
对于您的情况,Elasticdump 是完美的答案。
首先,您需要下载映射,然后是索引
# Install the elasticdump
npm install elasticdump -g
# Dump the mapping
elasticdump --input=http://<your_es_server_ip>:9200/index --output=es_mapping.json --type=mapping
# Dump the data
elasticdump --input=http://<your_es_server_ip>:9200/index --output=es_index.json --type=data
如果你想在任何服务器上转储数据,我建议你通过 docker 安装 esdump。您可以从这个网站获取更多信息Blog Link
【讨论】:
ElasticSearch 本身提供了一种创建数据备份和恢复的方法。执行此操作的简单命令是:
CURL -XPUT 'localhost:9200/_snapshot/<backup_folder name>/<backupname>' -d '{
"indices": "<index_name>",
"ignore_unavailable": true,
"include_global_state": false
}'
现在,如何创建,这个文件夹,如何在ElasticSearch配置中包含这个文件夹路径,以便它可以用于ElasticSearch,恢复方法,很好解释here。看它的实用演示冲浪here。
【讨论】:
数据本身是一个或多个 lucene 索引,因为您可以有多个分片。您还需要备份的是集群状态,其中包含有关集群、可用索引、它们的映射、它们组成的分片等的各种信息。
不过,它都在data 目录中,您可以复制它。它的结构非常直观。在复制之前最好禁用自动刷新(为了备份索引的一致视图并避免在复制文件时对其进行写入),发出手动刷新,同时禁用分配。记得从所有节点复制目录。
此外,elasticsearch 的下一个主要版本将提供一个新的快照/恢复 api,允许您执行增量快照并通过 api 恢复它们。这是相关的 github 问题:https://github.com/elasticsearch/elasticsearch/issues/3826。
【讨论】:
您还可以通过 http 请求以 JSON 格式转储 elasticsearch 数据:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.htmlCURL -XPOST 'https://ES/INDEX/_search?scroll=10m'CURL -XPOST 'https://ES/_search/scroll' -d '{"scroll": "10m", "scroll_id": "ID"}'
【讨论】:
要将所有文档从 ElasticSearch 导出为 JSON,您可以使用 esbackupexporter 工具。它适用于索引快照。它将带有快照(S3、Azure blob 或文件目录)的容器作为输入,并每天为每个索引输出一个或多个压缩 JSON 文件。导出历史快照时非常方便。要导出您的热门索引数据,您可能需要先制作快照(请参阅上面的答案)。
【讨论】:
如果您想在数据离开 Elasticsearch 的过程中对其进行处理,您可能需要使用 Logstash。它有一个方便的Elasticsearch Input Plugin。
然后您可以导出到任何内容,从 CSV 文件到 reindexing the data on another Elasticsearch cluster。虽然对于后者,您也有Elasticsearch's own Reindex。
【讨论】:
在撰写此答案时(2021 年),备份 ElasticSearch 集群的官方方法是对其进行快照。参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshot-restore.html
【讨论】: