数据备份是一个必须要考虑的问题,官网提供了 snapshot 接口来备份和恢复数据。

先来看看官方说明

如果ES是集群,那么需要使用共享存储,支持的存储有:

a、shared file system

b、S3

c、HDFS

我使用的是第一种,NFS共享文件系统。这里要说一下权限问题,ES一般是使用 elasticsearch 用户启动的,要保证共享目录对 elasticsearch 用户有读写权限,要不然创建仓库和快照的时候会报访问拒绝500错误。

在nfs-server上导出共享目录的权限配置,这里将所有连接用户都压缩为root权限:

# vim /etc/exports
/data02/es 192.168.3.56(rw,sync,all_squash,anonuid=0,anongid=0,no_subtree_check) 192.168.3.57(rw,sync,all_squash,anonuid=0,anongid=0,no_subtree_check) 192.168.3.49(rw,sync,all_squash,anonuid=0,anongid=0,no_subtree_check) # /etc/init.d/nfs-kernel-server reload

1、创建挂载目录,并给予权限

# mkidr -pv /nh/esbk/my_backup
# chmod 755 /nh/esbk/
# chown elasticsearch.elasticsearch /nh/esbk/

2、挂载共享目录

# vim /etc/fstab
192.168.3.97:/data02/es /nh/esbk/my_backup nfs defaults 0 0 # mount -a
# df -hT

3、修改ES的配置文件,添加仓库路径,重启服务

# vim /etc/elasticsearch/elasticsearch.yml
path.repo: ["/nh/esbk"] # /etc/init.d/elasticsearch restart

4、注册快照仓库到ES,这里是在 kibana 的 Dev Tools 上操作的,也可以使用 curl 发起请求。

Before any snapshot or restore operation can be performed, a snapshot repository should be registered in Elasticsearch. 

After all nodes are restarted, the following command can be used to register the shared file system repository with the name my_backup.
PUT /_snapshot/my_backup
{
"type": "fs",
"settings": {
"compress": true,
"location": "/nh/esbk/my_backup"
}
}

5、查看仓库信息

GET /_snapshot/my_backup

# curl -u elastic -XGET 'http://192.168.3.49:9200/_snapshot/my_backup?pretty'
{
"my_backup" : {
"type" : "fs",
"settings" : {
"compress" : "true",
"location" : "/nh/esbk/my_backup"
}
}
}

6、创建快照

A repository can contain multiple snapshots of the same cluster.
Snapshots are identified by unique names within the cluster.
A snapshot with the name snapshot_1 in the repository my_backup can be created by executing the following command.
PUT /_snapshot/my_backup/snapshot_1

这里发起请求后,会立马返回 true,并在后台执行操作。

如果想等待执行完成之后再返回,可以加一个参数:

PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true

7、查看刚才创建的快照的信息

Once a snapshot is created information about this snapshot can be obtained using the following command.
GET /_snapshot/my_backup/snapshot_1

{
"snapshots": [
{
"snapshot": "snapshot_1",
"uuid": "xSMRNVMIRHmx_qlhX5fqfg",
"version_id": 5040199,
"version": "5.4.1",
"indices": [
".monitoring-kibana-2-2017.07.05",
".monitoring-kibana-2-2017.07.11",
"zixun-nginx-access-2017.07.12",
".monitoring-logstash-2-2017.07.07",
".monitoring-kibana-2-2017.07.07",
"filebeat-2017.07.07",
".watcher-history-3-2017.07.04",
".watcher-history-3-2017.07.07",
".monitoring-es-2-2017.07.05",
".kibana",
".monitoring-data-2",
".watcher-history-3-2017.06.27",
".monitoring-logstash-2-2017.07.10",
".monitoring-kibana-2-2017.07.10",
".monitoring-es-2-2017.07.08",
".monitoring-logstash-2-2017.07.12",
".monitoring-es-2-2017.07.10",
".watcher-history-3-2017.07.06",
".monitoring-kibana-2-2017.07.09",
".watcher-history-3-2017.07.12",
".watcher-history-3-2017.07.03",
".monitoring-alerts-2",
".monitoring-logstash-2-2017.07.08",
".watcher-history-3-2017.07.01",
".watcher-history-3-2017.07.11",
".watcher-history-3-2017.07.05",
".watcher-history-3-2017.06.29",
".watcher-history-3-2017.06.28",
".monitoring-kibana-2-2017.07.08",
".security",
".monitoring-logstash-2-2017.07.11",
".monitoring-es-2-2017.07.11",
".watcher-history-3-2017.06.30",
".triggered_watches",
".watcher-history-3-2017.07.08",
".monitoring-es-2-2017.07.12",
".watcher-history-3-2017.07.09",
".monitoring-es-2-2017.07.09",
".monitoring-kibana-2-2017.07.12",
".monitoring-kibana-2-2017.07.06",
".watcher-history-3-2017.07.10",
"test",
".monitoring-es-2-2017.07.07",
".monitoring-logstash-2-2017.07.09",
".watches",
".monitoring-es-2-2017.07.06",
".watcher-history-3-2017.07.02"
],
"state": "SUCCESS",
"start_time": "2017-07-12T04:19:08.246Z",
"start_time_in_millis": 1499833148246,
"end_time": "2017-07-12T04:20:04.717Z",
"end_time_in_millis": 1499833204717,
"duration_in_millis": 56471,
"failures": [],
"shards": {
"total": 59,
"failed": 0,
"successful": 59
}
}
]
}

列出一个仓库里的所有快照

All snapshots currently stored in the repository can be listed using the following command:
GET /_snapshot/my_backup/_all

8、删除一个快照

A snapshot can be deleted from the repository using the following command:
DELETE /_snapshot/my_backup/snapshot_1

9、删除一个仓库

A repository can be deleted using the following command:
DELETE /_snapshot/my_backup

10、恢复一个快照(支持恢复部分数据以及恢复过程中修改索引信息,具体细节参考官方文档)

POST /_snapshot/my_backup/snapshot_1/_restore

11、查看快照状态信息(比如正在创建或者创建完成等)

a、列出所有当前正在运行的快照以及显示他们的详细状态信息

A list of currently running snapshots with their detailed status information can be obtained using the following command.
GET /_snapshot/_status

b、查看指定仓库的正在运行的快照以及显示他们的详细状态信息

GET /_snapshot/my_backup/_status

c、查看指定快照的详细状态信息即使不是正在运行

If both repository name and snapshot id are specified, this command will return detailed status information for the given snapshot even if it’s not currently running:
GET /_snapshot/my_backup/snapshot_1/_status

d、支持同时指定多个快照ID查看多个快照的信息

Multiple ids are also supported.
GET /_snapshot/my_backup/snapshot_1,snapshot_2/_status

12、如果要停止一个正在运行的snapshot任务(备份和恢复),将其删除即可。

elasticsearch5使用snapshot接口备份索引的更多相关文章

  1. elasticsearch-5.1.1使用snapshot接口备份索引

    如果ES是集群,那么需要使用共享存储,支持的存储有:a.shared file systemb.S3c.HDFS 我使用的是第一种,NFS共享文件系统.这里要说一下权限问题,ES一般是使用 elast ...

  2. 接口、索引器、Foreach的本质(学习笔记)

    接口 什么是接口? 接口代表一种能力,和抽象类类似但比抽象类的抽象程度更高! 接口的定义: public interface IEat//定义一个接口 { void Eat(string food); ...

  3. elasticsearch snapshot快照备份和恢复

    环境:mac   使用brew 安装elasticsearch   1.在 /usr/local/etc/elasticsearch/elasticsearch.yml 文件中配置快照地址     p ...

  4. es备份索引

    1.解压https://github.com/medcl/esm-abandonedhttps://github.com/medcl/esm-abandoned/releases tar xf lin ...

  5. elasticsearch5.0.1集群索引分片丢失的处理

    elasticdump命令安装 yum install npm npm install elasticdump -g 命令安装完毕,可以测试. 可能会报出nodejs的版本之类的错误,你需要升级一下版 ...

  6. hbase snapshot 表备份/恢复

    snapshot其实就是一组metadata信息的集合,它可以让管理员将表恢复到以前的一个状态.snapshot并不是一份拷贝,它只是一个文件名的列表,并不拷贝数据.一个全的snapshot恢复以为着 ...

  7. Elasticsearch snapshot 备份的使用方法 【备忘】

    常见的数据库都会提供备份的机制,以解决在数据库无法使用的情况下,可以开启新的实例,然后通过备份来恢复数据减少损失.虽然 Elasticsearch 有良好的容灾性,但由于以下原因,其依然需要备份机制. ...

  8. Elasticsearch:Cluster备份 Snapshot及Restore API

    Elasticsearch提供了replica解决方案,它可以帮我们解决了如果有一个或多个node失败了,那么我们的数据还是可以保证完整的情况,并且搜索还可以继续进行.但是,有一种情况是我们的所有的n ...

  9. 如何使用T-SQL备份还原数据库及c#如何调用执行? C#中索引器的作用和实现。 jquery控制元素的隐藏和显示的几种方法。 localStorage、sessionStorage用法总结 在AspNetCore中扩展Log系列 - 介绍开源类库的使用(一) span<T>之高性能字符串操作实测

    如何使用T-SQL备份还原数据库及c#如何调用执行? 准备材料:Microsoft SQL Server一部.需要还原的bak文件一只 一.备份 数据库备份语句:user master backup ...

随机推荐

  1. windows离线补丁包下载路径-云盾安骑士

    我们有一台阿里云服务器,只有内网可以访问,无外网资源. 阿里云账户邮箱反复收到阿里云云盾的漏洞报警通知,推荐安装安骑士组件. 安骑士组件是收费服务.阿里云服务器,无法连上外网,无法自动安装补丁.需要将 ...

  2. Azure-如何排查应用程序网关返回 HTTP Code 502 或客户端得到应用程序网关响应慢的问题(二)

    问题描述 经过如何排查应用程序网关返回 HTTP Code 502 或客户端得到应用程序网关响应慢的问题(一)中的排查步骤,可以判断出是由于 Web 服务器自身问题导致的响应异常. 那么可以在 IIS ...

  3. python实现简单线性回归

    之前推导了一元线性回归和多元线性回归,今天就用python来实现一下一元线性回归 先看下之前推导的结果   ,  第一种是用循环迭代的计算方法.这里的x,y是numpy中的array类型 def su ...

  4. Maven打包jar类库

    项目目录>mvn clean compile 编译命令,会在你的项目路径下生成一个target目录,在该目录中包含一个classes文件夹,里面全是生成的class文件及字节码文件. 项目目录& ...

  5. Trait 是什么东西

    PHP官方手册里面写的内容是 自 PHP 5.4.0 起,PHP 实现了一种代码复用的方法,称为 trait. Trait 是为类似 PHP 的单继承语言而准备的一种代码复用机制.Trait 为了减少 ...

  6. 工作小应用:EXCEL查找两列重复数据

    工作案例:excel存在A列.B列,需要找出B列没有A列的数据,具体做法如下(以office2007做案例): 1.点击 公式-定义名称 ,选中A列,填写名称“AAA”,选中B列,填写名称“BBB”: ...

  7. vi/vim命令详解

    基础命令学习目录首页 原文链接:https://www.cnblogs.com/mondol/p/vi-examples.html 进入vi vi filename # 打开或新建文件,并将光标置于第 ...

  8. runlevel 命令详解

    基础命令学习目录首页 原文链接:https://blog.csdn.net/PecoVio/article/details/82428883 runlevel 知识扩展 linux操作系统自从开始启动 ...

  9. [linux] LVM原磁盘扩容(非增加磁盘)

    阿里云机器,ECS运行时磁盘由300G扩容到500,重启机器生效后登录.可以看到/data目录总大小300G,/dev/vdb已经扩容到500G. [root@HD1g-elasticsearch2 ...

  10. 解决 vuex mapGetters 语法报错 (Unexpected token )

    在使用vuex2的mapGetters 和 mapActions 的方法时,借助 stage2 的 Object Rest Operator 特性,可以写出下面代码:  computed: { ... ...