elasticsearch 快照和恢复

编辑于 2022-02-22 12:56:38 阅读 1384

前提

如果你想使用快照和存储,你必须设置path.repo

vi elasticsearch.yml
path.repo: ["/usr/share/elasticsearch/backup"]

然后重启elasticsearch使生效

存储

创建存储
  • 存储名称:datasvr
  • 存储路径:/usr/share/elasticsearch/backup
  • max_restore_bytes_per_sec:40M
  • max_snapshot_bytes_per_sec:40M
  • 是否压缩compress:是
curl -H "Content-Type: application/json" -XPUT 'http://localhost:9200/_snapshot/datasvr' -d ' {"type":"fs","settings":{"location":"/usr/share/elasticsearch/backup","compress":true}}'
浏览器中查看存储信息
http://localhost:9200/_snapshot/datasvr/
删除存储
  • 存储名称:datasvr

仓库被注销时,ElasticSearch 只删除仓库存储快照的引用位置,快照本身没有被删除并且在原来的位置

curl -X DELETE "http://localhost:9200/_snapshot/datasvr"

快照

快照是基于存储的,一个存储下面可以创建多个快照

创建快照(备份索引)
  • 存储名称:datasvr
  • 快照名称:snapshot_1
备份指定索引
curl -H "Content-Type:application/json" -XPUT 'http://localhost:9200/_snapshot/datasvr/snapshot_1' -d '{"indices": "article"}'

备份全部索引
curl -H "Content-Type:application/json" -XPUT 'http://localhost:9200/_snapshot/datasvr/snapshot_1'
查看仓库存储的所有快照
浏览器中查看备份仓库所有快照信息
http://localhost:9200/_snapshot/datasvr/_all

浏览器中查看备份仓库某个快照信息
http://localhost:9200/_snapshot/datasvr/snapshot_1

删除快照
curl -X DELETE "http://localhost:9200/_snapshot/datasvr/snapshot_1"
恢复快照
恢复全部
curl -H "Content-Type:application/json" -XPOST 'http://localhost:9200/_snapshot/datasvr/snapshot_1/_restore'


恢复指定索引
curl -H "Content-Type:application/json" -XPOST 'http://localhost:9200/_snapshot/datasvr/snapshot_1/_restore' -d '{"indices": "article"}'

https://www.elastic.co/guide/en/elasticsearch/reference/7.17/snapshot-restore.html

广而告之,我的新作品《语音助手》上架Google Play了,欢迎下载体验