1. 程式人生 > >elasticsearch備份與恢復

elasticsearch備份與恢復

java 速度 完成 backups for arc backup 備份與恢復 let

備註:以下代碼在kibana插件下運行:

# 創建一個備份用的倉庫
# type:fs文件系統
# 支持Shared filesystem, Amazon S3, HDFS和Azure #Cloud
# location備份目錄

 PUT /_snapshot/my_backup
{
     "type": "fs",
     "settings": {
         "location": "c:/mount/backups/my_backup"
     }
}

  

# 修改備份倉庫屬性
# max——snapshot_bytes_per_sec,創建快照速度
# max_restore_bytes_per_sec,還原快照速度

POST /_snapshot/my_backup/
{
    "type": "fs",
    "settings": {
        "location": "/mount/backups/my_backup",
        "max_snapshot_bytes_per_sec" : "50mb",
        "max_restore_bytes_per_sec" : "50mb"
    }
}        

  

# 開始備份
#wait_for_completion等待完成參數,如果沒有,則後臺完成

PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true

  

# 查看快照

GET /_snapshot/my_backup/snapshot_1

  

# 查看所有快照

GET /_snapshot/my_backup/_all

  

# 快照詳細信息

GET /_snapshot/my_backup/snapshot_1/_status


# 刪除備份

DELETE /_snapshot/my_backup/snapshot_1

  

# 恢復snapshot_1裏的全部索引

POST /_snapshot/my_backup/snapshot_1/_restore


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

POST /_snapshot/my_backup/snapshot_1/_restore
{
    "indices": "index_1",
    "rename_pattern": "index_(.+)",
    "rename_replacement": "restored_index_$1"
}

  

# 查看恢復的狀態

GET /_recovery/restored_index_3
GET /_recovery/

  

# 取消恢復過程不管是正在備份,還是備份完成

DELETE /restored_index_3

  

elasticsearch備份與恢復