elasticsearch备份与恢复

一、参考文档

elasticseach权威指南: https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html

二、前期准备

架设NFS服务器,并将其挂在至所有elasticsearch节点,挂载点为/data/backup/elasticsearch

三、配置elasticsearch

  • 修改elasticsearch配置文件/etc/elasticsearch/elasticsearch.yml, 添加path.repo:["/data/backup/elasticsearch"]

  • 重启elasticsearch systemctl restart elasatcisearch

  • 创建备份仓库

    $ curl -XPUT http://localhost:9200/_snapshot/backup -H 'Content-Type:application/json' -d '
    {
        "type": "fs",
        "settings": {
            "location": "/data/backup/elasticsearch",
            "max_snapshot_bytes_per_sec": "50mb",
            "max_restore_bytes_per_sec": "50mb",
            "compress": "true"
        }
    }
    '
    
  • 备份数据

    $ curl -XPOST http://localhost:9200/_snapshot/backup/backup-2019-03-01
    

    TIPS: 如果不希望快照作为后台进程运行,可以通过添加wait_for_completion=true参数,使其在前台运行,知道备份完成。
    curl -XPOST http://localhost:9200/_snapshot/backup/backup-2019-03-01?wait_for_completion=true

  • 终止备份

    $ curl -XDELETE http://localhost:9200/_snapshot/backup/backup-2019-03-1
    

四、恢复数据

如果是在新的集群恢复数据,需要先将NFS挂载至elasticsearch节点,并修改配置文件path.repo:["/data/backup/elasticsearch"], 并创建备份仓库,而后执行如下命令:

$ curl -XPOST http://localhost:9200/_snapshot/backup/backup-2019-03-01?wait_for_completion=true

如果,不在新的集群恢复,那么只需要执行上述命令即可。

备注: 使用快照并不会备份templates

你可能感兴趣的:(elasticsearch备份与恢复)