1.在原来的机器上进行备份(我这里备份只保留2天,所以多了些处理脚本)
##创建备份仓库目录
curl -H "Content-Type: application/json" -XPUT http://192.168.1.136:19200/_snapshot/esbackup -d'{
    "type": "fs", 
    "settings": {
        "location": "/home/yeemiao/single_elasticsearch/esbak"
    }
}'

##备份
curl -H "Content-Type: application/json" -XPUT http://192.168.1.136:19200/_snapshot/esbackup/snapshot_20190815

2.查看备份情况
curl -X GET "http://192.168.1.136:19200/_snapshot/esbackup/_all?pretty"
我这里已经有备份,查看备份情况
[yeemiao@localhost esbak]$ curl -X GET "http://192.168.1.136:19200/_snapshot/esbackup/_all?pretty"
{
  "snapshots" : [
    {
      "snapshot" : "snapshot_20190815",
      "uuid" : "jZk8QYgISMmkc1qpNB4BZw",
      "version_id" : 6050099,
      "version" : "6.5.0",
      "indices" : [
        "reservation_hxl",
        "reservation",
        "vacc_update",
        "reservation_new",
        "child_inocexamine_student_inoculation1",
        "child_inocexamine_vacc",
        "hxl_update",
        "bak01_hxl_test",
        "child_inocexamine_student",
        "bak_hxl_test",
        "child_inocexamine_student_inoculation",
        "inoculate_new",
        "update",
        "bak02_hxl_test",
        "inoculate",
        ".security-6"
      ],
      "include_global_state" : true,
      "state" : "IN_PROGRESS",
      "start_time" : "2019-08-15T05:45:40.443Z",
      "start_time_in_millis" : 1565847940443,
      "end_time" : "1970-01-01T00:00:00.000Z",
      "end_time_in_millis" : 0,
      "duration_in_millis" : -1565847940443,
      "failures" : [ ],
      "shards" : {
        "total" : 0,
        "failed" : 0,
        "successful" : 0
      }
    }
  ]
}


3.将es备份目录打包,然后上传到新部署的机器上面
[yeemiao@localhost single_elasticsearch]$ cd /home/yeemiao/single_elasticsearch
tar -czvf esbak20190815.tar ./esbak
scp esbak20190815.tar yeemiao@192.168.1.134:/tmp/

4.新机器安装部署es
安装步骤省略,特别注意如下参数必须跟原来机器一致,因为我们等会将原来机器的备份文件加压到该目录
path.repo: /home/yeemiao/single_elasticsearch/esbak

5.将原主机备份的文件解压到新机器path.repo参数指定的目录
[yeemiao@localhost tmp]$ cd /tmp/
[yeemiao@localhost tmp]$ tar -xvf esbak20190815.tar
[yeemiao@localhost esbak]$ cd /tmp/esbak
[yeemiao@localhost esbak]$ cp -r ./* /home/yeemiao/single_elasticsearch/esbak

6.执行恢复
新的机器这个时候是没有index的
[yeemiao@localhost esbak]$ curl -X GET 'http://192.168.1.134:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size

执行恢复步骤
6.1 创建备份指定目录
curl -H "Content-Type: application/json" -XPUT http://192.168.1.134:9200/_snapshot/esbackup -d'{
    "type": "fs", 
    "settings": {
        "location": "/home/yeemiao/single_elasticsearch/esbak"
    }
}'

6.2 查看备份信息,这个时候备份信息已经注册进来了
curl -X GET "http://192.168.1.134:9200/_snapshot/esbackup/_all?pretty"

6.3 执行恢复
curl -XPOST http://192.168.1.134:9200/_snapshot/esbackup/snapshot_20190815/_restore


7.验证
[yeemiao@localhost esbak]$ curl -X GET 'http://192.168.1.134:9200/_cat/indices?v'
这里输出查看到跟原来的主机结果一致

-- The End --
09-07 13:04