Elasticsearch 备份并在另一个集群恢复

最近需要把一个 ES 集群的数据迁移到另一个 ES 集群。写篇文章简要记录一下备份恢复的过程。

Elasticsearch 备份并在另一个集群恢复

最近需要把一个 ES 集群的数据迁移到另一个 ES 集群。写篇文章简要记录一下备份恢复的过程。

  1. elasticsearch.yml 中新增 path.repo: ["/var/backups"],其中 /var/backups 为你想要备份到的目录,需要先手动创建。然后重启 ES
  2. 新建一个 backup:
curl -XPUT "http://localhost:9200/_snapshot/my_backup" -H 'Content-Type: application/json' -d'
{
  "type": "fs",
  "settings": {
    "location": "/var/backups"
  }
}' -u elastic:password
  1. 新建一个 snapshot:
curl -X PUT "localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true" -H 'Content-Type: application/json' -d'
{
  "indices": "apm*",
  "ignore_unavailable": true,
  "include_global_state": false
}
' -u elastic:password
  1. 可以用 curl "localhost:9200/_snapshot/my_backup/snapshot_1" -u elastic:password 查看备份的状态:
{
  "snapshots": [
    {
      "snapshot": "snapshot_1",
      "uuid": "jBZ5Ilh7TbiAvn7y5rKvKA",
      "version_id": 6020499,
      "version": "6.2.4",
      "indices": [
        "apm-6.3.2-transaction-2018.10.30",
        "apm-6.3.2-span-2018.10.06",
      ],
      "include_global_state": false,
      "state": "SUCCESS",
      "start_time": "2018-11-06T14:42:35.326Z",
      "start_time_in_millis": 1541515355326,
      "end_time": "2018-11-06T16:22:44.028Z",
      "end_time_in_millis": 1541521364028,
      "duration_in_millis": 6008702,
      "failures": [],
      "shards": {
        "total": 221,
        "failed": 0,
        "successful": 221
      }
    }
  ]
}
  1. /var/backups 打包拷贝到新的服务器并恢复到原位置,然后按照步骤 1、2 新建 backup
  2. curl -X POST /_snapshot/my_backup/snapshot_1/_restore