若是ES是集羣,那麼須要使用共享存儲,支持的存儲有:
a、shared file system
b、S3
c、HDFSnode
我使用的是第一種,NFS共享文件系統。這裏要說一下權限問題,ES通常是使用 elasticsearch 用戶啓動的,要保證共享目錄對 elasticsearch 用戶有讀寫權限,要否則建立倉庫和快照的時候會報訪問拒絕500錯誤。nginx
在nfs-server上導出共享目錄的權限配置,這裏將全部鏈接用戶都壓縮爲root權限:sql
# vim /etc/exports /data02/es 192.168.3.56(rw,sync,all_squash,anonuid=0,anongid=0,no_subtree_check) 192.168.3.57(rw,sync,all_squash,anonuid=0,anongid=0,no_subtree_check) 192.168.3.49(rw,sync,all_squash,anonuid=0,anongid=0,no_subtree_check) # /etc/init.d/nfs-kernel-server reload
一、建立掛載目錄,並給予權限shell
# mkidr -pv /nh/esbk/my_backup # chmod 755 /nh/esbk/ # chown elasticsearch.elasticsearch /nh/esbk/
二、掛載共享目錄vim
# vim /etc/fstab 192.168.3.97:/data02/es /nh/esbk/my_backup nfs defaults 0 0 # mount -a # df -hT
三、修改ES的配置文件,添加倉庫路徑,重啓服務ruby
# vim /etc/elasticsearch/elasticsearch.yml path.repo: ["/nh/esbk"] # /etc/init.d/elasticsearch restart
四、註冊快照倉庫到ES,這裏是在 kibana 的 Dev Tools 上操做的,也可使用 curl 發起請求。bash
Before any snapshot or restore operation can be performed, a snapshot repository should be registered in Elasticsearch. After all nodes are restarted, the following command can be used to register the shared file system repository with the name my_backup.
PUT /_snapshot/my_backup { "type": "fs", "settings": { "compress": true, "location": "/nh/esbk/my_backup" } }
五、查看倉庫信息curl
GET /_snapshot/my_backup # curl -u elastic -XGET 'http://192.168.3.49:9200/_snapshot/my_backup?pretty' { "my_backup" : { "type" : "fs", "settings" : { "compress" : "true", "location" : "/nh/esbk/my_backup" } } }
六、建立快照elasticsearch
A repository can contain multiple snapshots of the same cluster. Snapshots are identified by unique names within the cluster. A snapshot with the name snapshot_1 in the repository my_backup can be created by executing the following command.
PUT /_snapshot/my_backup/snapshot_1
這裏發起請求後,會立馬返回 true,並在後臺執行操做。
若是想等待執行完成以後再返回,能夠加一個參數:ide
PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
七、查看剛纔建立的快照的信息
Once a snapshot is created information about this snapshot can be obtained using the following command.
GET /_snapshot/my_backup/snapshot_1 { "snapshots": [ { "snapshot": "snapshot_1", "uuid": "xSMRNVMIRHmx_qlhX5fqfg", "version_id": 5040199, "version": "5.4.1", "indices": [ ".monitoring-kibana-2-2017.07.05", ".monitoring-kibana-2-2017.07.11", "zixun-nginx-access-2017.07.12", ".monitoring-logstash-2-2017.07.07", ".monitoring-kibana-2-2017.07.07", "filebeat-2017.07.07", ".watcher-history-3-2017.07.04", ".watcher-history-3-2017.07.07", ".monitoring-es-2-2017.07.05", ".kibana", ".monitoring-data-2", ".watcher-history-3-2017.06.27", ".monitoring-logstash-2-2017.07.10", ".monitoring-kibana-2-2017.07.10", ".monitoring-es-2-2017.07.08", ".monitoring-logstash-2-2017.07.12", ".monitoring-es-2-2017.07.10", ".watcher-history-3-2017.07.06", ".monitoring-kibana-2-2017.07.09", ".watcher-history-3-2017.07.12", ".watcher-history-3-2017.07.03", ".monitoring-alerts-2", ".monitoring-logstash-2-2017.07.08", ".watcher-history-3-2017.07.01", ".watcher-history-3-2017.07.11", ".watcher-history-3-2017.07.05", ".watcher-history-3-2017.06.29", ".watcher-history-3-2017.06.28", ".monitoring-kibana-2-2017.07.08", ".security", ".monitoring-logstash-2-2017.07.11", ".monitoring-es-2-2017.07.11", ".watcher-history-3-2017.06.30", ".triggered_watches", ".watcher-history-3-2017.07.08", ".monitoring-es-2-2017.07.12", ".watcher-history-3-2017.07.09", ".monitoring-es-2-2017.07.09", ".monitoring-kibana-2-2017.07.12", ".monitoring-kibana-2-2017.07.06", ".watcher-history-3-2017.07.10", "test", ".monitoring-es-2-2017.07.07", ".monitoring-logstash-2-2017.07.09", ".watches", ".monitoring-es-2-2017.07.06", ".watcher-history-3-2017.07.02" ], "state": "SUCCESS", "start_time": "2017-07-12T04:19:08.246Z", "start_time_in_millis": 1499833148246, "end_time": "2017-07-12T04:20:04.717Z", "end_time_in_millis": 1499833204717, "duration_in_millis": 56471, "failures": [], "shards": { "total": 59, "failed": 0, "successful": 59 } } ] }
列出一個倉庫裏的全部快照
All snapshots currently stored in the repository can be listed using the following command:
GET /_snapshot/my_backup/_all
八、刪除一個快照
A snapshot can be deleted from the repository using the following command:
DELETE /_snapshot/my_backup/snapshot_1
九、刪除一個倉庫
A repository can be deleted using the following command:
DELETE /_snapshot/my_backup
十、恢復一個快照(支持恢復部分數據以及恢復過程當中修改索引信息,具體細節參考官方文檔)
POST /_snapshot/my_backup/snapshot_1/_restore
十一、查看快照狀態信息(好比正在建立或者建立完成等)
a、列出全部當前正在運行的快照以及顯示他們的詳細狀態信息
A list of currently running snapshots with their detailed status information can be obtained using the following command.
GET /_snapshot/_status
b、查看指定倉庫的正在運行的快照以及顯示他們的詳細狀態信息
GET /_snapshot/my_backup/_status
c、查看指定快照的詳細狀態信息即便不是正在運行
If both repository name and snapshot id are specified, this command will return detailed status information for the given snapshot even if it’s not currently running:
GET /_snapshot/my_backup/snapshot_1/_status
d、支持同時指定多個快照ID查看多個快照的信息
Multiple ids are also supported.
GET /_snapshot/my_backup/snapshot_1,snapshot_2/_status
十二、若是要中止一個正在運行的snapshot任務(備份和恢復),將其刪除便可。