《Linux运维总结:基于快照模式迁移单节点elasticsearch数据(方案二)》
创始人
2024-02-26 21:54:40
0

一、背景信息

说明:由于整个系统需要从互联网迁移到政务外网,elasticsearch作为其中一个组件,也需要将 所有索引数据 迁移到政务外网。 由于数据量比较大,所以使用快照的模式对elasticsearch数据进行备份及恢复操作,提升效率。


二、自动化备份恢复工具

基于快照模式单节点elasticsearch数据自动化备份恢复工具

1、实现功能如下

1、一键备份全索引,类似于Mysql全库备份模式。
2、一键恢复指定日期全索引,类似于Mysql全库恢复模式。
3、一键备份单索引,类似于Mysql分库备份模式。
4、一键恢复指定日期单索引,类似于Mysql分库恢复模式。
5、保留7天内备份文件。


三、备份前操作

说明:当前工具实现了两种模式备份,单索引和全索引,所以这里elasticsearch.yml设置了两个备份仓库地址,如下所示:

cluster.name: my-application
node.name: node1
network.host: 0.0.0.0
network.publish_host: 192.168.1.174
http.port: 9200
transport.tcp.port: 9300
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts: ["192.168.1.174:9300"]
#【/data/backup/single-index为单个索引快照备份目录】;【/data/backup/all-index为所有索引快照备份目录】
path.repo: ["/data/backup/single-index","/data/backup/all-index"]

三、使用工具实现数据备份恢复

注意:如果源主机和目标主机网络相通,可在源主机上进行备份,同时可在源主机上对目标主机的es数据进行恢复,无需将备份文件拷贝到目标主机。

帮助信息

[root@localhost elasticdump_snapshot]# ./op.sh 
Usage:bash op.sh backup-all        es所有索引进行快照备份. bash op.sh restore-all       es所有索引进行快照恢复bash op.sh backup-single     es单个索引进行快照备份bash op.sh restore-single    es单个索引进行快照恢复

说明:由于当前elasticsearch是采用docker部署,elasticsearch.yml中path.repo中定义的两个备份仓库地址,对应宿主机的/data/pkgs/es-tools/tools/single/backup/all-index,/data/pkgs/es-tools/tools/single/backup/single-index目录,目录权限位777。

1、编辑env.conf文件

############################################<<适用于单机es2.0.0版本>>####################################################
# 导出,即备份
# 源es ip地址,根据实际情况修改
ES_SOURCE_IP="192.168.1.174"# 源es 端口,根据实际情况修改
ES_SOURCE_PORT="9201"# 快照仓库备份目录,根据实际情况修改
ES_SNAPSHOT_BACKUP_DIR="/data/pkgs/es-tools/tools/single/backup"
##########################################################################################################################
# 导入,即恢复
# 目标es ip地址,根据实际情况修改
ES_TARGET_IP="192.168.1.48"# 目标es 端口,根据实际情况修改
ES_TARGET_PORT="9201"# 快照仓库恢复目录,根据实际情况修改
ES_SNAPSHOT_RESTORE_DIR="/data/pkgs/es-tools/tools/single/backup"# 恢复模式一:根据单个索引快照遍历恢复所有索引数据,二者选其一,根据当前环境采用的备份模式来确定,时间日期根据实际情况修改
# 例如: 2022-11-25
ES_SINGLE_RESTORE_DATE_TIME="2022-11-28"# 恢复模式二:根据所有索引快照恢复所有索引数据,二者选其一,根据当前环境采用的备份模式来确定,时间日期根据实际情况修改
# 例如: 2022-11-25
ES_ALL_RESTORE_DATE_TIME="2022-11-28"
##########################################################################################################################

3.1、全索引模式

说明:全索引模式,是指全部索引一起备份,类似于Mysql的全库备份方式。

2、备份源主机es索引数据,全索引模式

[root@localhost elasticdump_snapshot]# ./op.sh backup-all
[root@localhost elasticdump_snapshot]# ll /data/pkgs/es-tools/tools/single/backup/all-index/
-rw-r--r-- 1 105 108  38 11月 28 13:28 index
drwxr-xr-x 9 105 108 155 11月 28 13:28 indices
-rw-r--r-- 1 105 108 110 11月 28 13:28 meta-all-index-2022-11-28.dat
-rw-r--r-- 1 105 108 300 11月 28 13:28 snap-all-index-2022-11-28.dat

如下图所示:
在这里插入图片描述

3、目标主机es索引数据恢复,全索引模式

[root@localhost elasticdump_snapshot]# ./op.sh restore-all
2022-11-28 13:31:19 Info: The all index data is restore successfully.

如下图所示:
在这里插入图片描述


3.2、单索引模式

说明:单索引模式,是指单个索引备份,类似于Mysql的分库备份方式。

2、备份源主机es索引数据,单索引模式

[root@localhost elasticdump_snapshot]# ./op.sh backup-single
[root@localhost elasticdump_snapshot]# ll /data/pkgs/es-tools/tools/single/backup/single-index
[root@localhost elasticdump_snapshot]# ll /data/pkgs/es-tools/tools/single/backup/single-index
-rw-r--r-- 1 root root 455 11月 28 13:32 es_indices.txt
-rw-r--r-- 1  105  108 206 11月 28 13:32 index
drwxr-xr-x 9  105  108 155 11月 28 13:32 indices
-rw-r--r-- 1  105  108 110 11月 28 13:32 meta-conference-index-2-2022-11-28.dat
-rw-r--r-- 1  105  108 110 11月 28 13:32 meta-depart_person-2022-11-28.dat
-rw-r--r-- 1  105  108 110 11月 28 13:32 meta-depart_person_statics-2022-11-28.dat
-rw-r--r-- 1  105  108 110 11月 28 13:32 meta-duty_statistics-2022-11-28.dat
-rw-r--r-- 1  105  108 110 11月 28 13:32 meta-logger_index-2022-11-28.dat
-rw-r--r-- 1  105  108 110 11月 28 13:32 meta-statistics-2022-11-28.dat
-rw-r--r-- 1  105  108 110 11月 28 13:32 meta-test-2022-11-28.dat
-rw-r--r-- 1  105  108 224 11月 28 13:32 snap-conference-index-2-2022-11-28.dat
-rw-r--r-- 1  105  108 214 11月 28 13:32 snap-depart_person-2022-11-28.dat
-rw-r--r-- 1  105  108 230 11月 28 13:32 snap-depart_person_statics-2022-11-28.dat
-rw-r--r-- 1  105  108 218 11月 28 13:32 snap-duty_statistics-2022-11-28.dat
-rw-r--r-- 1  105  108 212 11月 28 13:32 snap-logger_index-2022-11-28.dat
-rw-r--r-- 1  105  108 208 11月 28 13:32 snap-statistics-2022-11-28.dat
-rw-r--r-- 1  105  108 196 11月 28 13:32 snap-test-2022-11-28.dat
[root@localhost elasticdump_snapshot]# 

如下图所示:
在这里插入图片描述

3、目标主机es索引数据恢复,单索引模式

[root@localhost elasticdump_snapshot]# ./op.sh restore-single
2022-11-28 13:34:16 Info: The logger_index index data is restore successfully.
2022-11-28 13:34:16 Info: The depart_person index data is restore successfully.
2022-11-28 13:34:16 Info: The conference-index-2 index data is restore successfully.
2022-11-28 13:34:16 Info: The duty_statistics index data is restore successfully.
2022-11-28 13:34:16 Info: The depart_person_statics index data is restore successfully.
2022-11-28 13:34:20 Info: The statistics index data is restore successfully.
2022-11-28 13:34:20 Info: The test index data is restore successfully.

如下图所示:
在这里插入图片描述


总结:整理不易,如果对你有帮助,可否点赞关注一下?

更多详细内容请参考:Linux运维实战总结

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
苏州离哪个飞机场近(苏州离哪个... 本篇文章极速百科小编给大家谈谈苏州离哪个飞机场近,以及苏州离哪个飞机场近点对应的知识点,希望对各位有...
客厅放八骏马摆件可以吗(家里摆... 今天给各位分享客厅放八骏马摆件可以吗的知识,其中也会对家里摆八骏马摆件好吗进行解释,如果能碰巧解决你...