ES的快照和恢复

个人学习笔记,谢绝转载!!!

原文:https://www.cnblogs.com/wshenjin/p/16072599.html


创建快照仓库

curl -H "Content-Type: application/json" -XPOST  http://127.0.0.1:9200/_snapshot/EsSnapshot -d '{
  "type": "fs",
  "settings": {
      "compress" : "true",
        "location": "/data/backup/elasticsearch_snapshot"
  }
}'

共享文件系统仓库(“type”: “fs”)使用共享文件系统存快照,如果要注册共享文件系统仓库,必须在所有master和data节点挂载相同的共享文件系统到同一个路径位置。
这个路径位置(或者它的一个父目录)必须在所有master和data节点的path.repo设置上注册。

查看快照仓库

curl -XGET http://127.0.0.1:9200/_snapshot

查看快照仓库列表

curl 127.0.0.1:9200/_cat/repositories?v

删除快照仓库

curl -XDELETE http://127.0.0.1:9200/_snapshot/EsSnapshot

创建快照

curl -H "Content-Type: application/json" -XPUT http://127.0.0.1:9200/_snapshot/EsSnapshot/snapshot_20220328?wait_for_completion=true -d '{
  "indices":"index1,index2",  ##不写就全部
  "ignore_unavailable": true,
  "include_global_state": false
}' 

indices:指定要包含到快照的索引列表
ignore_unavailable:设置为 true 时,在创建快照时会忽略不存在的索引。默认情况下,如果选项 ignore_unavailable 没有设值,一个索引缺失,快照请求会失败。
include_global_state:为 false,可以阻止集群全局状态信息被保存为快照的一部分。默认情况下,如果如果一个快照中的一个或者多个索引没有所有主分片可用,整个快照创建会失败,该情况可以通过设置 partial 为 true 来改变。

查看快照

curl -XGET http://127.0.0.1:9200/_snapshot/EsSnapshot/snapshot_20220328

删除快照

curl -XDELETE http://127.0.0.1:9200/_snapshot/EsSnapshot/snapshot_20220328

从快照中恢复

curl -H "Content-Type: application/json" -XPOST http://127.0.0.1:9200/_snapshot/EsSnapshot/snapshot_20220328/_restore?wait_for_completion=true  -d '{
  "indices":"index1,index2"  ##不写就全部
}'

默认情况下,快照中的所有索引将被恢复,集群状态不被恢复。
可以通过在恢复请求中使用 indices 和 include_global_state 选项来指定要恢复的索引和允许恢复集群全局状态。
索引列表支持多索引语法: rename_pattern 和 rename_replacement 选项在恢复时通过正则表达式来重命名索引。
设置 include_aliases 为 false 可以防止与索引关联的别名被一起恢复。

posted @ 2022-03-29 16:37  wshenJin  阅读(1402)  评论(0编辑  收藏  举报