Elasticsearch 快照备份与恢复
path.repo: ["/es_backup/my_backup/"] #如果想保存到多个路径可以逗号隔开
# 修改完之后,记得重启Es
# 如果本地没有该目录,创建该目录,目录权限也要设置正确
curl -X PUT "http://localhost:9200/_snapshot/my_backup&pretty" -H 'Content-Type: application/json' -d' { "type": "fs", "settings": { "compress" : "true", "location": "/es_backup/my_backup/" } }'# 查看仓库信息
curl -XGET "http://localhost:9200/_snapshot/my_backup?pretty"# 删除仓库
curl -XDELETE 'http://localhost:9200/_snapshot/my_backup'
# 创建快照 curl -XPUT ’http://localhost:9200/_snapshot/my_backup/snapshot_2?wait_for_completion=true‘
# 使用当前日期来命名快照,日期格式:snapshot-2018.11.29 curl -X PUT "http://localhost:9200/_snapshot/my_backup/%3Csnapshot-%7Bnow%2Fd%7D%3E"# 查看索引
curl -XGET 'http://localhost:9200/_cat/indices?v'
# 指定索引创建快照 curl -XPUT 'http://localhost:9200/_snapshot/my_backup/snapshot_1' -H 'Content-Type: application/json' -d '{ "indices": "nginx-ingress-controller-log-2018.11.27,nginx-ingress-controller-log-2018.11.28", "ignore_indices": "missing" }'# 查看所有快照
curl -XGET "http://localhost:9200/_snapshot/my_backup?pretty"
# 查看指定快照
curl -XGET "localhost:9200/_snapshot/my_backup/_all?pretty"
# 恢复快照(所有索引) curl -XPOST http://localhost:9200/_snapshot/my_backup/snapshot_1/_restore # 恢复快照(指定索引) curl -XPOST "http://localhost:9200/_snapshot/my_backup/snapshot-2018.11.29/_restore?wait_for_completion=true" -H 'Content-Type: application/json' -d' { "indices":"nginx-ingress-controller-log-2018.11.29", "ignore_unavailable":"true" }'# 注意:恢复快照的时候需要停止要恢复的索引
# 快照恢复前需要关掉索引
curl -XPOST "http://localhost:9200/my_index/_close"
curl -XPOST "http://localhost:9200/customer/_close"
# 开启索引
curl -XPOST "http://localhost:9200/my_index/_open"
# 查看索引状态
curl -XGET 'http://localhost:9200/_cat/indices?v'
curl -XGET "http://localhost:9200/_recovery/"
# 查看仓库信息 curl -XGET "localhost:9200/_snapshot/my_backup?pretty" # 查看所有快照 curl -XGET "localhost:9200/_snapshot/my_backup/_all?pretty" # 删除快照 curl -XDELETE "localhost:9200/_snapshot/my_backup/snapshot_2" # 查看仓库列表 curl -X GET "localhost:9200/_cat/repositories?v" # 获取所有已注册快照仓库
curl -X GET "localhost:9200/_snapshot/_all?pretty"