《Linux运维总结:基于快照模式迁移单节点elasticsearch数据(方案二)》

一、背景信息

说明:由于整个系统需要从互联网迁移到政务外网,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 1128 13:28 index
drwxr-xr-x 9 105 108 155 1128 13:28 indices
-rw-r--r-- 1 105 108 110 1128 13:28 meta-all-index-2022-11-28.dat
-rw-r--r-- 1 105 108 300 1128 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 1128 13:32 es_indices.txt
-rw-r--r-- 1  105  108 206 1128 13:32 index
drwxr-xr-x 9  105  108 155 1128 13:32 indices
-rw-r--r-- 1  105  108 110 1128 13:32 meta-conference-index-2-2022-11-28.dat
-rw-r--r-- 1  105  108 110 1128 13:32 meta-depart_person-2022-11-28.dat
-rw-r--r-- 1  105  108 110 1128 13:32 meta-depart_person_statics-2022-11-28.dat
-rw-r--r-- 1  105  108 110 1128 13:32 meta-duty_statistics-2022-11-28.dat
-rw-r--r-- 1  105  108 110 1128 13:32 meta-logger_index-2022-11-28.dat
-rw-r--r-- 1  105  108 110 1128 13:32 meta-statistics-2022-11-28.dat
-rw-r--r-- 1  105  108 110 1128 13:32 meta-test-2022-11-28.dat
-rw-r--r-- 1  105  108 224 1128 13:32 snap-conference-index-2-2022-11-28.dat
-rw-r--r-- 1  105  108 214 1128 13:32 snap-depart_person-2022-11-28.dat
-rw-r--r-- 1  105  108 230 1128 13:32 snap-depart_person_statics-2022-11-28.dat
-rw-r--r-- 1  105  108 218 1128 13:32 snap-duty_statistics-2022-11-28.dat
-rw-r--r-- 1  105  108 212 1128 13:32 snap-logger_index-2022-11-28.dat
-rw-r--r-- 1  105  108 208 1128 13:32 snap-statistics-2022-11-28.dat
-rw-r--r-- 1  105  108 196 1128 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运维实战总结

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东城绝神

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值