首页 > 其他分享 >ElasticSearch 快照 备份、恢复数据

ElasticSearch 快照 备份、恢复数据

时间:2022-09-22 16:48:09浏览次数:73  
标签:index rw 快照 备份 ElasticSearch ecopherebbs snapshot es

ElasticSearch 设置备份文件地址 

  • 在elasticsearch.yml 新增
    path.repo: ["/home/es/snapshot"]

    注册快照存储库

    PUT _snapshot/ecopherebbs
    {
      "type": "fs",
      "settings": {
          "location": "/home/es/snapshot"
      }
    }
    保存成功

查看快照存储库保存结果 

GET _snapshot 

返回结果 

{
  "ecopherebbs" : {
    "type" : "fs",
    "settings" : {
      "location" : "/home/es/snapshot"
    }
  }
} 

创建快照 

异步创建 

  • 创建
    PUT _snapshot/ecopherebbs/snapshot_20210631
    {
    "ignore_unavailable": true,
     "include_global_state": true
    }
  • 查看状态
GET _snapshot/ecopherebbs/snapshot_20210631 

处理中 

{
  "snapshots" : [
    {
      "snapshot" : "snapshot_20210631",
      "uuid" : "PTBkWV-pQ8CQ7l4RNxISfA",
      "version_id" : 7090399,
      "version" : "7.9.3",
      "indices" : [
        "t_e_s_t___2_0_2_1_0_4_2_1_0_9_2_9_index",
        "test0627",
        "test110",
        ".kibana-event-log-7.9.3-000001",
        "fang_fa_index",
        "filebeat-7.9.3-2021.06.29-000001",
        "gateway_requests",
        "my_index",
        "ilm-history-2-000003",
        ".kibana-event-log-7.9.3-000002",
        ".kibana_1"
      ],
      "data_streams" : [ ],
      "include_global_state" : true,
      "state" : "IN_PROGRESS",
      "start_time" : "2021-06-30T05:26:10.530Z",
      "start_time_in_millis" : 1625030770530,
      "end_time" : "1970-01-01T00:00:00.000Z",
      "end_time_in_millis" : 0,
      "duration_in_millis" : 0,
      "failures" : [ ],
      "shards" : {
        "total" : 0,
        "failed" : 0,
        "successful" : 0
      }
    }
  ]
}

处理完成 

{
  "snapshots" : [
    {
      "snapshot" : "snapshot_20210631",
      "uuid" : "PTBkWV-pQ8CQ7l4RNxISfA",
      "version_id" : 7090399,
      "version" : "7.9.3",
      "indices" : [
        "t_e_s_t___2_0_2_1_0_4_2_1_0_9_2_9_index",
        "test0627",
        "test110",
        ".kibana-event-log-7.9.3-000001",
        "fang_fa_index",
        "filebeat-7.9.3-2021.06.29-000001",
        "gateway_requests",
        "my_index",
        "ilm-history-2-000003",
        ".kibana-event-log-7.9.3-000002",
        ".kibana_1"
      ],
      "data_streams" : [ ],
      "include_global_state" : true,
      "state" : "SUCCESS",
      "start_time" : "2021-06-30T05:26:10.530Z",
      "start_time_in_millis" : 1625030770530,
      "end_time" : "2021-06-30T05:26:16.937Z",
      "end_time_in_millis" : 1625030776937,
      "duration_in_millis" : 6407,
      "failures" : [ ],
      "shards" : {
        "total" : 200,
        "failed" : 0,
        "successful" : 200
      }
    }
  ]
} 

指定索引进行快照 

PUT _snapshot/ecopherebbs/snapshot_20210630?wait_for_completion=true
{
  "indices": "index1,index2",
  "ignore_unavailable": true,
   "include_global_state": true
} 
  1. wait_for_completion=true时会一直阻塞直到快照完成,kibana执行时超时为30秒,超时后快照依然会在后台执行
  2. snapshot_20200729 就是指定的备份快照命中
  3. 请求体重indices指定需要备份的索引(多个用逗号隔开),也可以不指定,这样会备份所有的es索引库数据

 

在服务器查看备份的数据 

每次执行快照都会生成一个 meta和一个snap文件 

[es@test12 snapshot]$ ls -lrt
总用量 1404
drwxrwxr-x. 62 es es   4096 6月  30 13:23 indices
-rw-rw-r--.  1 es es 460329 6月  30 13:24 meta--WCM58RpQNm5bEywCjO_cg.dat
-rw-rw-r--.  1 es es   1596 6月  30 13:24 snap--WCM58RpQNm5bEywCjO_cg.dat
-rw-rw-r--.  1 es es   1596 6月  30 13:26 snap-PTBkWV-pQ8CQ7l4RNxISfA.dat
-rw-rw-r--.  1 es es 460329 6月  30 13:26 meta-PTBkWV-pQ8CQ7l4RNxISfA.dat
-rw-rw-r--.  1 es es    302 6月  30 13:52 snap-N3zRMDnDTEqoiShEwjKosA.dat
-rw-rw-r--.  1 es es 460329 6月  30 13:52 meta-N3zRMDnDTEqoiShEwjKosA.dat
-rw-rw-r--.  1 es es  24990 6月  30 13:52 index-2
-rw-rw-r--.  1 es es      8 6月  30 13:52 index.latest 

恢复数据 

本机恢复 

POST _snapshot/ecopherebbs/snapshot_20210631_02/_restore

执行恢复要将之前的索引删除,否则会报错 

POST /_snapshot/my_backup/snapshot_1/_restore
{
    "indices": "index_1", 
    "rename_pattern": "index_(.+)", 
    "rename_replacement": "restored_index_$1" 
} 

其他服务器恢复 

  1. 配置第一步设置的目录 path.repo: ["/home/es/snapshot"]
  2. 创建仓库
    PUT _snapshot/ecopherebbs
    {
     "type": "fs",
     "settings": {
         "location": "/home/es/snapshot-test"
     }
    }
  3. 执行恢复索引
    POST _snapshot/ecopherebbs/snapshot_20210631_02/_restore

    常见问题

    报错 doesn't match any of the locations specified by path.repo because this setting is empty

    {
    "error" : {
     "root_cause" : [
       {
         "type" : "repository_exception",
         "reason" : "[ecopherebbs] location [/home/es/snapshot] doesn't match any of the locations specified by path.repo because this setting is empty"
       }
     ],
     "type" : "repository_exception",
     "reason" : "[ecopherebbs] failed to create repository",
     "caused_by" : {
       "type" : "repository_exception",
       "reason" : "[ecopherebbs] location [/home/es/snapshot] doesn't match any of the locations specified by path.repo because this setting is empty"
     }
    },
    "status" : 500
    } 

``` 

  • 解决方法:

    在为es集群环境做灾备和恢复时候,首先需要创建创建一个仓库,并往仓库中存放快照(每个快照中会区分不同的索引)。但是在创建仓库的时候,要求仓库的地址必须在每个集群环境中的elasticsearch.yml中进行配置

标签:index,rw,快照,备份,ElasticSearch,ecopherebbs,snapshot,es
From: https://www.cnblogs.com/yuarvin/p/16719840.html

相关文章

  • elasticsearch的.security-7索引崩溃恢复笔记
    装了es三方插件重启后出现以下问题failedtoauthenticateuser[elastic]failedtoretrievepasswordhashforreserveduser[elastic]org.elasticsearch.action.......
  • Windows - 部署 Elasticsearch
    Windows-部署Elasticsearch                                      引用:https://blog......
  • MySql 数据备份
    相关命令的执行都在windows服务器下,且工作目录就是mysqlserver的bin目录下.1、mysqldump全备份mysqldump-h127.0.0.1-u用户名-p"密码"数据库名称有表的话写表......
  • elasticsearch生成证书的两种方式
    1.elasticsearch-certgen方式注意:这种方式如果以后新增节点导致证书得重新生成并放到es所有节点2.elasticsearch-certutil方式##(1)创建证书$pwd/alidata1/admin......
  • MYSQL备份(直接拷贝数据库文件
    目的:把A机中的库转移到B机中。1、停止mysql服务,在A机mysql安装目录下,找到my.ini文件打开,在此文件中找到datadir,把这个路径下的数据文件:ibdata1以及所有文件夹拷贝到B机中d......
  • linux系统管理类-备份策略
    1.如果一个系统没有任何的备份策略,请写出一个较为全面合理的备份方案!通用的系统数据目录-必须要备份的1.如果是数据库服务器:需要备份这些差异备份好处是,原始文件大......
  • elasticsearch8.1源码编译笔记
    环境idea2022.1.3jdk17macos10.14.6gradle7.4.2(代码自动下载)前置准备idea设置JDK17idea设置gradleJVM为ProjectJVMgradle设置aliyun加速(可选),有时设......
  • xtrabackup 8.0 备份恢复与原理介绍
    https://www.modb.pro/db/102109 1.备份工具特性对比2.工作过程PerconaXtraBackup是基于InnoDB的崩溃恢复功能的,它复制InnoDB数据文件,这导致数据内部不一致;然后,它对......
  • ElasticSearch安装使用
    要吃多少根冰棍才能说出如此冰冷刺骨的话语简介有了mysql,为什么还要用elasticsearch?mysql更多是用来存储数据,在数据量过多的时候,使用ES来检索数据(快)。ES基本概念In......
  • 您在 Elasticsearch 中的数据库数据
    您在Elasticsearch中的数据库数据如果您像我一样喜欢Elasticsearch的灵活性和可扩展性。与Kibana搭配使用,它成为利用数据的完美工具,即使对于非技术人员也是如此。......