elasticsearch 快照和恢复
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了elasticsearch 快照和恢复相关的知识,希望对你有一定的参考价值。
首先,这是官方介绍:
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
创建成功后我们可以查看一下这个仓库信息
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
本文出自 “飞一般的爱情故事” 博客,请务必保留此出处http://niubdada.blog.51cto.com/3511133/1959065
以上是关于elasticsearch 快照和恢复的主要内容,如果未能解决你的问题,请参考以下文章
除了使用Elasticsearch恢复API以外,还有其他方法可以恢复Elasticsearch快照吗?
《Elasticsearch 源码解析与优化实战》第13章:Snapshot 模块分析