首先,这是官方介绍:
https://www.elastic.co/guide/en/elasticsearch/reference/5.5/modules-snapshots.html#_snapshot
第一步:先创建一个快照仓库,使用API创建
PUT /_snapshot/esbackup { "type":"fs" , "settings": { "location": "/data/backup" } } 返回结果 { "acknowledged": true }
当然,没那么简单,/data/backup,这个目录不是随便指定得,需要在elasticsearch.yml 配置文件里面指定,不然会报500错误, 如果是集群,则每一个数据节点都得配置
path.repo: /data/backup
如果是集群,则每一个数据节点都得配置 “path.repo: /data/backup”,并且,这个目录对于每一个数据节点都要有共享得读写权限,这里,我们使用NFS共享
[root@ND78 data]# vim /etc/exports /data/backup 192.168.0.76(rw)
确定每一个节点挂载起来这个目录后,才能创建快照仓库
创建成功后我们可以查看一下这个仓库信息
GET _snapshot/esbackup { "esbackup": { "type": "fs", "settings": { "location": "/data/backup" } } }
第二步:备份
PUT _snapshot/esbackup/b20170824
b20170824是备份名字
一个仓库可以存储多个备份,比如再备份一个
PUT _snapshot/esbackup/b20170825
查看备份
GET _snapshot/esbackup/b20170824 { "snapshots": [ { "snapshot": "b20170824", "uuid": "sajgUSp0RHClo7JvSxrMjQ", "version_id": 5020299, "version": "5.2.2", "indices": [ "logstash-2017.05.08", "megacorp", "logstash-2017.07.26", "test_index", ".kibana", "logstash-2017.05.04", ".monitoring-es-2-2017.08.17", ".monitoring-es-2-2017.08.22", ".monitoring-data-2", "oeeee-2017.04.29", "logstash-2017.05.06", "my_index", "logstash-2017.05.09", ".monitoring-es-2-2017.08.19", ".monitoring-es-2-2017.08.21", "logstash-2017.04.23", "kcis_user", "logstash-2017.04.21", "logstash-2017.05.05", ".monitoring-es-2-2017.08.23", "logstash-2017.05.14", ".monitoring-es-2-2017.08.18", "my_index3", "logstash-2017.05.13", "logstash-2017.05.11", "daily-tag-2017.07.11", "tag_profile", "logstash-2017.05.02", ".monitoring-es-2-2017.08.24", "logstash-2017.05.03", "logstash-2017.05.12", "logstash-2017.04.22", ".monitoring-es-2-2017.08.20", "user_profile_v1", "logstash-2017.05.10", "logstash-2017.05.07", "website", "my_index2" ], "state": "IN_PROGRESS", "start_time": "2017-08-24T07:10:45.148Z", "start_time_in_millis": 1503558645148, "failures": [], "shards": { "total": 0, "failed": 0, "successful": 0 } } ] }
第三步:还原
还原指定索引
POST _snapshot/esbackup/b20170825/_restore { "indices":"logstash-2017.05.13" }
还原所有索引
POST _snapshot/esbackup/b20170825/_restore