Elasticsearch集群数据备份与恢复的方法是什么

发布时间:2021-12-16 10:17:31 作者:iii
来源:亿速云 阅读:312

本篇内容主要讲解“Elasticsearch集群数据备份与恢复的方法是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Elasticsearch集群数据备份与恢复的方法是什么”吧!

简介

实战

1 创建原始索引并导入数据

PUT _template/blog-template
{
  "index_patterns": [
    "blog-*"
  ],
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  },
  "mappings": {
    "dynamic_templates": [
      {
        "integers": {
          "match": "int_*",
          "mapping": {
            "type": "integer"
          }
        }
      },
      {
        "strings": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    ],
    "properties": {
      "title": {
        "type": "text"
      }
    }
  }
}

PUT blog-test
POST blog-test/_bulk
{"index":{}}
{"title":"elasticsearch best practice","author_firstname":"tony","author_lastname":"song","tags":"elasticsearch ,logstash","int_age":18,"locale":"zh,en"}
{"index":{}}
{"title":"elastic stack release V5","author_firstname":"shay","author_lastname":"banon","tags":"elk ,elasticsearch,release","int_age":28,"locale":"zhc,en"}
{"index":{}}
{"title":"kibana tutorial","author_firstname":"zen","author_lastname":"wei","tags":"","int_age":38,"locale":"zhc,en"}

GET blog-test
GET blog-test/_search

2 修改elasticsearch配置文件

修改 elasticsearch.yml 配置文件,增加如下配置:

path.repo: ["/home/elastic/backup"]

重启elasticsearch进程,查看创建的repo:

GET _cluster/settings?include_defaults&filter_path=*.path.repo

#输出结果:
{
  "defaults" : {
    "path" : {
      "repo" : [
        "/home/elastic/backup"
      ]
    }
  }
}

3 创建关联 repository

#创建关联 repository
PUT /_snapshot/my_fs_backup
{
    "type": "fs",
    "settings": {
        "location": "/home/elastic/backup/my_fs_backup",
        "compress": true
    }
}

查看创建的关联:

GET _snapshot/my_fs_backup

#输出结果:
{
  "my_fs_backup" : {
    "type" : "fs",
    "settings" : {
      "compress" : "true",
      "location" : "/home/elastic/backup/my_fs_backup"
    }
  }
}

查看在哪个node上创建了关联:

POST _snapshot/my_fs_backup/_verify

#输出结果
{
  "nodes" : {
    "pMrJwVGSQcSgeTZdh71QRw" : {
      "name" : "node1"
    }
  }
}

4 执行 snapshot

#创建snapshot_1对blog-test索引做快照
PUT /_snapshot/my_fs_backup/snapshot_1?wait_for_completion=true
{
  "indices": "blog-test",
  "ignore_unavailable": true,
  "include_global_state": false
}

查看创建的快照:

GET /_snapshot/my_fs_backup/snapshot_*
#GET /_snapshot/my_fs_backup/_all 看所有的

#输出结果:
{
  "snapshots" : [
    {
      "snapshot" : "snapshot_1",
      "uuid" : "FEbAt3BiR1SAiBkO7pfoZg",
      "version_id" : 7020199,
      "version" : "7.2.1",
      "indices" : [
        "blog-test"
      ],
      "include_global_state" : false,
      "state" : "SUCCESS",
      "start_time" : "2021-02-06T03:28:40.001Z",
      "start_time_in_millis" : 1612582120001,
      "end_time" : "2021-02-06T03:28:40.213Z",
      "end_time_in_millis" : 1612582120213,
      "duration_in_millis" : 212,
      "failures" : [ ],
      "shards" : {
        "total" : 3,
        "failed" : 0,
        "successful" : 3
      }
    }
  ]
}

查看快照状态:

GET _snapshot/my_fs_backup/snapshot_1/_status

#输出结果:
{
  "snapshots" : [
    {
      "snapshot" : "snapshot_1",
      "repository" : "my_fs_backup",
      "uuid" : "FEbAt3BiR1SAiBkO7pfoZg",
      "state" : "SUCCESS",
      "include_global_state" : false,
      "shards_stats" : {
        "initializing" : 0,
        "started" : 0,
        "finalizing" : 0,
        "done" : 3,
        "failed" : 0,
        "total" : 3
      },
      "stats" : {
        "incremental" : {
          "file_count" : 12,
          "size_in_bytes" : 15608
        },
        "total" : {
          "file_count" : 12,
          "size_in_bytes" : 15608
        },
        "start_time_in_millis" : 1612582120074,
        "time_in_millis" : 108
      },
      "indices" : {
        "blog-test" : {
          "shards_stats" : {
            "initializing" : 0,
            "started" : 0,
            "finalizing" : 0,
            "done" : 3,
            "failed" : 0,
            "total" : 3
          },
          "stats" : {
            "incremental" : {
              "file_count" : 12,
              "size_in_bytes" : 15608
            },
            "total" : {
              "file_count" : 12,
              "size_in_bytes" : 15608
            },
            "start_time_in_millis" : 1612582120074,
            "time_in_millis" : 108
          },
          "shards" : {
            "0" : {
              "stage" : "DONE",
              "stats" : {
                "incremental" : {
                  "file_count" : 4,
                  "size_in_bytes" : 5104
                },
                "total" : {
                  "file_count" : 4,
                  "size_in_bytes" : 5104
                },
                "start_time_in_millis" : 1612582120143,
                "time_in_millis" : 39
              }
            },
            "1" : {
              "stage" : "DONE",
              "stats" : {
                "incremental" : {
                  "file_count" : 4,
                  "size_in_bytes" : 5265
                },
                "total" : {
                  "file_count" : 4,
                  "size_in_bytes" : 5265
                },
                "start_time_in_millis" : 1612582120074,
                "time_in_millis" : 25
              }
            },
            "2" : {
              "stage" : "DONE",
              "stats" : {
                "incremental" : {
                  "file_count" : 4,
                  "size_in_bytes" : 5239
                },
                "total" : {
                  "file_count" : 4,
                  "size_in_bytes" : 5239
                },
                "start_time_in_millis" : 1612582120113,
                "time_in_millis" : 21
              }
            }
          }
        }
      }
    }
  ]
}

5 恢复 snapshot

POST _snapshot/my_fs_backup/snapshot_1/_restore
{
  "indices": "blog-test",
  "ignore_unavailable": true,
  "rename_pattern": "(.+)",
  "rename_replacement": "restored_$1"
}

查询新索引的数据:

GET restored_blog-test/_search

到此,相信大家对“Elasticsearch集群数据备份与恢复的方法是什么”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. mysql数据备份与恢复的简单操作
  2. elasticsearch数据备份恢复

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

elasticsearch

上一篇:SpringMVC+myBatis如何结合使用

下一篇:Linux sftp命令的用法是怎样的

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》