当前位置: 首页 > news >正文

es数据备份和迁移Elasticsearch

Elasticsearch数据备份与恢复

前提

# 注意:
1.在进行本地备份时使用--type需要备份索引和数据(mapping,data)
2.在将数据备份到另外一台ES节点时需要比本地备份多备份一种数据类型(analyzer,mapping,data,template)

一.本地备份与恢复

# 前提:
· 必须要有Node环境和npm软件:nodejs,npm  1.:下载包
wget https://nodejs.org/dist/v14.17.1/node-v14.17.1-linux-x64.tar.xz2.:安装包(如果本身有node包但是不是新版本建议卸载重装)
xz -d node-v14.17.1-linux-x64.tar.xz
tar -xvf node-v14.17.1-linux-x64.tar
echo "export NODE_HOME=/home/workspaces/node-v14.17.1-linux-x64
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules" >>/etc/profile
source /etc/profile3.:验证安装是否成功
node -v4.:设置淘宝镜像
npm config set registry http://registry.npm.taobao.org5.:安装npm(只需要在一个节点安装即可,如果前端还有nginx做反向代理可以每个节点都装)
[root@elkstack01 ~]# yum install -y npm6.:进入下载head插件代码目录
[root@elkstack01 src]# cd /usr/local/7.:从GitHub上克隆代码到本地(或者直接从找es-head的包)
[root@elkstack01 local]# git clone git://github.com/mobz/elasticsearch-head.git8.:克隆完成后,进入elasticsearch插件目录
[root@elkstack01 local]# cd elasticsearch-head/9.:清除缓存
[root@elkstack01 elasticsearch-head]# npm cache clean -f
#使用npm安装n模块(不同的项目js脚本所需的node版本可能不同,所以就需要node版本管理工具)10.安装elasticdump
[root@db04 ~]# npm install elasticdump -g11.本地目录备份## 第一次进行的是索引的备份
## 第二次进行的是数据的备份
[root@db04 bin]# ./elasticdump --input=http://10.0.0.54:9200/student/user --output=/tmp/student_mapping.json --type=mapping
Wed, 12 Aug 2020 07:41:59 GMT | starting dump
Wed, 12 Aug 2020 07:41:59 GMT | got 1 objects from source elasticsearch (offset: 0)
Wed, 12 Aug 2020 07:41:59 GMT | sent 1 objects to destination file, wrote 1
Wed, 12 Aug 2020 07:41:59 GMT | got 0 objects from source elasticsearch (offset: 1)
Wed, 12 Aug 2020 07:41:59 GMT | Total Writes: 1
Wed, 12 Aug 2020 07:41:59 GMT | dump complete
[root@db04 bin]# ./elasticdump --input=http://10.0.0.54:9200/student/user --output=/tmp/student_data.json --type=data
Wed, 12 Aug 2020 07:42:21 GMT | starting dump
Wed, 12 Aug 2020 07:42:21 GMT | got 8 objects from source elasticsearch (offset: 0)
Wed, 12 Aug 2020 07:42:21 GMT | sent 8 objects to destination file, wrote 8
Wed, 12 Aug 2020 07:42:21 GMT | got 0 objects from source elasticsearch (offset: 8)
Wed, 12 Aug 2020 07:42:21 GMT | Total Writes: 8
Wed, 12 Aug 2020 07:42:21 GMT | dump complete##备份之后用Elasticsearch Head插件模拟数据丢失,误删除student索引和数据并用elasticdump恢复[root@db04 bin]# ./elasticdump --output=http://10.0.0.54:9200/student --input=/tmp/student_mapping.json --type=mapping
Wed, 12 Aug 2020 07:46:21 GMT | starting dump
Wed, 12 Aug 2020 07:46:21 GMT | got 1 objects from source file (offset: 0)
Wed, 12 Aug 2020 07:46:21 GMT | sent 1 objects to destination elasticsearch, wrote 1
Wed, 12 Aug 2020 07:46:21 GMT | got 0 objects from source file (offset: 1)
Wed, 12 Aug 2020 07:46:21 GMT | Total Writes: 1
Wed, 12 Aug 2020 07:46:21 GMT | dump complete
[root@db04 bin]# ./elasticdump --output=http://10.0.0.54:9200/student --input=/tmp/student_data.json --type=data
Wed, 12 Aug 2020 07:46:40 GMT | starting dump
Wed, 12 Aug 2020 07:46:40 GMT | got 8 objects from source file (offset: 0)
Wed, 12 Aug 2020 07:46:40 GMT | sent 8 objects to destination elasticsearch, wrote 8
Wed, 12 Aug 2020 07:46:40 GMT | got 0 objects from source file (offset: 8)
Wed, 12 Aug 2020 07:46:40 GMT | Total Writes: 8
Wed, 12 Aug 2020 07:46:40 GMT | dump complete
#  根据索引名和类型进行备份

#备份成功。数据恢复成功

二.备份到另一台ES节点(如果是同一集群的节点索引不能重名)

# 备份到另一台ES节点(同一集群索引不能重名)
[root@db04 bin]# ./elasticdump --input=http://10.0.0.54:9200/student --output=http://10.0.0.55:9200/students --type=analyzer
Wed, 12 Aug 2020 08:14:00 GMT | starting dump
Wed, 12 Aug 2020 08:14:00 GMT | got 1 objects from source elasticsearch (offset: 0)
Wed, 12 Aug 2020 08:14:01 GMT | sent 1 objects to destination elasticsearch, wrote 1
Wed, 12 Aug 2020 08:14:01 GMT | got 0 objects from source elasticsearch (offset: 1)
Wed, 12 Aug 2020 08:14:01 GMT | Total Writes: 1
Wed, 12 Aug 2020 08:14:01 GMT | dump complete
[root@db04 bin]# ./elasticdump --input=http://10.0.0.54:9200/student --output=http://10.0.0.55:9200/students --type=mapping
Wed, 12 Aug 2020 08:14:10 GMT | starting dump
Wed, 12 Aug 2020 08:14:10 GMT | got 1 objects from source elasticsearch (offset: 0)
Wed, 12 Aug 2020 08:14:10 GMT | sent 1 objects to destination elasticsearch, wrote 1
Wed, 12 Aug 2020 08:14:10 GMT | got 0 objects from source elasticsearch (offset: 1)
Wed, 12 Aug 2020 08:14:10 GMT | Total Writes: 1
Wed, 12 Aug 2020 08:14:10 GMT | dump complete
[root@db04 bin]# ./elasticdump --input=http://10.0.0.54:9200/student --output=http://10.0.0.55:9200/students --type=data
Wed, 12 Aug 2020 08:14:15 GMT | starting dump
Wed, 12 Aug 2020 08:14:15 GMT | got 8 objects from source elasticsearch (offset: 0)
Wed, 12 Aug 2020 08:14:15 GMT | sent 8 objects to destination elasticsearch, wrote 8
Wed, 12 Aug 2020 08:14:15 GMT | got 0 objects from source elasticsearch (offset: 8)
Wed, 12 Aug 2020 08:14:15 GMT | Total Writes: 8
Wed, 12 Aug 2020 08:14:15 GMT | dump complete
[root@db04 bin]#elasticdump --input=http://10.0.0.54:9200/student --output=http://100.10.0.55:9200/students --type=template

三.本地备份与恢复脚本

# 1.本地备份脚本
[root@db04 ~]# vim output_Es.sh
#!/bin/bash
read -p '要备份的机器是:'${1}
#要导出的索引名
index_name='
student
'
for index in `echo $index_name`
doecho "start input index ${index}"elasticdump --input=http://${1}:9200/${index} --output=/data/${index}_alias.json --type=alias &> /dev/nullelasticdump --input=http://${1}:9200/${index} --output=/data/${index}_analyzer.json --type=analyzer &> /dev/nullelasticdump --input=http://${1}:9200/${index} --output=/data/${index}_data.json --type=data &> /dev/nullelasticdump --input=http://${1}:9200/${index} --output=/data/${index}_alias.json --type=alias &> /dev/nullelasticdump --input=http://${1}:9200/${index} --output=/data/${index}_template.json --type=template &> /dev/null
done# 2.恢复脚本
[root@db04 ~]# vim input_Es.sh
#!/bin/bash
read -p '要导入的机器是:'${1}
#要导入的索引名
index_name='
student
'
for index in `echo $index_name`
doecho "start input index ${index}"elasticdump --input=/data/${index}_alias.json --output=http://${1}:9200/${index} --type=alias &> /dev/nullelasticdump --input=/data/${index}_analyzer.json --output=http://${1}:9200/${index} --type=analyzer &> /dev/nullelasticdump --input=/data/${index}_data.json --output=http://${1}:9200/${index} --type=data &> /dev/nullelasticdump --input=/data/${index}_template.json --output=http://${1}:9200/${index} --type=template &> /dev/null
done

测试脚本

# 0.配置环境变量
[root@db04 ~]# vim /etc/profile.d/elasticdump.sh 
export PATH=/root/node-v10.13.0-linux-x64/lib/node_modules/elasticdump/bin:$PATH
[root@db04 ~]# source /etc/profile# 1.创建备份目录
[root@db04 ~]# mkdir /data# 2.执行备份脚本
[root@db04 ~]# sh output_Es.sh 
要备份的机器是:10.0.0.54
start input index student# 3.查看备份目录
[root@db04 ~]# ll /data/
total 16
-rw-r--r-- 1 root root    5 Aug 12 16:59 student_alias.json
-rw-r--r-- 1 root root  101 Aug 12 16:59 student_analyzer.json
-rw-r--r-- 1 root root 1284 Aug 12 16:59 student_data.json
-rw-r--r-- 1 root root    5 Aug 12 16:59 student_template.json

# 模拟误删除操作

# 执行恢复脚本
[root@db04 ~]#  sh input_Es.sh 
要导入的机器是:10.0.0.54
start input index student## 数据恢复

相关文章:

es数据备份和迁移Elasticsearch

Elasticsearch数据备份与恢复 前提 # 注意: 1.在进行本地备份时使用--type需要备份索引和数据(mapping,data) 2.在将数据备份到另外一台ES节点时需要比本地备份多备份一种数据类型(analyzer,mapping,data,template) …...

Oracle数据块之数据行中的SCN

从Oracle 10g开始,如果在表级别打开ROW DEPENDENCIES,业务数据行发生更改时会在数据块中进行登记。 可以通过DUMP数据块来观察上述SCN: (1)创建测试表,插入3条测试数据,插入一条提交一次。并调用…...

手写tomcat(Ⅱ)——Socket通信+tomcat静态资源的获取

Socket通信简介 参考文章:socket通讯原理及例程(一看就懂) socket是介于应用层(http协议)和传输层(TCP/UDP协议)之间的一层虚拟层 Socket是一个程序,符合TCP/UDP协议的规范&…...

解决Error: error:0308010C:digital envelope routines::unsupported的四种解决方案

问题描述: 报错:Error: error:0308010C:digital envelope routines::unsupported 报错原因: 主要是因为 nodeJs V17 版本发布了 OpenSSL3.0 对算法和秘钥大小增加了更为严格的限制,nodeJs v17 之前版本没影响&am…...

shell 脚本笔记2

3.env与set区别 env用于查看系统环境变量 set用于查看系统环境变量自定义变量函数 4.常用环境变量 变量名称含义PATH命令搜索的目录路径, 与windows的环境变量PATH功能一样LANG查询系统的字符集HISTFILE查询当前用户执行命令的历史列表 Shell变量:自定义变量 目标…...

aws eks集成wasm运行时并启动pod

参考资料 WebAssembly 在云原生中的实践指南,https://cloud.tencent.com/developer/article/2324065 作为一种通用字节码技术,wasm的初衷是在浏览器中的程序实现原生应用性能。高级语言将wasm作为目标语言进行编译并运行在wasm解释器中。和nodejs类似的…...

linux:切分大文件

文章目录 1. 前言2. 用法3. 例子 1. 前言 如果传输、存储过程中出现大文件,希望切分成小文件。在 Linux 中,可以使用多种工具来切分大文件,最常用的是 split 命令。split 命令可以将一个大文件按照指定大小切分成多个小文件。 2. 用法 spl…...

docker 配置文件使用经验,后续持续增加

1. 容器中如何访问主机服务 在docker容器、docker compose 中如何访问主机服务呢? docker容器 20.10.0 版本在 linux 新增 host.docker.internal 支持: docker run -it --add-hosthost.docker.internal:host-gateway alpine cat /etc/hosts 127.0.0.…...

Qml:键盘事件

import QtQuickWindow {width: 640height: 480visible: truetitle: qsTr("Test KeyEvent")//传递给活动窗口的QQuickWindow//传递给当前活动的Item(focus为true),如没则找子节点中的,都没有则忽略Item{id:item1//focus:…...

Java列表导出时将附件信息压缩成一个zip

一:使用场景 在最近的工作当中遇到了一个需求,在列表导出时,不仅需要将列表信息导出为excel文件,同时也需要将列表每一条数据所对应的附件信息放在同一个文件夹当中,并且压缩成一个zip响应给浏览器。首先后端需要写两…...

简单美观易上手的 Docker Compose 可视化管理器 Dockge

本文首发于只抄博客,欢迎点击原文链接了解更多内容。 前言 Dockge 是 Uptime Kuma 作者的新作品,因此 UI 风格与 Uptime Kuma 基本一致,如果你正在使用 Uptime Kuma 的话,那么 Dockge 的 UI 设计应该也不会让你失望。Dockge 主打…...

贴片 RS8752XK 封装SOP-8 250MHz,2通道高速运放

传感器信号放大:在传感器应用中,RS8752XK可以用于放大微弱的传感信号,如压力、温度、光强等传感器的信号。 数据采集系统:在数据采集设备中,RS8752XK可以用于放大和调理模拟信号,以供模数转换器&#xff0…...

图论-最短路算法

1. Floyd算法 作用:用于求解多源最短路,可以求解出任意两点的最短路 利用动态规划只需三重循环即可(动态规划可以把问题求解分为多个阶段)定义dp[k][i][j]表示点i到点j的路径(除去起点终点)中最大编号不超…...

家政预约小程序05服务管理

目录 1 设计数据源2 后台管理3 后端API4 调用API总结 家政预约小程序的核心是展示家政公司提供的各项服务的能力,比如房屋维护修缮,家电维修,育婴,日常保洁等。用户在选择家政服务的时候,价格,评价是影响用…...

Django自定义命令

Django自定义命令 我们知道,Django内部内置了很多命令,例如 python manage.py runserver python manage.py makemigrations python manage.py migrate我们可以在python控制台中查看所有命令 我们也可以自定义命令,让python manage.py执行…...

详解VLSM技术

在现代网络设计中,如何高效地分配和管理IP地址是一个关键问题。传统的子网划分方法虽然简单,但在实际应用中常常导致IP地址的浪费。为了应对这一问题,VLSM(Variable Length Subnet Mask,可变长子网掩码)技术…...

面向浏览器端免费开源的三维可视化编辑器,包含BIM轻量化,CAD解析预览等特色功能。

ES 3DEditor 🌍Github地址 https://github.com/mlt131220/ES-3DEditor 🌍在线体验 https://editor.mhbdng.cn/#/ 基于vue3与ThreeJs,具体查看Doc 主要功能: 模型导入展示,支持OBJ、FBX、GLTF、GLB、RVT、IFC、SEA、3…...

Nacos 进阶篇---Nacos服务端怎么维护不健康的微服务实例 ?(七)

一、引言 在 Nacos 后台管理服务列表中,我们可以看到微服务列表,其中有一栏叫“健康实例数” (如下图),表示对应的客户端实例信息是否可用状态。 那Nacos服务端是怎么感知客户端的状态是否可用呢 ? 本章…...

【oracle004】oracle内置函数手册总结(已更新)

1.熟悉、梳理、总结下oracle相关知识体系。 2.日常研发过程中使用较少,随着时间的推移,很快就忘得一干二净,所以梳理总结下,以备日常使用参考 3.欢迎批评指正,跪谢一键三连! 总结源文件资源下载地址&#x…...

建模:Maya

一、常用按键 1、alt 左键 —— 环绕查看 2、alt 中键 —— 拖动模型所在面板 3、空格 —— 进入三视图模式;空格 左键按住拖动 —— 切换到对应视图 二、骨骼归零 1、T Pose 旋转模式,点击模型,摆好T姿势即可 2、复制模型设置200距离…...

持续总结中!2024年面试必问 20 道 Redis面试题(四)

上一篇地址:持续总结中!2024年面试必问 20 道 Redis面试题(三)-CSDN博客 七、Redis过期键的删除策略? Redis 过期键的删除策略主要涉及以下几种方式: 1. 定时删除(Timed Expiration&#xff…...

Java中关于List的一些常用操作

先定义一个List&#xff0c;代码如下 //定义一个实例类 public class Model{private String id;private String code;private String name;//setter getter 方法省略}//定义一个List,赋值过程省略 List<Model> list new ArrayList<>();1.将List中每一个对象的id…...

Docker仓库解析

目录 1、Docker仓库类型2、Docker仓库的作用3、工作原理4、管理与使用最佳实践 Docker仓库是Docker生态系统中的重要组成部分&#xff0c;它是用于存储和分发Docker镜像的集中化服务。无论是公共还是私有&#xff0c;仓库都是开发者之间共享和复用容器镜像的基础。 1、Docker仓…...

开发人员容易被骗的原因有很多,涉及技术、安全意识、社会工程学以及工作环境等方面。以下是一些常见原因:

技术方面&#xff1a; 漏洞和补丁管理不当&#xff1a;未及时更新软件和依赖库可能存在已知漏洞&#xff0c;容易被攻击者利用。缺乏安全编码实践&#xff1a;没有遵循安全编码规范&#xff0c;容易引入SQL注入、跨站脚本&#xff08;XSS&#xff09;等安全漏洞。错误配置&…...

使用Python实现深度学习模型:自动编码器(Autoencoder)

自动编码器&#xff08;Autoencoder&#xff09;是一种无监督学习的神经网络模型&#xff0c;用于数据的降维和特征学习。它由编码器和解码器两个部分组成&#xff0c;通过将输入数据编码为低维表示&#xff0c;再从低维表示解码为原始数据来学习数据的特征表示。本教程将详细介…...

数据结构--树与二叉树--编程实现以孩子兄弟链表为存储结构递归求树的深度

数据结构–树与二叉树–编程实现以孩子兄弟链表为存储结构递归求树的深度 题目: 编程实现以孩子兄弟链表为存储结构&#xff0c;递归求树的深度。 ps&#xff1a;题目来源2025王道数据结构 思路&#xff1a; 从根结点开始 结点 N 的高度 max{N 孩子树的高度 1, N兄弟树的…...

Property xxx does not exist on type ‘Window typeof globalThis‘ 解决方法

问题现象 出现以上typescript警告&#xff0c;是因为代码使用了window的非标准属性&#xff0c;即原生 window 对象上不存在该属性。 解决办法 在项目 根目录 或者 src目录 下新建 xxx.d.ts 文件&#xff0c;然后进行对该 属性 进行声明即可。 注意&#xff1a;假如xxx.d.ts文…...

BOM..

区别&#xff1a;...

rust的版本问题,安装问题,下载问题

rust的版本、安装、下载问题 rust版本问题&#xff0c; 在使用rust的时候&#xff0c;应用rust的包&#xff0c;有时候包的使用和rust版本有关系。 error: failed to run custom build command for pear_codegen v0.1.2 Caused by: process didnt exit successfully: D:\rus…...

SDUT 链表9-------7-9 sdut-C语言实验-约瑟夫问题

7-9 sdut-C语言实验-约瑟夫问题 分数 20 全屏浏览 切换布局 作者 马新娟 单位 山东理工大学 n个人想玩残酷的死亡游戏&#xff0c;游戏规则如下&#xff1a; n个人进行编号&#xff0c;分别从1到n&#xff0c;排成一个圈&#xff0c;顺时针从1开始数到m&#xff0c;数到m的…...