1. 程式人生 > >elasticsearch系列(六)備份

elasticsearch系列(六)備份

indices stat 必須 tor 信息 操作 accepted gui 配置

快照備份

1.創建文件倉庫

1.1 在$ELASTICSEARCH_HOME/config/elasticsearch.yaml中增加配置

#這個路徑elasticsearch必須有權限訪問,這個路徑是所有快照倉庫的根路徑

path.repo: your_path

1.2 調用rest api

// nlp_defect是你倉庫的名稱

put url/_snapshot/nlp_defect

{

"type": "fs",

"settings": {

"location": "/home/elasticsearch/nlp"

}

}

回復

{

"acknowledged":true

}

表示創建成功

2.配置倉庫

max_snapshot_bytes_per_sec

當快照數據進入倉庫時,這個參數控制這個過程的限流情況。默認是每秒20mb。

max_restore_bytes_per_sec

當從倉庫恢復數據時,這個參數控制什麽時候恢復過程會被限流以保障你的網絡不會被占滿。默認是每秒 `20mb`。

post _snapshot/nlp_defect

{

"type": "fs",

"settings": {

"location": "/home/elasticsearch/nlp",

"max_snapshot_bytes_per_sec": "50mb",

"max_restore_bytes_per_sec": "50mb"

}

}

回復

{

"acknowledged":true

}

表示修改成功

3.指定備份索引

put _snapshot/nlp_defect/snapshot_20170613

{

"indices": "defect"

}

回復

{

"accepted":true

}

表示快照成功

備註

可以增加wait_for_completion=true來阻塞至操作結束再返回

4.查看快照信息

get _snapshot/nlp_defect/snapshot_20170613

回復

{

"snapshots": [

{

"snapshot": "snapshot_20170613",

"uuid": "YKVFEaTjTE-7XWl27O38Ew",

"version_id": 5020299,

"version": "5.2.2",

"indices": [

"defect"

],

"state": "SUCCESS",

"start_time": "2017-06-13T06:17:18.585Z",

"start_time_in_millis": 1497334638585,

"end_time": "2017-06-13T06:17:19.038Z",

"end_time_in_millis": 1497334639038,

"duration_in_millis": 453,

"failures": [],

"shards": {

"total": 5,

"failed": 0,

"successful": 5

}

}

]

}

5.刪除快照

delete _snapshot/nlp_defect/snapshot_20170613

回復

{

"acknowledged":true

}

表示成功

快照恢復

從快照恢復

//默認恢復,恢復之後和之前的一樣

post _snapshot/nlp_defect/snapshot_20170613/_restore

//輔助配置

{

"indices": "defect",

"rename_pattern": "defect",

"rename_replacement": "defect_1"

}

跨集群恢復

原集群創建快照倉庫repository,創建快照snapshot,完成後把snapshot拷貝至新集群,

新集群創建快照倉庫repository_1,repository_1與repository名稱最好一樣,把snapsot解壓到該倉庫下,執行,ok

_snapshot/$repository_1/$snapshot/_restore

當然也可以自定義配置,這個和同集群一樣

參考資料

//官網備份指導

https://www.elastic.co/guide/cn/elasticsearch/guide/cn/backing-up-your-cluster.html

//官方恢復指導

https://www.elastic.co/guide/cn/elasticsearch/guide/cn/_restoring_from_a_snapshot.html

elasticsearch系列(六)備份