elasticsearch snapshot快照備份和恢復
阿新 • • 發佈:2017-08-31
pre 需要 位置 oca wait _for 通過 ati tom 環境: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‘
elasticsearch snapshot快照備份和恢復