遷移注意事項
-
保證ES集羣不再接受新的數據(如果是備份的話,這一點可以不考慮,但是做數據遷移的話,建議這樣做).
-
不建議直接在生產環境做這些操作,最好是先在本地搭建一個和生產環境一樣的集羣環境,創建一些測試數據,把整個過程先跑一遍,然後再到生產環境操作。
-
配置文件中指定path.repo路徑,如:path.repo: /data/backups/elasticsearch
註冊快照倉庫
-
共享的文件系統,如NAS
-
Amazon S3
-
HDFS (Hadoop Distributed File System)
-
Azure Cloud
$ curl -XPUT http://192.168.0.1:9200/_snapshot/my_backup -d '
{
"type": "fs",
"settings": {
"location": "/data/backups/elasticsearch"
}
}
'
-
compress 是否壓縮
-
max_snapshot_bytes_per_sec 製作快照的速度,默認20mb/s
-
max_restore_bytes_per_sec 快照恢復的速度,默認20mb/s
$ curl -XPOST http://192.168.0.1:9200/_snapshot/my_backup/
{
"type": "fs",
"settings": {
"location": "/data/backups/elasticsearch",
"max_snapshot_bytes_per_sec" : "50mb",
"max_restore_bytes_per_sec" : "50mb",
"compress" : true
}
}
檢查註冊的倉庫信息
$ curl -XGET http://192.168.0.1:9200/_snapshot/my_backup
開始備份
$ curl -XPUT http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812
$ curl -XPUT http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812?wait_for_completion=true
默認是備份所有的索引indices, 如果要指定index,可以
$ curl -XPUT http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812
{
"indices": "index_1,index_2"
}
查看備份狀態
$ curl -XGET http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812/_status
-
INITIALIZING 集羣狀態檢查,檢查當前集羣是否可以做快照,通常這個過程會非常快
-
STARTED 正在轉移數據到倉庫
-
FINALIZING 數據轉移完成,正在轉移元信息
-
DONE 完成
-
FAILED 備份失敗
取消備份
$ curl -XDELETE http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812
恢復備份
$ curl -XPOST http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812/_restore
同備份一樣,也可以設置wait_for_completion=true等待恢復結果
$ curl -XPOST http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812/_restore?wait_for_completion=true
$ curl -XPOST http://192.168.0.1:9200/_snapshot/my_backup/snapshot_20150812/_restore
{
"indices": "index_1",
"rename_pattern": "index_(.+)",
"rename_replacement": "restored_index_$1"
}
-
上面的indices, 表示只恢復索引’index_1’
-
renamepattern: 表示重命名索引以’index‘開頭的索引.
-
rename_replacement: 表示將所有的索引重命名爲’restored_index_xxx’.如index_1會被重命名爲restored_index_1.
查看恢復進度
# 查看所有索引的恢復進度
$ curl -XGET http://192.168.0.1:9200/_recovery/
# 查看索引restored_index_1的恢復進度
$ curl -XGET http://192.168.0.1:9200/_recovery/restored_index_1
取消恢復
$ curl -XDELETE http://192.168.0.1:9200/restored_index_1