Data rollback method, device, equipment and medium
By switching the backup node to the primary node in the database and performing data rollback, the problem of long-term unavailability caused by database data recovery failure is solved, and fast data recovery and efficient data management are achieved.
Patent Information
- Application Number
- CN202110193457.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-20
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2041-02-20
AI Technical Summary
In the prior art, when database data recovery fails, the problem of data unreliability cannot be effectively solved, resulting in the database being unavailable for a long time.
A data rollback method is provided. By switching the backup node to the master node and the original master node to the slave node, the backup data is used to roll back the data of the existing node to achieve fast data recovery.
It achieves fast data rollback, avoids long-term database unavailability, and improves the efficiency and reliability of data recovery.
Smart Images

Figure CN114968656B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of database technology, and in particular to a data rollback method, apparatus, device, and medium. Background Art
[0002] To prevent data loss, the database can use a multi-replica set architecture to synchronize data.
[0003] When restoring a database, all nodes need to download and reload external backup data. This external backup data may become unreliable due to attacks or other factors, leading to data recovery failure and the database becoming unavailable. When data recovery fails, existing technologies attempt to retrieve and restore the external backup data again, but this may fail again and fail to resolve the issue. Summary of the Invention
[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a data rollback method, apparatus, device and medium.
[0005] An embodiment of the present disclosure provides a data rollback method, the method comprising:
[0006] Get data rollback request;
[0007] Switch the pre-determined backup node to the current master node, and switch the original master node in the existing nodes to the current slave node;
[0008] Based on the backup data in the current master node, data is rolled back for the existing nodes including the current slave node.
[0009] The present disclosure also provides a data rollback device, the device comprising:
[0010] Request acquisition module, used to obtain data rollback requests;
[0011] A switching module is used to switch a predetermined backup node to the current master node, and to switch the original master node in the stock node to the current slave node;
[0012] A data rollback module is used to roll back data on the existing nodes including the current slave node based on the backup data in the current master node.
[0013] An embodiment of the present disclosure also provides an electronic device, comprising: a processor; a memory for storing instructions executable by the processor; the processor for reading the executable instructions from the memory and executing the instructions to implement the data rollback method provided in the embodiment of the present disclosure.
[0014] An embodiment of the present disclosure further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to execute the data rollback method provided by the embodiment of the present disclosure.
[0015] The technical solution provided by the embodiments of the present disclosure has the following advantages over the existing technology: the data rollback solution provided by the embodiments of the present disclosure obtains a data rollback request; switches the backup node to the current master node, and switches the original master node among the existing nodes to the current slave node; and based on the backup data in the current master node, performs data rollback on the existing nodes including the current slave node. Using the above technical solution, an original node can be used as a backup node. When data rollback is required, the role of the backup node is switched to the master node, and data rollback of all nodes is performed using its backup data, achieving rapid data rollback and preventing the database from falling into a long-term unavailable state. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0017] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0018] Figure 1 A flowchart of a data rollback method provided in an embodiment of the present disclosure;
[0019] Figure 2 A flowchart of another data rollback method provided in an embodiment of the present disclosure;
[0020] Figure 3 A schematic diagram of the structure of a data rollback device provided in an embodiment of the present disclosure;
[0021] Figure 4 A schematic structural diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0022] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features therein can be combined with each other in the absence of conflict.
[0023] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0024] Figure 1 This is a flow chart of a data rollback method provided by an embodiment of the present disclosure. The method can be executed by a data rollback device, wherein the device can be implemented using software and / or hardware and can generally be integrated into an electronic device. Figure 1 As shown, the method includes:
[0025] Step 101: Get a data rollback request.
[0026] The data rollback request is used to request data recovery for all nodes in the database. In the embodiments of this disclosure, the MongoDB database is used as an example. The MongoDB database can adopt a high-availability architecture with a three-node replica set. The three data nodes are located on different physical servers and can automatically synchronize data.
[0027] In the embodiment of the present disclosure, before obtaining the data rollback request, it also includes: obtaining a data recovery request; adding a blank node, and replacing the blank node with the target node, wherein the target node is the original master node, the original slave node or the original hidden node; performing data recovery on the replaced original master node, the original slave node and the original hidden node based on the external backup data. When the user finds a problem or needs to use historical data, a data recovery request can be initiated. The replica set of the database can provide three roles. The hidden node is a data node that does not support access by default in the database. The primary node is a data node that supports read and write requests. The secondary node is a data node that supports read-only requests. The primary node and the secondary node provide services. When the primary node fails, the system can automatically elect a new primary node. When the slave node is unavailable, the backup node takes over the service to ensure service availability in multiple ways. The original hidden node, the original master node and the original slave node refer to the nodes of the three roles before data recovery.
[0028] A blank node refers to a data node with empty data. The target node is one of the original master node, original slave node, and original hidden node. Since the original master node and the original slave node support access, when the original master node or the original slave node is used as the target node, a new one needs to be re-determined and the external access network needs to be switched. The target node is preferably the original hidden node, which has the lowest impact on user access. The blank node replaces the target node, and the name of the replaced target node remains unchanged. After that, the replaced original master node, original slave node, and original hidden node can all download external backup data, perform data recovery, and re-establish the replica set. Among them, the external backup data can be the backup data of the database stored in an external device. The external backup data can include physical backup data and incremental backup data, etc. For example, when the target node is the original hidden node, the blank node replaces the original hidden node as the new original hidden node. After that, the original master node, original slave node, and the replaced original hidden node can perform data recovery through the external backup data.
[0029] In an embodiment of the present disclosure, obtaining a data rollback request includes: if it is detected that the result of data recovery is a data recovery failure, determining that a data rollback request has been obtained. External backup data may become unreliable due to attacks or other reasons. Therefore, when it is detected that the result of the data recovery is a data recovery failure, it can be determined that a data rollback request has been obtained, triggering a data rollback. Optionally, when it is detected that the database is unavailable, or when a fault message such as data loss is received from a user, the result of the data recovery is determined to be a data recovery failure.
[0030] Step 102: Switch the predetermined backup node to the current master node, and switch the original master node in the stock nodes to the current slave node.
[0031] The backup node is a node previously determined during the data recovery process. In the disclosed embodiment, the backup node can be the original master node, the original slave node, or the original hidden node. In the disclosed embodiment, before adding a blank node and replacing the target node with the blank node, the process also includes: determining the target node as a backup node. After the target node is determined as a backup node, the target node no longer participates in data synchronization.
[0032] Specifically, after receiving a data rollback request, the backup node can be switched to the current master node and the original master node to the current slave node by modifying the role information. Existing nodes are nodes included in the database replica set. After the original master node is switched, the existing nodes can include the current slave node, the original slave node, and the original hidden node. One of the existing nodes is replaced by a blank node.
[0033] Step 103: Based on the backup data in the current master node, roll back the data of the existing nodes including the current slave node.
[0034] Data rollback refers to the act of restoring data to its historically correct state when a data processing error occurs. In the disclosed embodiment, this refers to restoring data to its historical state when data recovery fails. The backup data in the current master node is the node data at the time of data recovery described above. This differs from the time of the external backup data described above. The external backup data can be the node data stored at the backup time before the data recovery, for example, the node data stored one day before the data recovery.
[0035] Specifically, based on the backup data in the current master node, data rollback is performed on the existing nodes including the current slave node, including: synchronizing the backup data in the current master node to the current slave node, the original slave node, and the original hidden node through the consistency protocol. Among them, the consistency protocol (Raft protocol), also known as the data replication protocol, is a protocol for achieving data consistency between nodes in a database replica set. Through the consistency protocol, the backup data of the current master node can be synchronized to the current slave node, the original slave node, and the original hidden node, so that the data of all nodes in the database can be correctly restored.
[0036] The data rollback solution provided by the disclosed embodiment receives a data rollback request; switches the backup node to the current master node, and switches the original master node among the existing nodes to the current slave node; and based on the backup data in the current master node, performs a data rollback on the existing nodes, including the current slave node. Using the above technical solution, an original node can be used as a backup node. When data rollback is required, the backup node's role is switched to the master node, and data rollback of all nodes is performed using its backup data, achieving rapid data rollback and preventing the database from being unavailable for a long time.
[0037] In some embodiments, after performing data recovery on the replaced original master node, original slave node, and original hidden node based on external backup data, the method may further include: if the data recovery result is determined to be successful, deleting the backup node after a set time. The set time can be pre-set based on actual conditions, for example, two days. If the data recovery result is successful, the backup node can be deleted after the set time, and the resources of the backup node can be released to save storage resources.
[0038] Figure 2 This is a flow chart of another data rollback method provided by the embodiment of the present disclosure. This embodiment further optimizes the above data rollback method based on the above embodiment. Figure 2 As shown, the method includes:
[0039] Step 201: Obtain a data recovery request.
[0040] Step 202: Determine the target node as a backup node.
[0041] The target node is the original master node, the original slave node or the original hidden node.
[0042] Step 203: Add a blank node and replace the target node with the blank node.
[0043] Step 204: Perform data recovery on the replaced original master node, original slave node, and original hidden node based on the external backup data.
[0044] Step 205 : Whether it is detected that the result of data recovery is successful, if so, execute step 209 ; otherwise, execute step 206 .
[0045] Step 206: Get a data rollback request.
[0046] Step 207: Switch the predetermined backup node to the current master node, and switch the original master node in the stock nodes to the current slave node.
[0047] The backup node is the original master node, the original slave node or the original hidden node.
[0048] Step 208: Based on the backup data in the current master node, roll back the data of the existing nodes including the current slave node.
[0049] The stock nodes include the current slave node, the original slave node and the original hidden node, and one of the stock nodes is replaced by a blank node.
[0050] Rolling back data of the existing nodes including the current slave node based on the backup data in the current master node may include: synchronizing the backup data in the current master node to the current slave node, the original slave node and the original hidden node through a data consistency protocol.
[0051] Step 209: Delete the backup node after the set time.
[0052] In the embodiments of the present disclosure, MongoDB database is used as an example for explanation. Specifically, the configuration management function of MongoDB can be used to complete node management at the MongoDB level; the relationship between container nodes equipped with database services on the database platform can be used; and the backup function of MongoDB can be used to achieve synchronization between newly added blank nodes and existing nodes.
[0053] In this solution, database backup and recovery are achieved by adding blank nodes, and the existing method of restoring all node data is replaced by node replacement. This allows the instance to quickly enable the data on the old node for a quick rollback when data recovery encounters an error. Compared to the existing solution of restoring data through external backup, this solution is less time-consuming because the backup time increases with the size of the data, and in extreme cases may even exceed 24 hours. This solution is also faster in rollback. When a data recovery error occurs, the removed old node can be directly used as the new primary node to restore the data without the need for the backup and recovery process, which greatly reduces user unavailable time.
[0054] The data rollback solution provided by the embodiment of the present disclosure obtains a data recovery request, determines the target node as a backup node, adds a blank node, and replaces the target node with the blank node. If it is detected that the result of data recovery is a data recovery failure, a data rollback request is obtained, the backup node is switched to the current master node, and the original master node in the stock nodes is switched to the current slave node. Based on the backup data in the current master node, the data of the stock nodes including the current slave node is rolled back; if it is detected that the result of data recovery is a data recovery success, the backup node is deleted after a set time. By adopting the above technical solution, an original node can be used as a backup node. When data rollback is required, the role of the backup node is switched to the master node, and the data of all nodes are rolled back through its backup data, thereby achieving rapid data rollback and preventing the database from falling into an unavailable state for a long time.
[0055] Figure 3 This is a schematic diagram of the structure of a data rollback device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware and can generally be integrated into an electronic device. Figure 3 As shown, the device includes:
[0056] Request acquisition module 301, used to obtain a data rollback request;
[0057] The switching module 302 is used to switch the predetermined backup node to the current master node, and switch the original master node in the existing nodes to the current slave node;
[0058] The data rollback module 303 is configured to roll back data of the existing nodes including the current slave node based on the backup data in the current master node.
[0059] The data rollback solution provided by the disclosed embodiment receives a data rollback request; switches the backup node to the current master node, and switches the original master node among the existing nodes to the current slave node; and based on the backup data in the current master node, performs a data rollback on the existing nodes, including the current slave node. Using the above technical solution, an original node can be used as a backup node. When data rollback is required, the backup node's role is switched to the master node, and data rollback of all nodes is performed using its backup data, achieving rapid data rollback and preventing the database from being unavailable for a long time.
[0060] Optionally, the device further includes a data recovery module, which is specifically configured to: before obtaining the data rollback request, further include:
[0061] Get data recovery request;
[0062] Add a blank node and replace the target node with the blank node, wherein the target node is the original master node, the original slave node or the original hidden node;
[0063] Data recovery is performed on the replaced original master node, the original slave node, and the original hidden node based on the external backup data.
[0064] Optionally, the existing nodes include the current slave node, the original slave node and the original hidden node, and one of the existing nodes is replaced by the blank node.
[0065] Optionally, the data rollback module 303 is specifically configured to:
[0066] The backup data in the current master node is synchronized to the current slave node, the original slave node and the original hidden node through a consistency protocol.
[0067] Optionally, the data recovery module is further configured to: add a blank node and replace the blank node with the target node.
[0068] The target node is determined as a backup node.
[0069] Optionally, the device further includes a backup deletion module, specifically configured to: after performing data recovery on the replaced original master node, the original slave node, and the original hidden node based on external backup data,
[0070] If it is determined that the result of the data recovery is that the data recovery is successful, the backup node is deleted after a set time.
[0071] Optionally, the request acquisition module 301 is specifically configured to:
[0072] If it is detected that the result of the data recovery is a data recovery failure, it is determined that a data rollback request is obtained.
[0073] The data rollback device provided in the embodiments of the present disclosure can execute the data rollback method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0074] Figure 4 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. Figure 4 As shown, the electronic device 400 includes one or more processors 401 and a memory 402 .
[0075] The processor 401 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 400 to perform desired functions.
[0076] The memory 402 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. The non-volatile memory may include, for example, read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 401 may execute the program instructions to implement the data rollback method of the embodiment of the present disclosure described above and / or other desired functions. Various contents such as input signals, signal components, noise components, etc. may also be stored in the computer-readable storage medium.
[0077] In one example, the electronic device 400 may further include an input device 403 and an output device 404 , and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).
[0078] In addition, the input device 403 may also include, for example, a keyboard, a mouse, and the like.
[0079] The output device 404 can output various information to the outside, including determined distance information, direction information, etc. The output device 404 can include, for example, a display, a speaker, a printer, a communication network and its connected remote output device, etc.
[0080] Of course, to simplify, Figure 4Only some of the components related to the present disclosure in the electronic device 400 are shown, and components such as buses, input / output interfaces, etc. are omitted. In addition, the electronic device 400 may further include any other appropriate components according to specific application scenarios.
[0081] In addition to the above-mentioned method and device, the embodiment of the present disclosure may also be a computer program product, which includes computer program instructions, and when the computer program instructions are executed by a processor, the processor executes the data rollback method provided by the embodiment of the present disclosure.
[0082] The computer program product may be written in any combination of one or more programming languages to implement the operations of the disclosed embodiments, including object-oriented programming languages such as Java, C++, and conventional procedural programming languages such as C or similar programming languages. The program code may be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0083] In addition, the embodiment of the present disclosure may also be a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the processor executes the data rollback method provided by the embodiment of the present disclosure.
[0084] The computer-readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can, for example, include but is not limited to a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0085] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.
[0086] The foregoing description is intended only to provide specific embodiments of the present disclosure, intended to enable those skilled in the art to understand and implement the present disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the embodiments described herein, but rather to be construed in the broadest manner consistent with the principles and novel features disclosed herein.
Claims
1. A data rollback method, characterized in that: include: Get data recovery request; Add a blank node and replace the target node with the blank node, wherein the target node is the original master node, the original slave node or the original hidden node; Performing data recovery on the replaced original master node, the original slave node, or the original hidden node based on external backup data; Get data rollback request; Switching a predetermined backup node to a current master node, and switching an original master node among existing nodes to a current slave node, wherein the backup node is the original master node, the original slave node, or the original hidden node, and the existing nodes include the current slave node, the original slave node, and the original hidden node, and one of the existing nodes is replaced by the blank node; Based on the backup data in the current master node, data is rolled back for the existing nodes including the current slave node.
2. The method according to claim 1, characterized in that Rolling back data of the existing nodes including the current slave node based on the backup data in the current master node includes: The backup data in the current master node is synchronized to the current slave node, the original slave node and the original hidden node through a consistency protocol.
3. The method according to claim 1, characterized in that Adding a blank node and replacing the blank node before the target node also includes: The target node is determined as a backup node.
4. The method according to claim 3, characterized in that After restoring data of the replaced original master node, the original slave node, or the original hidden node based on the external backup data, the method further includes: If it is determined that the result of the data recovery is that the data recovery is successful, the backup node is deleted after a set time.
5. The method according to claim 1, characterized in that The obtaining of the data rollback request includes: If it is detected that the result of the data recovery is a data recovery failure, it is determined that a data rollback request is obtained.
6. A data rollback device, characterized in that: include: A data recovery module, used to obtain data recovery requests; Adding a blank node and replacing a target node with the blank node, wherein the target node is an original master node, an original slave node, or an original hidden node; performing data recovery on the replaced original master node, the original slave node, or the original hidden node based on external backup data; Request acquisition module, used to obtain data rollback requests; a switching module, configured to switch a predetermined backup node to the current master node, and switch an original master node among the existing nodes to the current slave node, wherein the backup node is the original master node, the original slave node, or the original hidden node, and the existing nodes include the current slave node, the original slave node, and the original hidden node, and one of the existing nodes is obtained by replacing the blank node; A data rollback module is used to roll back data on the existing nodes including the current slave node based on the backup data in the current master node.
7. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing instructions executable by the processor; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the data rollback method described in any one of claims 1-5.
8. A computer-readable storage medium, characterized in that The storage medium stores a computer program, and the computer program is used to execute the data rollback method described in any one of claims 1 to 5.
Citation Information
Patent Citations
Volume recovering method and device
CN107656838A
Data backup method and device, node equipment and readable storage medium
CN111831475A