• 《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"]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

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

    注意:如果源主机和目标主机网络相通,可在源主机上进行备份,同时可在源主机上对目标主机的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单个索引进行快照恢复
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    说明:由于当前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"
    ##########################################################################################################################
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

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

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

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

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


    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]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

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

    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.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

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


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

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

  • 相关阅读:
    从 HPC 到 AI:探索文件系统的发展及性能评估
    vue3: 2.如何利用 effectScope 自己实现一个青铜版pinia 一 getters篇
    丰田工厂停产竟然因为磁盘...
    面试官:如何优雅依赖多个版本的jar包?
    SSH基本概念及常见问题解决
    SystemVerilog学习-10-验证量化和覆盖率
    关于硬盘的知识
    GBase 8c分布式核心技术—在线扩容
    基于Spring实现策略模式
    中国新型建材行业竞争分析与前景战略研究报告2022-2028年版
  • 原文地址:https://blog.csdn.net/m0_37814112/article/details/128075709