ES快照备份恢复,快照备份存放于Ucloud的UFile,所以本文仅适用于存放在UFile中,其他类似;
参考文档:
https://www.elastic.co/guide/cn/elasticsearch/guide/current/_restoring_from_a_snapshot.html
https://docs.ucloud.cn/analysis/ues/plugins/ufile
https://github.com/ufilesdk-dev/elasticsearch-repository-ufile
创建备份仓库:
curl -XPUT localhost:9200/_snapshot/my_backup -H 'Content-type':'application/json' -d'{"type": "ufile","settings": {"endpoint": "bucket域名","public_key": "令牌公钥","private_key": "令牌私钥","bucket": "bucket名称", "compress": true, "chunk_size":"500mb", "base_path": "es", "max_snapshot_bytes_per_sec": "500mb", "max_restore_bytes_per_sec": "500mb"}}'
type为fs时:
curl -XPUT localhost:9200/_snapshot/es_backup -H 'Content-type':'application/json' -d'{"type": "fs", "settings": {"location":"/mnt/elastic","max_snapshot_bytes_per_sec" : "300mb","max_restore_bytes_per_sec" : "300mb" }}'
当出现如下报错:
{"error":{"root_cause":[{"type":"exception","reason":"failed to create blob container"}],"type":"exception","reason":"failed to create blob container","caused_by":{"type":"access_denied_exception","reason
原因:备份文件写入目录没权限,将备份目录所属用户改为与es相同的即可,
chown -R elastic:elastic /mnt/elastic
注意:1、type为ufile,若用nfs做共享存储,type应为fs
2、endpoint写的地址,一定要转换为ufile内网地址,不然传输会很慢很慢
创建快照:
curl -X PUT http://localhost:9200/_snapshot/my_backup/categorys1113 -d '{"indices": "categorys"}'
恢复快照:
curl -X POST http://localhost:9200/_snapshot/my_backup/categorys1113/_restore -d '{"indices":"categorys","rename_pattern":"categorys", "rename_replacement": "categorys1113" }'
查看快照恢复状态
curl -X GET http://localhost:9200/_snapshot/my_backup/_all?pretty
查看快照恢复情况:
curl -X GET http://localhost:9200/ecarx_musics_new/_recovery
如果恢复是报错如下:
先关闭索引,等快照恢复完成后再打开
关闭索引:
curl -X POST http://localhost:9200/ecarx_musics_new/_close
打开索引:
curl -X POST http://localhost:9200/ecarx_musics_new/_open
PS:命令在es-head或者es服务端机器执行都可以