elasticsearch备份恢复

1、重新导入数据

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

ignore_unavailable设置为true,如果某些索引不可用,恢复过程还是会成功的。
通过include_global_state存储了集群的state,还会同时恢复一些template。
rename_pattern正则匹配的索引,rename_replacement重命名后的索引。index_01 -> restores_index_01

这个restore过程也是在后台运行的,如果要在前台等待它运行完,那么可以加上wait_for_completion flag:
POST _snapshot/my_backup/snapshot_1/_restore?wait_for_completion=true。
restore过程只能针对已经close掉的index来执行,而且这个index的shard还必须跟snapshot中的index的shard
数量是一致的。restore操作会自动在恢复好一个index之后open这个index,或者如果这些index不存在,那么就会自动创建这些index

默认情况下,如果某个索引在恢复的时候,没有在snapshot中拥有所有的shard的备份,那么恢复操作就会失败,
比如某个shard恢复失败了。但是可以将partial设置为true。

2、监控restore的进度

从一个仓库中恢复数据,其实内部机制跟从其他的node上恢复一个shard是一样的。如果要监控这个恢复的过程,可以用recovery api,
比如:GET restored_index_3/_recovery。如果要看所有索引的恢复进度:GET /_recovery/。可以看到恢复进度的大致的百分比。结果大致如下所示:

curl -XGET 'http://es02:9200/my_index/_recovery?pretty'

3、取消恢复过程

如果要取消一个恢复过程,那么需要删除已经被恢复到es中的数据。因为一个恢复过程就只是一个shard恢复,发送一个delete操作删除那个索引即可,
比如:DELETE /restored_index_3。如果那个索引正在被恢复,那么这个delete命令就会停止恢复过程,然后删除已经恢复的 所有数据。

curl -XDELETE 'http://elasticsearch02:9200/my_index'

猜你喜欢

转载自blog.csdn.net/fantasticqiang/article/details/80468862