ES升级--05--快照生成 和备份

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


备份ES数据

1.关闭集群自动均衡

有密码加上 -u ‘elastic:escdms’

curl -XPUT "http://192.168.2.89:9200/_cluster/settings?pretty" -H 'Content-Type:application/json' -d '{
  "persistent": {
    "cluster.blocks.read_only": true,
    "cluster.routing.rebalance.enable": "none"
  },
  "transient": {
    "cluster.blocks.read_only": true,
    "cluster.routing.rebalance.enable": "none"
  }
}'

curl命令可以在kibana平台替换为如下命令:

PUT /_cluster/settings
{
  "persistent": {
    "cluster.blocks.read_only": true,
    "cluster.routing.rebalance.enable": "none"
  },
  "transient": {
    "cluster.blocks.read_only": true,
    "cluster.routing.rebalance.enable": "none"
  }
}

在这里插入图片描述

2.执行同步刷新

curl -X POST "http://192.168.2.89:9200/_flush/synced"
POST /_flush/synced

在这里插入图片描述

3.停止集群节点的Elasticsearch服务

ps aux | grep elasticsearch
kill -9  xxxxxx
pkill -f elasticsearch 

4.修改Elasticsearch配置文件,开启快照功能,配置仓库目录为共享存储

如果没有这个

# 设置备份路径
path.repo: ["/home/data/elastic-6.3.2/mybackup"]

5.重启集群节点的Elasticsearch服务

bin/elasticsearch -d

6.通开启集群分片重建、恢复集群写入配置

先执行

curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings -d '{
  "persistent": {
    "cluster.blocks.read_only": false
  }
}'

后执行

curl -XPUT "http://192.168.2.89:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d '{
  "persistent": {
    "cluster.blocks.read_only": false,
    "cluster.routing.rebalance.enable": "ALL"
  },
  "transient": {
     "cluster.blocks.read_only": false,
    "cluster.routing.rebalance.enable": "ALL"
  }
}'
PUT /_cluster/settings
{
  "persistent": {
    "cluster.blocks.read_only": false,
    "cluster.routing.rebalance.enable": "ALL"
  },
  "transient": {
     "cluster.blocks.read_only": false,
    "cluster.routing.rebalance.enable": "ALL"
  }
}

在这里插入图片描述

7.注册快照存储

  • 通过http提交注册快照存储,需指定到快照仓库目录下
curl -X PUT "http://192.168.2.89:9200/_snapshot/mybackup" -H 'Content-Type: application/json'  -d'
{
  "type": "fs",
  "settings": {
    "location": "/home/data/elastic-6.3.2/mybackup"
  }
}'

8.执行快照

  • IaaS环境执行生成快照,通过http提交,第一次为全量,后面再执行则为增量
curl -XPUT "http://192.168.2.89:9200/_snapshot/mybackup/snapshot_20240606?wait_for_completion=true"  -H 'Content-Type: application/json' -d '{
  "ignore_unavailable": true,
  "include_global_state": true
}'

在这里插入图片描述
也可以选定某个索引

curl -XPUT "http://192.168.2.54:9200/_snapshot/my_backup/snapshot_20240607?wait_for_completion=true"  -H 'Content-Type: application/json' -d '{
  "indices": "cbsp_appform_index",
  "ignore_unavailable": true,
  "include_global_state": true
}'

在这里插入图片描述

9.查看快照执行情况

有密码加上 -u ‘elastic:escdms’

curl -X GET "http://192.168.2.89:9200/_snapshot/mybackup/_all" 
GET _snapshot/mybackup/_all

在这里插入图片描述

10 删除多余快照

  • 查看所有快照仓库
GET _snapshot/_all

在这里插入图片描述

  • 查看此仓库的快照情况
GET _snapshot/my_backup/_all
  • 删除之前的有的快照
curl -X DELETE "localhost:9200/_snapshot/<repository_name>/*"
DELETE /_snapshot/<repository_name>/*

恢复数据 ----环境es7.9

1.将备份数据复制到新版es目录

  • app账号登录新环境,将备份数据复制到新版es目录

传输用rsync

安装命令

sudo yum install rsync

在这里插入图片描述

传输命令 :账号 root ,会弹窗口要求输入密码

rsync -avz /home/data/elastic-6.3.2/es_bak  root@192.168.2.79:/home/es/

在这里插入图片描述

检查文件夹和权限

等待传输完成 查看文件夹

/data/es/mybackup
  • 注意文件夹和权限问题

在这里插入图片描述

  • 注意权限
chown -R es:es  /data/es    

2.elasticsearch.yml 配置

path.repo: ["/data/es/mybackup"]

3.重新启动es服务

 bin/elasticsearch -d

4.注册备份仓库

curl -XPUT "http://192.168.2.79:9200/_snapshot/mybackup" -H 'Content-Type: application/json' -d '{
  "type": "fs",
  "settings": {
    "location": "/data/es/mybackup"
  }
}'

在这里插入图片描述

5.恢复数据

  • mybackup :备份仓库
  • snapshot_20240607:快照版本
curl -XPOST "http://192.168.2.79:9200/_snapshot/mybackup/snapshot_20240607/_restore" -H 'Content-Type: application/json' -d '{
  "ignore_unavailable": true,
  "include_global_state": true
}'

在这里插入图片描述

可以制定恢复索引

curl -XPOST "http://192.168.2.89:9200/_snapshot/mybackup/snapshot_20240606/_restore" -H 'Content-Type: application/json' -d '{
  "indices": "laas_*",
  "ignore_unavailable": true,
  "include_global_state": true
}'

如果出现索引重复 导致报错

curl -XPOST "http://192.168.2.89:9200/_snapshot/mybackup/snapshot_20240606/_restore" -H 'Content-Type: application/json' -d '{
  "ignore_unavailable": true,
  "include_global_state": true,
  "rename_pattern": ".monitoring-es-6-2024.06.06",
  "rename_replacement": "restored_monitoring_es"
}'

4. 验证

http://192.168.2.79:9200/_cat/indices?v
http://192.168.2.79:9200/cbsp_appform_index/_count
http://192.168.2.79:9200/cbsp_appform_index/_search?q=:&pretty

在这里插入图片描述

相关推荐

  1. 服务器的云备份快照有哪些区别?

    2024-06-11 20:06:02       32 阅读
  2. Elasticsearch(ES)数据备份迁移

    2024-06-11 20:06:02       24 阅读
  3. ubuntu server 20.04 备份恢复 系统 LTS

    2024-06-11 20:06:02       47 阅读
  4. 使用elasticsearch-dump工具备份ES数据库

    2024-06-11 20:06:02       63 阅读
  5. 09ES6:Set Map 数据结构

    2024-06-11 20:06:02       48 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-11 20:06:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-11 20:06:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-11 20:06:02       82 阅读
  4. Python语言-面向对象

    2024-06-11 20:06:02       91 阅读

热门阅读

  1. 电商财务管理---云账户系统

    2024-06-11 20:06:02       28 阅读
  2. C++多线程并发

    2024-06-11 20:06:02       20 阅读
  3. springboot链接kafka异步发送消息

    2024-06-11 20:06:02       30 阅读
  4. CSS弹窗

    CSS弹窗

    2024-06-11 20:06:02      26 阅读
  5. python:大文件分批/块导入数据库方式记录

    2024-06-11 20:06:02       33 阅读
  6. SpringBoot集成mongodb

    2024-06-11 20:06:02       31 阅读
  7. mysql(54) : dbcp多实例使用

    2024-06-11 20:06:02       22 阅读
  8. 箭头函数 this

    2024-06-11 20:06:02       27 阅读
  9. 高通Android 12应用保活时序问题踩坑

    2024-06-11 20:06:02       29 阅读
  10. R语言中的dplyr包函数总结

    2024-06-11 20:06:02       33 阅读
  11. 多人中招!企业裁员前的十大征兆!

    2024-06-11 20:06:02       25 阅读
  12. 这些Linux知识可不是靠背就会的!

    2024-06-11 20:06:02       28 阅读
  13. web前端开发转正申请:成长、挑战与未来展望

    2024-06-11 20:06:02       30 阅读