设为首页 收藏本站
查看: 996|回复: 0

[经验分享] elasticsearch数据备份恢复

[复制链接]
发表于 2019-1-29 06:50:50 | 显示全部楼层 |阅读模式
  本文主要介绍elasticsearch集群数据备份及恢复,利用共享文件系统,通过快照方式备份。
  集群的部署参考:http://hnr520.blog.运维网.com/4484939/1876467
  一、配置修改
  1.配置文件必须添加如下参数
  path.repo:  /mnt/backups/es_mybak
  二、数据备份
  1.创建备份仓库
curl -XPUT 'http://192.168.115.11:9200/_snapshot/EsBackup' -d '{  
"type": "fs",
"settings": {
    "location": "/mnt/backups/es_mybak"
    }
}'
[root@node1 local]# curl -XPUT 'http://192.168.115.11:9200/_snapshot/EsBackup' -d '{
> "type": "fs",
> "settings": {
>     "location": "/mnt/backups/es_mybak"
> }
> }'
{"acknowledged":true}  
  给我们的仓库取一个名字,在本例它叫 EsBackup 。
  我们指定仓库的类型应该是一个共享文件系统,这里采用nfs。
  最后,我们提供一个已挂载的设备(/mnt/backups/es_mybak )作为目的地址。
  注意:共享文件系统路径必须确保集群所有节点都可以访问到。
  2.查询备份仓库
[root@node1 local]# curl -XGET 'http://192.168.115.11:9200/_snapshot?pretty'
{
  "EsBackup" : {
    "type" : "fs",
    "settings" : {
      "location" : "/mnt/backups/es_mybak"
    }
  }
}  3.备份所有索引

curl -XPUT 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_all'
[root@node1 local]# curl -XPUT 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_all'
{"accepted":true}  4.查看备份快照

curl -XGET 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_all?pretty'
[root@node1 elasticsearch5]# curl -XGET 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_*?pretty'
{
  "snapshots" : [
    {
      "snapshot" : "snapshot_all",
      "uuid" : "MRTYocxBT4qgwtpu_6jdpg",
      "version_id" : 5000199,
      "version" : "5.0.1",
      "indices" : [
        "els_student_hnr05",
        "hnrtest",
        "els_student_hnr03",
        "els_student",
        "els_student_hnr02",
        "els_student_hnr04",
        "els_python01",
        "els_student_hnr01"
      ],
      "state" : "SUCCESS",
      "start_time" : "2017-05-17T10:00:46.860Z",
      "start_time_in_millis" : 1495015246860,
      "end_time" : "2017-05-17T10:00:54.209Z",
      "end_time_in_millis" : 1495015254209,
      "duration_in_millis" : 7349,
      "failures" : [ ],
      "shards" : {
        "total" : 40,
        "failed" : 0,
        "successful" : 40
      }
    }
  ]
}  5.备份部分索引

curl -XPUT 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_els_student_hnr05' -d '{ "indices": "els_student_hnr05" }'
[root@node1 elasticsearch5]# curl -XPUT 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_els_student_hnr05' -d '{ "indices": "els_student_hnr05" }'
{"accepted":true}  6.查看备份快照

curl -XGET 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_els_student_hnr05?pretty'
查看快照的详细信息,可以看到每个shard的信息
curl -XGET 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_els_student_hnr05/_status?pretty'
[root@node1 elasticsearch5]# curl -XGET 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_els_student_hnr05?pretty'   
{
  "snapshots" : [
    {
      "snapshot" : "snapshot_els_student_hnr05",
      "uuid" : "hsSkWa63Ss6MJjh0Eo4arA",
      "version_id" : 5000199,
      "version" : "5.0.1",
      "indices" : [
        "els_student_hnr05"
      ],
      "state" : "SUCCESS",
      "start_time" : "2017-05-18T00:58:35.699Z",
      "start_time_in_millis" : 1495069115699,
      "end_time" : "2017-05-18T00:58:36.396Z",
      "end_time_in_millis" : 1495069116396,
      "duration_in_millis" : 697,
      "failures" : [ ],
      "shards" : {
        "total" : 5,
        "failed" : 0,
        "successful" : 5
      }
    }
  ]
}  三、.部分索引数据恢复

  1.查询索引
curl -XGET '192.168.115.11:9200/_cat/indices?v'
health status index             uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   els_student_hnr05 mkvmTguZS4m1wGKbB8TOEw   5   1         99            0    124.7kb         62.3kb
green  open   hnrtest           Y-bjuEPLQTGGP88EafDlyg   5   1          0            0      1.5kb           795b
green  open   els_student_hnr03 _UHB6P-fRfucH7lEyE-C7g   5   1         99            0    146.7kb         73.3kb
green  open   els_student       JC69IBEjTji8jU6bxCDE3A   5   1        999            0    495.9kb        247.9kb
green  open   els_student_hnr02 k-aLl7tzRUyRfwJs8O0-kA   5   1         99            0    109.8kb         54.9kb
green  open   els_student_hnr04 zAkj7GvfQ-CqmuFMJUTSuA   5   1         99            0    162.8kb         81.4kb
green  open   els_python01      wmdREADVQmCX773_JDL46Q   5   1          0            0      1.5kb           795b
green  open   els_student_hnr01 BJlcIp7mS0ii9nDYj8UDyQ   5   1        100            0    109.2kb         54.6kb  2.删除索引els_student_hnr05
[root@node1 elasticsearch5]# curl -XDELETE 'http://192.168.115.11:9200/els_student_hnr05'
{"acknowledged":true}  3.根据snapshot_els_student_hnr05快照恢复索引

curl -XPOST 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_els_student_hnr05/_restore'
[root@node1 elasticsearch5]# curl -XPOST 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_els_student_hnr05/_restore'
{"accepted":true}  4.再次查看索引

[root@node1 elasticsearch5]# curl -XGET '192.168.115.11:9200/_cat/indices?v'
health status index             uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   hnrtest           Y-bjuEPLQTGGP88EafDlyg   5   1          0            0      1.5kb           795b
green  open   els_student_hnr05 S3AsHa4dRtuXXZ3uIDGvuQ   5   1         99            0    124.7kb         62.3kb  被删除的索引els_student_hnr05已经恢复回来
  四、数据完全恢复
  1.关闭所有节点,删除数据目录下的所有数据,重新启动集群
  kill -9 $(ps -ef | grep -v grep | grep elasticsearch | awk '{print $2}')
  2.重新启动集群

  
  3.创建备份仓库
curl -XPUT 'http://192.168.115.11:9200/_snapshot/EsBackup' -d '{
"type": "fs",
"settings": {
    "location": "/mnt/backups/es_mybak"
    }
}'  4.查看备份快照

curl -XGET 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_*?pretty'
{
  "snapshots" : [
    {
      "snapshot" : "snapshot_all",
      "uuid" : "MRTYocxBT4qgwtpu_6jdpg",
      "version_id" : 5000199,
      "version" : "5.0.1",
      "indices" : [
        "els_student_hnr05",
        "hnrtest",
        "els_student_hnr03",
        "els_student",
        "els_student_hnr02",
        "els_student_hnr04",
        "els_python01",
        "els_student_hnr01"
      ],
      "state" : "SUCCESS",
      "start_time" : "2017-05-17T10:00:46.860Z",
      "start_time_in_millis" : 1495015246860,
      "end_time" : "2017-05-17T10:00:54.209Z",
      "end_time_in_millis" : 1495015254209,
      "duration_in_millis" : 7349,
      "failures" : [ ],
      "shards" : {
        "total" : 40,
        "failed" : 0,
        "successful" : 40
      }
    },
    {
      "snapshot" : "snapshot_els_student_hnr05",
      "uuid" : "hsSkWa63Ss6MJjh0Eo4arA",
      "version_id" : 5000199,
      "version" : "5.0.1",
      "indices" : [
        "els_student_hnr05"
      ],
      "state" : "SUCCESS",
      "start_time" : "2017-05-18T00:58:35.699Z",
      "start_time_in_millis" : 1495069115699,
      "end_time" : "2017-05-18T00:58:36.396Z",
      "end_time_in_millis" : 1495069116396,
      "duration_in_millis" : 697,
      "failures" : [ ],
      "shards" : {
        "total" : 5,
        "failed" : 0,
        "successful" : 5
      }
    }
  ]
}  5.恢复数据
curl -XPOST 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_all/_restore'  6.查询索引

[root@node1 elasticsearch5]# curl -XGET '192.168.115.11:9200/_cat/indices?v'
health status index             uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   hnrtest           LNkwevA2Sr2Jgue1oLRIGA   5   1          0            0      1.5kb           795b
green  open   els_student       6aE8M7KMRN2EdievhDBXcw   5   1        999            0    495.9kb        247.9kb
green  open   els_student_hnr04 8hXeVjXYRhS5POdy3hnMuQ   5   1         99            0    162.8kb         81.4kb
green  open   els_student_hnr01 afVLqgxpTqii6pNObLC2sA   5   1        100            0    109.2kb         54.6kb
green  open   els_student_hnr05 jzHPY_TlSEm-ZEXWz0sz4Q   5   1         99            0    124.7kb         62.3kb
green  open   els_student_hnr02 f3hqeM1pQkWttZifnCCQDQ   5   1         99            0    109.8kb         54.9kb
green  open   els_python01      4_vFwhn0RCi3SZbz2bORCw   5   1          0            0      1.5kb           795b
green  open   els_student_hnr03 esFyZMwwTaeLf7YrKxyYjQ   5   1         99            0    146.7kb         73.3kb
至此所有索引已经完全恢复  
  

  五、从全部索引快照中恢复单个索引
  1.删除索引els_student_hnr05
curl -XDELETE 'http://192.168.115.11:9200/els_student_hnr05'  2.恢复被删除的索引els_student_hnr05

curl -XPOST 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_all/_restore' -d '{
    "indices": "els_student_hnr05",
    "rename_replacement": "restored_index_$1"
}'  六、删除快照
curl -XDELETE 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_els_student_hnr05'
curl -XDELETE 'http://192.168.115.11:9200/_snapshot/EsBackup/snapshot_all'  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-668868-1-1.html 上篇帖子: centos7安装elasticsearch 下篇帖子: 安装和使用 Elasticsearch
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表