WO2021155668A1 - 一种数据库在线热备份的方法和设备 - Google Patents

一种数据库在线热备份的方法和设备 Download PDF

Info

Publication number
WO2021155668A1
WO2021155668A1 PCT/CN2020/118334 CN2020118334W WO2021155668A1 WO 2021155668 A1 WO2021155668 A1 WO 2021155668A1 CN 2020118334 W CN2020118334 W CN 2020118334W WO 2021155668 A1 WO2021155668 A1 WO 2021155668A1
Authority
WO
WIPO (PCT)
Prior art keywords
database
backup
main database
main
response
Prior art date
Application number
PCT/CN2020/118334
Other languages
English (en)
French (fr)
Inventor
徐基法
邓淮谦
Original Assignee
苏州浪潮智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 苏州浪潮智能科技有限公司 filed Critical 苏州浪潮智能科技有限公司
Publication of WO2021155668A1 publication Critical patent/WO2021155668A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2379Updates performed during online database operations; commit processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management

Definitions

  • the field relates to the computer field, and more specifically to a method and device for online hot backup of a database.
  • Database backup in a remote location is a common way to ensure data security. According to whether the database needs to be shut down, database backup is divided into cold backup and hot backup. To ensure the normal operation of business systems, database hot backup has become the primary choice for remote disaster recovery.
  • the first is to monitor the archive log of the database (for example: binlog in the MySQL command), filter the database change operations in the archive log, and execute the SQL command in the backup database.
  • Database hot backup The second is to use the master-slave mode of the database (for example: REPLICATION in the MySQL command) to realize hot backup of the database by configuring the standby database.
  • the master-slave mode of the database for example: REPLICATION in the MySQL command
  • the basic core is based on the database archive log.
  • the adoption of either scheme will cause the database to occupy a rapid growth in disk space, requiring regular operation and maintenance personnel Clean up the archive log, it is easier to cause abnormalities in the database hot backup due to log cleanup.
  • the purpose of the embodiments of the present invention is to provide a method and device for online hot backup of a database.
  • online real-time hot backup of the database can be realized and online master/backup switching is supported, and the safe and stable operation of the business system is guaranteed.
  • It can significantly reduce the growth rate of the disk space occupied by the database, and the configuration is simple, which greatly improves the efficiency of operation and maintenance, and avoids database backup abnormalities caused by human operations.
  • an aspect of the embodiments of the present invention provides a method for online hot backup of a database, which includes the following steps:
  • DBUtils a third-party module of database connection pool implemented by Python
  • the SQL commands in the cache list are sequentially put into RabbitMQ (an open source message broker software that implements the Advanced Message Queuing Protocol (AMQP) (also known as message-oriented middleware), which is high-performance, robust and reliable. Erlang, which is famous for its scalability, is written in) the queue and clears the cache list;
  • RabbitMQ an open source message broker software that implements the Advanced Message Queuing Protocol (AMQP) (also known as message-oriented middleware), which is high-performance, robust and reliable.
  • Erlang which is famous for its scalability, is written in
  • the asynchronous mechanism of Celery calls the Worker process to connect to the backup database and asynchronously execute the SQL commands in the RabbitMQ queue to complete the backup.
  • it further includes: configuring the database type, IP address, maximum number of automatic connections, and mailbox information of the main database and the backup database.
  • the update operation includes insert, update and delete.
  • it further includes:
  • an email is sent to notify the operation and maintenance personnel.
  • it further includes:
  • the backup database In response to the main database being abnormal and the maximum number of automatic connections to the main database has been exceeded, the backup database will be used as the main database to provide services;
  • a device for online hot backup of a database includes:
  • connection module is configured to encapsulate the main database based on DBUtils and connect to the backup database, and establish a cache list in the main database;
  • An identification module which is configured to execute SQL commands in response to establishing a transaction in the main database, identify update operations to the main database, and record related SQL commands in the cache list;
  • the write module is configured to respond to the transaction commit, put the SQL commands in the cache list into the RabbitMQ queue in order and clear the cache list;
  • the backup module is configured to call the Worker process via Celery's asynchronous mechanism to connect to the backup database and asynchronously execute the SQL commands in the RabbitMQ queue to complete the backup.
  • it further includes a configuration module configured to configure the database type, IP address, maximum number of automatic connections, and mailbox information of the main database and the backup database.
  • the update operation includes insert, update and delete.
  • the judgment module is configured as:
  • an email is sent to notify the operation and maintenance personnel.
  • a switching module is further included, and the switching module is configured as:
  • the backup database In response to the main database being abnormal and the maximum number of automatic connections to the main database has been exceeded, the backup database will be used as the main database to provide services;
  • the present invention has the following beneficial technical effects:
  • the method for online hot backup of a database provided by the embodiment of the present invention encapsulates the main database based on DBUtils and connects to the backup database, and establishes a cache list in the main database; Establish transactions to execute SQL commands in the database, identify update operations to the main database and record related SQL commands in the cache list; in response to the transaction commit, put the SQL commands in the cache list into the RabbitMQ queue in order and clear the cache List; through Celery's asynchronous mechanism to call the Worker process to connect to the backup database and asynchronously execute the SQL commands in the RabbitMQ queue to complete the backup technical solution, which can realize online real-time hot backup of the database and support online master/backup switching to ensure the safe and stable operation of the business system. It can significantly reduce the growth rate of the disk space occupied by the database, and the configuration is simple, which greatly improves the efficiency of operation and maintenance, and avoids database backup abnormalities caused by human operations.
  • Fig. 1 is a schematic flowchart of a method for online hot backup of a database according to an embodiment of the present invention
  • Fig. 2 is a schematic diagram of a device for online hot backup of a database according to an embodiment of the present invention
  • FIG. 3 is a schematic flowchart of a process of online hot backup of a database according to an embodiment of the present invention
  • Fig. 4 is a schematic flowchart of switching between a primary database and a backup database according to an embodiment of the present invention.
  • the first aspect of the embodiments of the present invention proposes an embodiment of a method for online hot backup of a database.
  • Figure 1 shows a schematic flow chart of the method.
  • the method may include the following steps:
  • S1 encapsulates the main database based on DBUtils and connects to the backup database, and establishes a cache list in the main database;
  • S2 executes SQL commands in response to the establishment of a transaction in the main database, identifies the update operation to the main database and records the SQL commands related to it in the cache list;
  • S3 puts the SQL commands in the cache list into the RabbitMQ queue in order and clears the cache list;
  • S4 uses Celery's asynchronous mechanism to call the Worker process to connect to the backup database and asynchronously execute the SQL commands in the RabbitMQ queue to complete the backup.
  • the invention provides a method for online hot backup of a Python-based database connection pool DBUtils+RabbitMQ+Celery.
  • Operation and maintenance personnel configure the connection information of the primary and standby databases and the maximum number of automatic connections, repackage DBUtils to connect to the primary database and backup database, and provide database services based on the database connection pool repackaged by DBUtils, and serve as the primary database.
  • the connection establishes the corresponding cache list.
  • online real-time hot backup of the database can be realized and online main-backup switching can be supported, the safe and stable operation of the business system can be ensured, and the growth rate of the disk space occupied by the database can be significantly reduced.
  • it further includes: configuring the database type, IP address, maximum number of automatic connections, and mailbox information of the main database and the backup database.
  • the maximum number of connections is the number of failed attempts to connect to the main database.
  • the backup database will be automatically switched to the main database to provide external services.
  • an email will be sent to the configured email address to notify the operation and maintenance personnel Perform maintenance.
  • the update operation includes insert, update and delete.
  • an email is sent to notify the operation and maintenance personnel.
  • an audible alarm or an alarm lamp can be set to indicate the abnormality.
  • the backup database In response to the main database being abnormal and the maximum number of automatic connections to the main database has been exceeded, the backup database will be used as the main database to provide services;
  • the business system accesses the database service, creates a new database connection, and allocates the bound cache list. Automatically recognize the database update operation (Insert/Update/Delete), and record the SQL commands in the connection corresponding list in order.
  • the automatic catching and identifying (Try+Exception) abnormality is a database connection abnormality
  • set the automatic reconnection to the main database (the number of times ⁇ the maximum number of automatic connections).
  • the connection still cannot be Automatically switch the backup database as the main database to provide external services.
  • the SQL command messages are still put into the RabbitMQ queue, and the Worker process of Celery is stopped at the same time.
  • the persistence characteristics of the RabbitMQ queue when the original database is detected to be restored After that, restart Celery's Worker process, which will asynchronously execute the persistent SQL command messages in the queue to automatically complete data synchronization.
  • online real-time hot backup of the database can be realized and online main-backup switching can be supported, the safe and stable operation of the business system can be ensured, and the growth rate of the disk space occupied by the database can be significantly reduced.
  • the above-mentioned programs can be stored in a computer readable storage medium.
  • the storage medium can be a magnetic disk, an optical disc, a read-only memory (Read-Only Memory, ROM), or a random access memory (Random Access Memory, RAM), etc.
  • the foregoing computer program embodiment can achieve the same or similar effects as any of the foregoing method embodiments corresponding thereto.
  • the method disclosed according to the embodiment of the present invention may also be implemented as a computer program executed by a CPU, and the computer program may be stored in a computer-readable storage medium.
  • the computer program executes the above-mentioned functions defined in the method disclosed in the embodiment of the present invention.
  • the second aspect of the embodiments of the present invention proposes a device for online hot backup of a database.
  • the device 200 includes:
  • connection module 201 is configured to encapsulate the main database based on DBUtils and connect to the backup database, and establish a cache list in the main database;
  • Recognition module 202 which is configured to execute SQL commands in response to establishing a transaction in the main database, recognize update operations on the main database, and record the SQL commands related to it in the cache list;
  • the writing module 203 is configured to, in response to the transaction commit, put the SQL commands in the cache list into the RabbitMQ queue in order and clear the cache list;
  • the backup module 204 is configured to call the Worker process to connect to the backup database via Celery's asynchronous mechanism to asynchronously execute the SQL commands in the RabbitMQ queue to complete the backup.
  • it further includes a configuration module configured to configure the database type, IP address, maximum number of automatic connections, and mailbox information of the main database and the backup database.
  • the update operation includes insert, update and delete.
  • a judgment module is further included, and the judgment module is configured as:
  • an email is sent to notify the operation and maintenance personnel.
  • a switching module is further included, and the switching module is configured as:
  • the backup database In response to the main database being abnormal and the maximum number of automatic connections to the main database has been exceeded, the backup database will be used as the main database to provide services;
  • the above method steps and system units or modules can also be implemented using a controller and a computer-readable storage medium for storing a computer program that enables the controller to implement the above steps or unit or module functions.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Quality & Reliability (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明提供了一种数据库在线热备份的方法和设备,该方法包括以下步骤:基于DBUtils将主数据库进行封装并连接到备份数据库,并在所述主数据库中建立缓存列表;响应于在主数据库中建立事务执行SQL命令,识别对主数据库的更新操作并将与其相关的SQL命令记录在缓存列表中;响应于事务提交,将缓存列表中的SQL命令按序放入RabbitMQ队列中并清空缓存列表;经由Celery的异步机制调用Worker工作进程连接备份数据库异步执行RabbitMQ队列中的SQL命令以完成备份。通过使用本发明的方法,能够实现数据库在线实时热备份并支持在线主备切换,保障业务系统安全稳定运行,能够显著降低数据库所占磁盘空间增长速度,且配置简单,大幅提高运维效率,避免因人为操作引起的数据库备份异常。

Description

一种数据库在线热备份的方法和设备
本申请要求于2020年2月9日提交中国国家知识产权局,申请号为202010083396.6,发明名称为“一种数据库在线热备份的方法和设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本领域涉及计算机领域,并且更具体地涉及一种数据库在线热备份的方法和设备。
背景技术
随着大数据时代的到来,各种数据存入数据库中,数据安全也越来约被重视。数据库在异地备份即是保证数据安全的一种常见的方式,根据是否需要关闭数据库,数据库备份又区分为冷备份与热备份。为保证业务系统的正常运行,数据库热备份成为异地灾备的首要选择。
现行数据库在线热备有两种方法:第一种为通过监测数据库的归档日志(例如:MySQL命令中的binlog),通过筛选归档日志中的数据库变动操作,将SQL命令在备份数据库中执行,实现数据库热备份。第二种为利用数据库的主从模式(例如:MySQL命令中的REPLICATION),通过配置备用数据库,实现数据库热备份。但是,在现行监测数据库归档日志的方案中,因日志监控采用的是时间轮询机制,数据更新存在延迟,当出现高并发场景时,无法有效同步更新备份数据库。利用数据库主从模式同步数据方案,运维成本偏高,且当SQL命令执行失败时,容易造成主库与备 库同步机制不工作。
不论是通过监测归档日志还是利用数据库自带主从模式的热备份模式,基本核心都是基于数据库的归档日志进行的,采用任一方案都会造成数据库所占磁盘空间快速增长,需运维人员定期清理归档日志,更易因日志清理引起数据库热备份出现异常。
发明内容
有鉴于此,本发明实施例的目的在于提出一种数据库在线热备份的方法和设备,通过使用本发明的方法,能够实现数据库在线实时热备份并支持在线主备切换,保障业务系统安全稳定运行,能够显著降低数据库所占磁盘空间增长速度,且配置简单,大幅提高运维效率,避免因人为操作引起的数据库备份异常。
基于上述目的,本发明的实施例的一个方面提供了一种数据库在线热备份的方法,包括以下步骤:
基于DBUtils(Python实现的数据库连接池第三方模块)将主数据库进行封装并连接到备份数据库,并在所述主数据库中建立缓存列表;
响应于在主数据库中建立事务执行SQL命令(结构化查询语言),识别对主数据库的更新操作并将与其相关的SQL命令记录在缓存列表中;
响应于事务提交,将缓存列表中的SQL命令按序放入RabbitMQ(实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件),由以高性能、健壮以及可伸缩性出名的Erlang写成)队列中并清空缓存列表;
经由Celery(一种分布式队列的管理工具,可通过接口快速实现并管理一个分布式的任务队列)的异步机制调用Worker工作进程连接备份数据库异步执行RabbitMQ队列中的SQL命令以完成备份。
根据本发明的一个实施例,还包括:配置主数据库和备份数据库的数据库类型、IP地址、最大自动连接次数和邮箱信息。
根据本发明的一个实施例,更新操作包括插入、更新和删除。
根据本发明的一个实施例,还包括:
通过自动捕捉识别主数据库连接是否异常;
响应于主数据库连接异常,发送邮件通知运维人员。
根据本发明的一个实施例,还包括:
响应于主数据库异常并且连接主数据库已经超过最大自动连接次数,将备份数据库作为主数据库提供服务;
响应于在备份数据库中建立事务执行SQL命令,识别对备份数据库的更新操作并将SQL命令记录在RabbitMQ队列中,并停止Worker工作进程;
响应于主数据库恢复,重新启动Worker工作进程以将更新操作备份到主数据库中。
本发明的实施例的另一个方面,还提供了一种数据库在线热备份的设备,设备包括:
连接模块,连接模块配置为基于DBUtils将主数据库进行封装并连接到备份数据库,并在所述主数据库中建立缓存列表;
识别模块,识别模块配置为响应于在主数据库中建立事务执行SQL命令,识别对主数据库的更新操作并将与其相关的SQL命令记录在缓存列表中;
写入模块,写入模块配置为响应于事务提交,将缓存列表中的SQL命令按序放入RabbitMQ队列中并清空缓存列表;
备份模块,备份模块配置为经由Celery的异步机制调用Worker工作进 程连接备份数据库异步执行RabbitMQ队列中的SQL命令以完成备份。
根据本发明的一个实施例,还包括配置模块,配置模块配置为配置主数据库和备份数据库的数据库类型、IP地址、最大自动连接次数和邮箱信息。
根据本发明的一个实施例,更新操作包括插入、更新和删除。
根据本发明的一个实施例,还包括判断模块,判断模块配置为:
通过自动捕捉识别主数据库连接是否异常;
响应于主数据库连接异常,发送邮件通知运维人员。
根据本发明的一个实施例,还包括切换模块,切换模块配置为:
响应于主数据库异常并且连接主数据库已经超过最大自动连接次数,将备份数据库作为主数据库提供服务;
响应于在备份数据库中建立事务执行SQL命令,识别对备份数据库的更新操作并将SQL命令记录在RabbitMQ队列中,并停止Worker工作进程;
响应于主数据库恢复,重新启动Worker工作进程以将更新操作备份到主数据库中。
本发明具有以下有益技术效果:本发明实施例提供的数据库在线热备份的方法,通过基于DBUtils将主数据库进行封装并连接到备份数据库,并在所述主数据库中建立缓存列表;响应于在主数据库中建立事务执行SQL命令,识别对主数据库的更新操作并将与其相关的SQL命令记录在缓存列表中;响应于事务提交,将缓存列表中的SQL命令按序放入RabbitMQ队列中并清空缓存列表;经由Celery的异步机制调用Worker工作进程连接备份数据库异步执行RabbitMQ队列中的SQL命令以完成备份的技术方案,能够实现数据库在线实时热备份并支持在线主备切换,保障业务系统安全稳定运行,能够显著降低数据库所占磁盘空间增长速度,且配置简单,大 幅提高运维效率,避免因人为操作引起的数据库备份异常。
附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的实施例。
图1为根据本发明一个实施例的数据库在线热备份的方法的示意性流程图;
图2为根据本发明一个实施例的数据库在线热备份的设备的示意图;
图3为根据本发明一个实施例的数据库在线热备份的过程的示意流程图;
图4为根据本发明一个实施例的主数据库和备份数据库切换的示意流程图。
具体实施方式
为使本发明的目的、技术方案和优点更加清楚明白,以下结合具体实施例,并参照附图,对本发明实施例进一步详细说明。
基于上述目的,本发明的实施例的第一个方面,提出了一种数据库在线热备份的方法的一个实施例。图1示出的是该方法的示意性流程图。
如图1中所示,该方法可以包括以下步骤:
S1基于DBUtils将主数据库进行封装并连接到备份数据库,并在所述主数据库中建立缓存列表;
S2响应于在主数据库中建立事务执行SQL命令,识别对主数据库的更新操作并将与其相关的SQL命令记录在缓存列表中;
S3响应于事务提交,将缓存列表中的SQL命令按序放入RabbitMQ队列中并清空缓存列表;
S4经由Celery的异步机制调用Worker工作进程连接备份数据库异步执行RabbitMQ队列中的SQL命令以完成备份。
本发明提供了一种基于Python的数据库连接池DBUtils+RabbitMQ+Celery的在线热备份的方法。最初需要搭建服务器(Ubantu或Centos等开源Linux系统),并在服务器中安装RabbitMQ、Celery等应用程序,并引入Python的数据库池第三方库DBUtils。运维人员通过配置主备数据库的连接信息、最大自动连接次数,将DBUtils重新封装后连接到主数据库和备份数据库,并基于DBUtils重新封装后的数据库连接池向外提供数据库服务,并为主数据库的连接建立对应的缓存列表。在某一数据库连接建立事务执行SQL命令时,自动识别出更新操作,并将SQL命令记录在数据库连接对应列表中,事务提交时(Commit),将列表中的SQL命令按序放入RabbitMQ队列中并清空列表,根据RabbitMQ队列由Celery的异步机制调用Worker工作进程连接备份数据,异步执行SQL命令,完成在不影响主数据库的前提下的数据库实时同步备份。当主数据库事务回滚(Rollback)时,清空该数据库连接的列表数据。
通过本发明的技术方案,能够实现数据库在线实时热备份并支持在线主备切换,保障业务系统安全稳定运行,能够显著降低数据库所占磁盘空间增长速度,且配置简单,大幅提高运维效率,避免因人为操作引起的数据库备份异常。
在本发明的一个优选实施例中,还包括:配置主数据库和备份数据库的数据库类型、IP地址、最大自动连接次数和邮箱信息。最大连接次数是 尝试连接主数据库的失败次数,超过此值后,将自动将备份数据库切换成主数据库向外提供服务,当检测到主数据异常时,向配置的邮箱地址发送邮件通知运维人员进行维护。
在本发明的一个优选实施例中,更新操作包括插入、更新和删除。
在本发明的一个优选实施例中,还包括:
通过自动捕捉识别主数据库连接是否异常;
响应于主数据库连接异常,发送邮件通知运维人员。检测到主数据库异常时还可以发出声音报警或者设置报警灯提示异常。
在本发明的一个优选实施例中,还包括:
响应于主数据库异常并且连接主数据库已经超过最大自动连接次数,将备份数据库作为主数据库提供服务;
响应于在备份数据库中建立事务执行SQL命令,识别对备份数据库的更新操作并将SQL命令记录在RabbitMQ队列中,并停止Worker工作进程;
响应于主数据库恢复,重新启动Worker工作进程以将更新操作备份到主数据库中。通过自动捕捉识别(Try+Exception)主数据库连接失败异常,并超过自动连接次数后仍无法连接的,将自动切换为备份数据库作为主数据库对外提供服务,将原主数据库作为备份数据库并邮件通知管理员主数据库异常,此时仍将变更SQL命令消息放入RabbitMQ队列中,但停止Celery的Worker工作进程,利用RabbitMQ队列持久化的特点,当监测到原主数据库恢复后,重新启动Celery的Worker工作进程,由其异步执行队列中的持久化的SQL命令消息,将原主数据库异常期间对原备份数据库的更新操作备份到原主数据库中,然后将原主数据库切换成主数据库向外提供服务。
实施例
如图3所示,数据库在线热备份的过程如下:
(1)首先,准备搭建服务器(Ubantu或Centos等开源Linux系统),并在服务器中安装RabbitMQ、Celery等应用程序,并引入Python的数据库池第三方库DBUtils。运维人员完成主备数据库连接信息(数据库类型、IP地址等)、最大自动连接次数、邮箱等信息,完成配置后启动服务(包括RabbitMQ和Celery)并自动验证主备数据库连接是否正常,验证无误后业务模块引入基于DBUtils重新封装后的数据库连接池,作为数据库执行模块。
(2)业务系统访问数据库服务,新建数据库连接,并分配绑定的缓存列表。自动识别出数据库更新操作(Insert/Update/Delete),并将SQL命令按序记入连接对应列表中。
(3)在数据库事务提交(Commit)时,主库完成提交后,将绑定列表中的SQL命令按序放入RabbitMQ队列中并清空列表数据,由Celery的异步机制调用Workers进程,异步连接备份数据库并执行SQL命令。在数据库事务回滚(Rollback)时,主库完成回滚后,清空绑定列表中的数据。
如图4所示,主数据库和备份数据库切换的过程如下:
在主数据库SQL命令执行异常,自动捕捉识别(Try+Exception)异常为数据库连接异常时,设置自动重连主库(次数≤最大自动连接数),当超过自动连接次数后仍无法连接时,将自动切换备份数据库作为主数据库对外提供服务。将原主数据库作为备份数据库并邮箱通知运维人员主数据库异常,此时仍将SQL命令消息放入RabbitMQ队列中,同时停止Celery的Worker进程,利用RabbitMQ队列持久化的特点,当监测到原数据库恢复后,重新启动Celery的Worker进程,由其异步执行队列中的持久化的SQL命令消息,自动完成数据同步。
通过本发明的技术方案,能够实现数据库在线实时热备份并支持在线 主备切换,保障业务系统安全稳定运行,能够显著降低数据库所占磁盘空间增长速度,且配置简单,大幅提高运维效率,避免因人为操作引起的数据库备份异常。
需要说明的是,本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,可以通过计算机程序来指令相关硬件来完成,上述的程序可存储于计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中存储介质可为磁碟、光盘、只读存储器(Read-Only Memory,ROM)或随机存取存储器(Random Access Memory,RAM)等。上述计算机程序的实施例,可以达到与之对应的前述任意方法实施例相同或者相类似的效果。
此外,根据本发明实施例公开的方法还可以被实现为由CPU执行的计算机程序,该计算机程序可以存储在计算机可读存储介质中。在该计算机程序被CPU执行时,执行本发明实施例公开的方法中限定的上述功能。
基于上述目的,本发明的实施例的第二个方面,提出了一种数据库在线热备份的设备,如图2所示,设备200包括:
连接模块201,连接模块201配置为基于DBUtils将主数据库进行封装并连接到备份数据库,并在所述主数据库中建立缓存列表;
识别模块202,识别模块202配置为响应于在主数据库中建立事务执行SQL命令,识别对主数据库的更新操作并将与其相关的SQL命令记录在缓存列表中;
写入模块203,写入模块203配置为响应于事务提交,将缓存列表中的SQL命令按序放入RabbitMQ队列中并清空缓存列表;
备份模块204,备份模块204配置为经由Celery的异步机制调用Worker工作进程连接备份数据库异步执行RabbitMQ队列中的SQL命令以完成备 份。
在本发明的一个优选实施例中,还包括配置模块,配置模块配置为配置主数据库和备份数据库的数据库类型、IP地址、最大自动连接次数和邮箱信息。
在本发明的一个优选实施例中,更新操作包括插入、更新和删除。
在本发明的一个优选实施例中,还包括判断模块,判断模块配置为:
通过自动捕捉识别主数据库连接是否异常;
响应于主数据库连接异常,发送邮件通知运维人员。
在本发明的一个优选实施例中,还包括切换模块,切换模块配置为:
响应于主数据库异常并且连接主数据库已经超过最大自动连接次数,将备份数据库作为主数据库提供服务;
响应于在备份数据库中建立事务执行SQL命令,识别对备份数据库的更新操作并将SQL命令记录在RabbitMQ队列中,并停止Worker工作进程;
响应于主数据库恢复,重新启动Worker工作进程以将更新操作备份到主数据库中。
需要特别指出的是,上述系统的实施例采用了上述方法的实施例来具体说明各模块的工作过程,本领域技术人员能够很容易想到,将这些模块应用到上述方法的其他实施例中。
此外,上述方法步骤以及系统单元或模块也可以利用控制器以及用于存储使得控制器实现上述步骤或单元或模块功能的计算机程序的计算机可读存储介质实现。
本领域技术人员还将明白的是,结合这里的公开所描述的各种示例性逻辑块、模块、电路和算法步骤可以被实现为电子硬件、计算机软件或两 者的组合。为了清楚地说明硬件和软件的这种可互换性,已经就各种示意性组件、方块、模块、电路和步骤的功能对其进行了一般性的描述。这种功能是被实现为软件还是被实现为硬件取决于具体应用以及施加给整个系统的设计约束。本领域技术人员可以针对每种具体应用以各种方式来实现的功能,但是这种实现决定不应被解释为导致脱离本发明实施例公开的范围。
上述实施例,特别是任何“优选”实施例是实现的可能示例,并且仅为了清楚地理解本发明的原理而提出。可以在不脱离本文所描述的技术的精神和原理的情况下对上述实施例进行许多变化和修改。所有修改旨在被包括在本公开的范围内并且由所附权利要求保护。

Claims (10)

  1. 一种数据库在线热备份的方法,其特征在于,包括以下步骤:
    基于DBUtils将主数据库进行封装并连接到备份数据库,并在所述主数据库中建立缓存列表;
    响应于在所述主数据库中建立事务执行结构化查询语言命令,识别对所述主数据库的更新操作并将与其相关的结构化查询语言命令记录在所述缓存列表中;
    响应于所述事务提交,将所述缓存列表中的所述结构化查询语言命令按序放入RabbitMQ队列中并清空所述缓存列表;
    经由Celery的异步机制调用Worker工作进程连接所述备份数据库异步执行所述RabbitMQ队列中的所述结构化查询语言命令以完成备份。
  2. 根据权利要求1所述的方法,其特征在于,还包括:配置所述主数据库和所述备份数据库的数据库类型、IP地址、最大自动连接次数和邮箱信息。
  3. 根据权利要求1所述的方法,其特征在于,所述更新操作包括插入、更新和删除。
  4. 根据权利要求1所述的方法,其特征在于,还包括:
    通过自动捕捉识别所述主数据库连接是否异常;
    响应于所述主数据库连接异常,发送邮件通知运维人员。
  5. 根据权利要求4所述的方法,其特征在于,还包括:
    响应于所述主数据库异常并且连接所述主数据库已经超过最大自动连接次数,将所述备份数据库作为主数据库提供服务;
    响应于在所述备份数据库中建立事务执行结构化查询语言命令,识别对 所述备份数据库的更新操作并将所述结构化查询语言命令记录在所述RabbitMQ队列中,并停止所述Worker工作进程;
    响应于所述主数据库恢复,重新启动所述Worker工作进程以将所述更新操作备份到所述主数据库中。
  6. 一种数据库在线热备份的设备,其特征在于,所述设备包括:
    连接模块,所述连接模块配置为基于DBUtils将主数据库进行封装并连接到备份数据库,并在所述主数据库中建立缓存列表;
    识别模块,所述识别模块配置为响应于在所述主数据库中建立事务执行结构化查询语言命令,识别对所述主数据库的更新操作并将与其相关的结构化查询语言命令记录在所述缓存列表中;
    写入模块,所述写入模块配置为响应于所述事务提交,将所述缓存列表中的所述结构化查询语言命令按序放入RabbitMQ队列中并清空所述缓存列表;
    备份模块,所述备份模块配置为经由Celery的异步机制调用Worker工作进程连接所述备份数据库异步执行所述RabbitMQ队列中的所述结构化查询语言命令以完成备份。
  7. 根据权利要求6所述的设备,其特征在于,还包括配置模块,所述配置模块配置为配置所述主数据库和所述备份数据库的数据库类型、IP地址、最大自动连接次数和邮箱信息。
  8. 根据权利要求6所述的设备,其特征在于,所述更新操作包括插入、更新和删除。
  9. 根据权利要求6所述的设备,其特征在于,还包括判断模块,所述判断模块配置为:
    通过自动捕捉识别所述主数据库连接是否异常;
    响应于所述主数据库连接异常,发送邮件通知运维人员。
  10. 根据权利要求9所述的设备,其特征在于,还包括切换模块,所述切换模块配置为:
    响应于所述主数据库异常并且连接所述主数据库已经超过最大自动连接次数,将所述备份数据库作为主数据库提供服务;
    响应于在所述备份数据库中建立事务执行结构化查询语言命令,识别对所述备份数据库的更新操作并将所述结构化查询语言命令记录在所述RabbitMQ队列中,并停止所述Worker工作进程;
    响应于所述主数据库恢复,重新启动所述Worker工作进程以将所述更新操作备份到所述主数据库中。
PCT/CN2020/118334 2020-02-09 2020-09-28 一种数据库在线热备份的方法和设备 WO2021155668A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010083396.6 2020-02-09
CN202010083396.6A CN111324617A (zh) 2020-02-09 2020-02-09 一种数据库在线热备份的方法和设备

Publications (1)

Publication Number Publication Date
WO2021155668A1 true WO2021155668A1 (zh) 2021-08-12

Family

ID=71170943

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/118334 WO2021155668A1 (zh) 2020-02-09 2020-09-28 一种数据库在线热备份的方法和设备

Country Status (2)

Country Link
CN (1) CN111324617A (zh)
WO (1) WO2021155668A1 (zh)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113806121B (zh) * 2021-02-09 2024-05-17 京东科技控股股份有限公司 实例备份异常检测方法、装置及电子设备、存储介质
CN114676118B (zh) * 2022-05-30 2022-08-12 深圳市科力锐科技有限公司 数据库切换方法、装置、设备及存储介质
CN117762692A (zh) * 2023-12-27 2024-03-26 湖南长银五八消费金融股份有限公司 一种数据库异常数据处理方法及系统

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109241175A (zh) * 2018-06-28 2019-01-18 东软集团股份有限公司 数据同步方法、装置、存储介质及电子设备
US20190188047A1 (en) * 2017-12-15 2019-06-20 Rubrik, Inc. On-Demand Provisioning of Customized Developer Environments
CN110046041A (zh) * 2019-04-15 2019-07-23 北京中安智达科技有限公司 一种基于celery调度框架的数据采集方法

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190188047A1 (en) * 2017-12-15 2019-06-20 Rubrik, Inc. On-Demand Provisioning of Customized Developer Environments
CN109241175A (zh) * 2018-06-28 2019-01-18 东软集团股份有限公司 数据同步方法、装置、存储介质及电子设备
CN110046041A (zh) * 2019-04-15 2019-07-23 北京中安智达科技有限公司 一种基于celery调度框架的数据采集方法

Also Published As

Publication number Publication date
CN111324617A (zh) 2020-06-23

Similar Documents

Publication Publication Date Title
WO2021155668A1 (zh) 一种数据库在线热备份的方法和设备
EP2790112B1 (en) Method and system for data synchronization and data access apparatus
US9098454B2 (en) Speculative recovery using storage snapshot in a clustered database
JP4637842B2 (ja) クラスタ化されたコンピューティングシステムにおける高速なアプリケーション通知
CN106776121B (zh) 一种数据灾备装置、系统及方法
US8140483B2 (en) Transaction log management
WO2017177941A1 (zh) 主备数据库切换方法和装置
US20080184063A1 (en) System and Method of Error Recovery for Backup Applications
US7330860B2 (en) Fault tolerant mechanism to handle initial load of replicated object in live system
US20180101558A1 (en) Log-shipping data replication with early log record fetching
US8527454B2 (en) Data replication using a shared resource
KR20140147812A (ko) 데이터베이스로의 미들-티어 트랜잭션 로그들의 인라인 위임을 지원하는 시스템들 및 방법들
WO2019223181A1 (zh) Etl任务数据源切换方法、系统、计算机设备和存储介质
US7401256B2 (en) System and method for highly available data processing in cluster system
CN106325768B (zh) 一种双机存储系统及方法
CN110109772B (zh) 一种cpu的重启方法、通信设备及可读存储介质
US8301750B2 (en) Apparatus, system, and method for facilitating communication between an enterprise information system and a client
CN110798339A (zh) 一种基于分布式任务调度框架的任务容灾方法
US20110173233A1 (en) Database system and database control method
CN101686261A (zh) 一种基于rac的冗余服务器系统
CN111897626A (zh) 一种面向云计算场景的虚拟机高可靠系统和实现方法
CN112631876A (zh) 基于Java的多线程监控系统及方法
US9128903B2 (en) Computer system, active system computer, and standby system computer
CN115934742A (zh) 一种故障处理方法、装置、设备及存储介质
US20130007508A1 (en) Managing storage providers in a clustered appliance environment

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20917334

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20917334

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 20917334

Country of ref document: EP

Kind code of ref document: A1