环境:mac
使用brew 安装elasticsearch
1.在 /usr/local/etc/elasticsearch/elasticsearch.yml 文件中配置快照地址
path.repo: ["/data/backups/my_backup"]
2.重启elasticsearch
3.注册仓库:curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
"type":"fs",
"settings":{
"location":"/data/backups/my_backup",
"compress":"true"
}
}'
4.查看仓库信息
curl -XGET 'http://localhost:9200/_snapshot/my_backup?pretty'
输出:
{
"my_backup" : {
"type" : "fs",
"settings" : {
"compress" : "true", # 指定是否对快照文件进行压缩. 默认是 true.
"location" : "/data/backups/my_backup" #指定快照的存储位置。必须要有
}
}
}
5.删除一个仓库
curl -XDELETE 'localhost:9200/_snapshot/my_backup'
6.创建快照
同一个集群中,一个仓库中可以存放多个快照。快照在集群中的名称是唯一的。使用下面命令创建快照名为snapshot_1的快照:
所有索引进行快照:
curl -XPUT "localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true?pretty"
某个索引进行快照:
curl -XPUT "localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true?pretty" -d '{"indices":"customer"}'
7.查看快照
curl -XGET "localhost:9200/_snapshot/my_backup/snapshot_1?pretty"
查看所有索引:curl -XGET "localhost:9200/_snapshot/my_backup/_all?pretty"
8.删除一个快照
curl -XDELETE "localhost:9200/_snapshot/my_backup/snapshot_1"
9.恢复一个快照 (恢复的意思是通过接口删除节点中的索引,不是删除备份的快照)
恢复所有索引:
curl -XPOST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore?wait_for_completion=true"
恢复某个索引:
curl -XPOST "localhost:9200/_snapshot/my_backup/snapshot_1/_restore?wait_for_completion=true" -d '{"indices":"customer","ignore_unavailable":"true"}'
注意:
快照恢复前需要关掉索引
curl -XPOST "localhost:9200/my_index/_close"
curl -XPOST "localhost:9200/customer/_close"
开启索引
curl -XPOST "localhost:9200/my_index/_open"
查看索引状态
curl 'localhost:9200/_cat/indices?v'
curl -XGET "localhost:9200/_recovery/"
10.查看快照状态信息(比如正在创建或者创建完成等)
a.列出所有当前正在运行的快照以及显示他们的详细状态信息
curl -XGET 'localhost:9200/_snapshot/_status?pretty'
b.查看指定仓库正在运行的快照以及显示他们的详细状态信息
curl -XGET 'localhost:9200/_snapshot/my_backup/_status?pretty'
c.查看指定快照的详细状态信息即使不是正在运行
curl -XGET 'localhost:9200/_snapshot/my_backup/snapshot_1/_status?pretty'
d.支持同时指定多个快照ID查看多个快照的信息
curl -XGET 'localhost:9200/_snapshot/my_backup/snapshot_1,snapshot_2/_status?pretty'