如何备份和恢复 ElasticSearch

Sha*_*awn 7 elasticsearch

我一直在尝试使用以下方法将 ElasticSearch 集群从一台服务器备份和还原到另一台服务器,但收效甚微。到目前为止,我还没有使用过备份过程,我想将我的整个 ElasticSearch 集群从一个 2GB 的小集群移动到 15GB 的集群。我使用了以下方法。

  1. 使用taskrabit/elasticsearch-dump - 我能够成功地将完整的数据库导出到 backup.json 文件,但是在恢复 backup.json 时,它给了我以下输出。在进一步研究输出后,我了解到插件的批量输入尚未完全开发。

     ./bin/elasticdump --all=true --input=/home/user/backup.json --output=http://192.168.0.213:9200/ --type=data
     Thu, 09 Feb 2017 06:43:29 GMT | starting dump
     Thu, 09 Feb 2017 06:43:29 GMT | got 61 objects from source file (offset: 0)
     Thu, 09 Feb 2017 06:43:29 GMT | sent 61 objects to destination elasticsearch, wrote 0
     Thu, 09 Feb 2017 06:43:29 GMT | got 0 objects from source file (offset: 61)
     Thu, 09 Feb 2017 06:43:29 GMT | Total Writes: 0
     Thu, 09 Feb 2017 06:43:29 GMT | dump complete
    
    Run Code Online (Sandbox Code Playgroud)
  2. 使用 elasticsearch-tools(es-export-bulk 和 es-import bulk)我再次能够成功备份 json。但是导入再次失败并出现错误:

     "statusCode":400,"response":"{"error":{ 
    
    Run Code Online (Sandbox Code Playgroud)

我使用了es-bulk-export 中的示例

  1. 使用 ElasticSearch 内置快照和还原。

     curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
       "type": "fs",
        "settings": {"location": "/home/shawn/backup", "compress": true}
     }'
    
    Run Code Online (Sandbox Code Playgroud)

我相信我错过了一些东西,因为执行给了我以下错误。我需要创建/_snapshot/my_backup吗?如果是这样怎么办?

{"error":{"root_cause":[
  {"type":"repository_exception",
   "reason":"[my_backup] location [/home/shawn/backup] doesn't match any of the locations specified by path.repo because this setting is empty"
  }],
   "type":"repository_exception","reason":"[my_backup] failed to create repository",
   "caused_by":
       {"type":"creation_exception","reason":"Guice creation errors:\n\n1) Error injecting constructor, RepositoryException[[my_backup] location [/home/shawn/backup] doesn't match any of the locations specified by path.repo because this setting is empty]\n  at org.elasticsearch.repositories.fs.FsRepository.<init>(Unknown Source)\n  while locating org.elasticsearch.repositories.fs.FsRepository\n  while locating org.elasticsearch.repositories.Repository\n\n1 error","caused_by":{"type":"repository_exception","reason":"[my_backup] location [/home/shawn/backup] doesn't match any of the locations specified by path.repo because this setting is empty"}}},"status":500}
Run Code Online (Sandbox Code Playgroud)

小智 8

您正在创建 _snapshot/my_backup 就好了,您只需要在/etc/elasticsearch/elasticsearch.yml 中添加一行:

path.repo: ["/home/shawn/backup"]
Run Code Online (Sandbox Code Playgroud)

这是快照的实际位置。然后重启 Elasticsearch。