0


ES快照备份及恢复(ES数据迁移)

迁移步骤说明:

  1. 需搭建共享目录新旧集群共6台服务器需要读写权限
  2. 新旧ES集群配置仓库路径,配置文件elasticsearch.yml
  3. 旧集群注册快照仓库
  4. 旧集群创建快照A(snapshot_A.2023****)
  5. 新集群注册快照仓库
  6. 新集群恢复快照A(snapshot_A.2023****)
  7. 新集群接入服务后需再次在旧集群备份快照B(snapshot_B.2023****)
  8. 新集群恢复快照B(snapshot_B.2023****),因快照恢复会删除原有同名索引,恢复时需要重命名索引文件
  9. 新集群合并索引数据(reindex)

ES配置仓库

elasticsearch.yml

#挂载的共享目录,新旧集群每台都需要配置

配置项:path.repo: /filehome/ods/tmap

注册仓库

curl -u elastic:Cfca@Es1234 -XPUT '10.241.132.75: 9200/_snapshot/imp' -H 'content-Type:application/json' -d '{

"type": "fs",

"settings": {

    "location": " /filehome/ods/tmap/imp",

    "compress": "true",

    "max_restore_bytes_per_sec": "50mb",

    "max_snapshot_bytes_per_sec": "50mb"

}

}'

仓库相关操作

查看仓库

curl -u elastic:Cfca@Es1234 -XGET '10.241.132.75:9200/_snapshot/_all?pretty'

删除仓库

#多集群操作后仓库数据发生变化注销仓库,后重新注册(注销仓库不会删除仓库下快照)

curl -u elastic:Cfca@Es1234 -XDELETE '10.241.132.75:9200/_snapshot/exp'

创建快照

#全量索引创建快照,es根据已创建快照增量备份

curl -u elastic:Cfca@Es1234 -XPUT '10.241.132.75:9200/_snapshot/exp/snapshot_1?wait_for_completion=true'

#指定索引创建快照

curl -u elastic:Cfca@Es1234 -XPUT '10.241.132.75:9200/_snapshot/exp/snapshot_75?wait_for_completion=true' -H 'content-Type:application/json' -d '{ "indices": "index1,index2,..,… "}'

快照相关操作

查询快照

curl -u elastic:Cfca@Es1234 -XGET '10.241.22.17:9200/_snapshot/exp/_all?pretty'

删除快照

curl -u elastic:Cfca@Es1234 -XDELETE '10.241.132.75:9200/_snapshot/exp/snapshot_1'

恢复快照

快照全量恢复

curl -u elastic:Cfca@Es1234 -XPOST '10.241.22.17:9200/_snapshot/exp/snapshot_75/_restore'

指定索引恢复

curl -u elastic:Cfca@Es1234 -XPOST '10.241.22.17:9200/_snapshot/exp/snapshot_75/_restore' -H 'content-Type:application/json' -d '{"indices":"eventindex"}'

恢复时重命名

#二次恢复时将索引重命名防止删除已恢复数据

curl -u elastic:Cfca@Es1234 -X POST "10.241.22.17:9200/_snapshot/exp/snapshot_17.20230227/_restore?pretty" -H 'Content-Type: application/json' -d'

{

"indices": "index1,index2,…",

"rename_pattern": "(.+)",

"rename_replacement": "restored-$1"

}'

合并索引

#reindex将restored-tradeindex索引数据合并到tradeindex,****不会对tradeindex原数据修改

curl -u elastic:Cfca@Es1234 -X POST "10.241.22.17:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'

{

"source": {

"index": "restored-tradeindex"

},

"dest": {

"index": "tradeindex"

}

}'

索引相关操作

查询全量索引

curl -u elastic:Cfca@Es1234 '10.241.22.17:9200/_cat/indices?v'

查询索引状态

curl -u elastic:Cfca@Es1234 -XGET '10.241.22.17:9200/_cat/indices/eventindex?v'

打开/关闭索引

#open/close

curl -u elastic:Cfca@Es1234 -XPOST '10.241.22.17:9200/eventindex/_close?pretty

删除索引

#慎用通配符,_all,防止误删*

curl -u elastic:Cfca@Es1234 -XDELETE '10.241.22.17:9200/index,habit*'


本文转载自: https://blog.csdn.net/qq_25782465/article/details/129261471
版权归原作者 下里巴人在种菜 所有, 如有侵权,请联系我们删除。

“ES快照备份及恢复(ES数据迁移)”的评论:

还没有评论