上次了解了在windows下用elasticSearch-head为elasticSearch备份数据,那么这次就来用elasticSearch-head为elasticSearch还原数据。
还原同样依赖于库,但是这里没有其它机器就是在这个机器上面的,由于之前备份就是直接在这个机器上面备份的,所以这里就不需要建立库了。直接用之前的my_backup库进行还原了。
_snapshot/my_backup/snapshot_1_restore?wait_for_completion=true POST
{}

这里就是说要用一个现成的库去还原,这里由于之前备份时候用的就是1,所以这里标记红色的位置也是1,用相同的号来还原。
当然,这里一般都会成功恢复,但是这里遇到了问题,可能是我是单机的情况,可能是我是windows版本的情况,可能我的是最新的7.14.0的原因,总之发现一个问题就是,你创建的快照之后,如果你删除了索引或者索引里面的数据,那么你创建的这个快照也将会对应删除对应的索引或者快照
那么经过一番的研究,其实可能与elasticSearch的版本有关
关于恢复快照上面的是请求url是:_snapshot/my_backup/snapshot_1_restore?wait_for_completion=true
而实际上还有另外一种方式的请求url:_snapshot/my_backup/snapshot_1/_restore?wait_for_completion=true
而我这个elasticSearch使用第一个没有报错,是因为它相当于又一次备份了名叫snapshot_1_restore的快照。。。
那么虽然你使用第二个方式_snapshot/my_backup/snapshot_1/_restore?wait_for_completion=true有可能会报错:
{
"error": {
"root_cause": [
{
"type": "snapshot_restore_exception",
"reason": "[my_backup:snapshot_5_restore/eBpTnXNtS0-Ab564KjouzQ] cannot restore index [movies] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"
}
],
"type": "snapshot_restore_exception",
"reason": "[my_backup:snapshot_5_restore/eBpTnXNtS0-Ab564KjouzQ] cannot restore index [movies] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"
},
"status": 500
}
这个错误你要仔细看“already exists in the cluster”不要一味的认为是这个方式有问题,我刚开始就是太简单的认为这个方式有问题,没有过多的查看具体错误详情。其实看了错误详情才知道,其实就是说如果你进行恢复所用的快照中对应某个索引,如果在当前elasticSearch中还存在,那么就会冲突的。
这个就和mysql有点不一样了,mysql对于这种情况好像是先判断是否存在,不存在就创建,mysql这个比较灵活,可以定义,一般默认就是判断是否存在,不存在就自动创建。
那么这里第二种的这种恢复快照的方式,其实可以在请求正文种指定只恢复某几个索引,如:
{
"indices": "schools_gov,movies"
}
像这样我只恢复schools_gov和movies,因为这两个正好就是被我已经删除了的,不会冲突了。
关键字词:windows,elasticSearch-head,elasticSearch,还原,恢复