elasticsearch snapshot備份、恢復
阿新 • • 發佈:2018-11-15
Elasticsearch配置檔案elasticsearch.yml設定倉庫路徑:
path.repo: "/data/elasticsearch/backup
1、建立倉庫
curl -XPUT http://127.0.0.1:9200/_snapshot/my_backup -H 'Content-Type: application/json' -d '{"type": "fs", "settings": {"location": "/data/elasticsearch/backup", "compress": true}}'
2、建立快照
curl -XPUT http://127.0.0.1:9200/_snapshot/my_backup/snapshot_2?wait_for_completion=true
3、恢復快照
curl -XPOST http://127.0.0.1:9200/_snapshot/my_backup/snapshot_1/_restore
日常操作:
檢視倉庫資訊
[email protected] ~ $ curl -XGET "localhost:9200/_snapshot/my_backup?pretty"
{
"my_backup" : {
"type" : "fs",
"settings" : {
"compress" : "true",
"location" : "/data/elasticsearch/backup"
}
}
}
檢視所有快照
[email protected] ~ $ curl -XGET "localhost:9200/_snapshot/my_backup/_all?pretty"
{
" snapshots" : [
{
"snapshot" : "snapshot_1",
"uuid" : "Vtuq35gqS42E4ZBvmeZaDw",
"version_id" : 6030299,
"version" : "6.3.2",
"indices" : [
"index",
"customer"
],
"include_global_state" : true,
"state" : "SUCCESS",
"start_time" : " 2018-08-22T11:56:49.009Z",
"start_time_in_millis" : 1534939009009,
"end_time" : "2018-08-22T11:56:49.177Z",
"end_time_in_millis" : 1534939009177,
"duration_in_millis" : 168,
"failures" : [ ],
"shards" : {
"total" : 7,
"failed" : 0,
"successful" : 7
}
},
{
"snapshot" : "snapshot_2",
"uuid" : "Ih6LJD-MRliLjxgGsu8VhA",
"version_id" : 6030299,
"version" : "6.3.2",
"indices" : [
"index",
"customer"
],
"include_global_state" : true,
"state" : "SUCCESS",
"start_time" : "2018-08-22T11:57:08.388Z",
"start_time_in_millis" : 1534939028388,
"end_time" : "2018-08-22T11:57:08.449Z",
"end_time_in_millis" : 1534939028449,
"duration_in_millis" : 61,
"failures" : [ ],
"shards" : {
"total" : 7,
"failed" : 0,
"successful" : 7
}
}
]
}
刪除快照
[email protected] ~ $ curl -XDELETE "localhost:9200/_snapshot/my_backup/snapshot_2"
{"acknowledged":true}
[email protected] ~ $ curl -XGET "localhost:9200/_snapshot/my_backup/_all?pretty"
{
"snapshots" : [
{
"snapshot" : "snapshot_1",
"uuid" : "Vtuq35gqS42E4ZBvmeZaDw",
"version_id" : 6030299,
"version" : "6.3.2",
"indices" : [
"index",
"customer"
],
"include_global_state" : true,
"state" : "SUCCESS",
"start_time" : "2018-08-22T11:56:49.009Z",
"start_time_in_millis" : 1534939009009,
"end_time" : "2018-08-22T11:56:49.177Z",
"end_time_in_millis" : 1534939009177,
"duration_in_millis" : 168,
"failures" : [ ],
"shards" : {
"total" : 7,
"failed" : 0,
"successful" : 7
}
}
]
}