elasticsearch snapshot

https://www.cnblogs.com/mayidudu/p/6094014.htmlhtml




1、Repositoriesvim

在elasticsearch.yml文件中增長path.repo路徑配置:api

$ vim /etc/elasticsearch/elasticsearch.ymlcurl

path.repo: ["/home/ccx/es/backups", "/mount/longterm_backups"]elasticsearch

重啓elasticsearchide

$ service elasticsearch restarturl

建立文件夾做爲repository的目錄,並修改文件夾權限spa

$ mkdir -p /home/ccx/es/backupsrest

$ chmod 755 /home/ccx/es/backups/orm

$ chown elasticsearch:elasticsearch /home/ccx/es/backups/

建立repository

$ curl -XPUT 'http://192.168.212.190:9200/_snapshot/my_backup' -d '{

"type": "fs",

"settings": {

"location": "/home/ccx/es/backups/my_backup",

"compress": true

}

}'

查看repository信息

$ curl -XGET 'http://192.168.212.190:9200/_snapshot/my_backup?pretty'

能夠使用POST 請求,用來修改已經存在的repository

$ curl -XPOST 'http://192.168.212.190:9200/_snapshot/my_backup' -d '{

"type": "fs",

"settings": {

"location": "/home/ccx/es/backups/my_backup",

"max_snapshot_bytes_per_sec" : "50mb",

"max_restore_bytes_per_sec" : "50mb"

}

}'

2、Snapshot

建立快照

備份工做在後臺運行

$ curl -XPUT 'http://192.168.212.190:9200/_snapshot/my_backup/snapshot_1'

同步執行,加wait_for_completion 標誌,備份完成後才返回,若是數據量大的話,會花很長時間

$ curl -XPUT 'http://192.168.212.190:9200/_snapshot/my_backup/snapshot_2?wait_for_completion=true'

若是隻想備份部分索引的話,能夠加上indices 參數:

$ curl -XPUT 'http://192.168.212.190:9200/_snapshot/my_backup/snapshot_3' -d '{

"indices": "index_1,index_2",

"ignore_indices": "missing"

}'

查看備份信息

$ curl -XGET 'http://192.168.212.190:9200/_snapshot/my_backup/snapshot_2'

若是要查看全部索引的信息,使用以下api:

$ curl -XGET 'http://192.168.212.190:9200/_snapshot/my_backup/_all'

另外還有個一api能夠看到更加詳細的信息:

$ curl -XGET 'http://192.168.212.190:9200/_snapshot/my_backup/snapshot_2/_status'

刪除備份

$ curl -XDELETE 'http://192.168.212.190:9200/_snapshot/my_backup/snapshot_2'

3、Restore

恢復snapshot_1裏的所有索引:

$ curl -XPOST 'http://192.168.212.190:9200/_snapshot/my_backup/snapshot_1/_restore'

api額外的參數:

$ curl -XPOST 'http://192.168.212.190:9200/_snapshot/my_backup/snapshot_1/_restore' -d '{

"indices": "index_1",

"rename_pattern": "index_(.+)",

"rename_replacement": "restored_index_$1"

}'

參數indices 設置只恢復index_1索引,參數rename_pattern 和rename_replacement 用來正則匹配要恢復的索引,而且重命名。和備份同樣,api會馬上返回值,而後在後臺執行恢復,使用wait_for_completion 標記強制同步執行。

以使用下面兩個api查看狀態

$ curl -XGET 'http://192.168.212.190:9200/_recovery/'

相關文章
相關標籤/搜索