Database online backup method and device, equipment and medium
By using the target node for online backup in the MongoDB replica cluster, the problem of physical backup consistency and downtime of databases is solved, and online consistent backup is achieved, reducing business impact.
Patent Information
- Application Number
- CN202310639421.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-31
- Publication Date
- 2024-12-03
AI Technical Summary
In the prior art, when physical backup of MongoDB databases is performed, in order to ensure consistency, the database is usually shut down, resulting in too long downtime of the database and affecting business operations.
By connecting to the target node in the MongoDB replica cluster, sending status adjustment instructions to it to pause synchronization with the master node's data, and then sending backup instructions to perform data backup. Finally, the target state is released after the backup is completed, ensuring the consistency of the backup data. It does not affect the operation of the master node.
The online consistent physical backup of MongoDB replica cluster is implemented, which avoids database downtime, ensures data consistency and reduces backup time.
Smart Images

Figure CN119065892A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of data backup, and in particular to a database online backup method, device, equipment and medium. Background Art
[0002] As the degree of digitalization continues to increase, the amount of data involved in work and life is increasing. People use databases to store and manage this data, making data consumption more convenient. However, database storage also has many security risks, such as natural disasters, hacker attacks, technical failures, etc., which may cause database crashes. Therefore, in order to ensure data security, it is necessary to back up the database so that data can be restored when the database crashes.
[0003] MongoDB is a database based on distributed file storage. When performing a physical backup of a MongoDB database, it is necessary to ensure the consistency of the physical backup, that is, all the data contained in the backup is from the same system time point, so that after the database is restored using the consistent backup file, there is no need to perform a recovery operation. In order to ensure the consistency of the physical backup, the existing solution usually shuts down the database for backup. When the database is shut down, it cannot provide services to users. However, the amount of data stored in the database is too large, and the shutdown backup will cause the database to be shut down for a long time, which has a great impact on the business. 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 database online backup method, device, equipment and medium.
[0005] In a first aspect, the present disclosure provides a database online backup method, comprising:
[0006] Connecting to a target node in a MongoDB replica cluster, the target node being used to synchronize data of a master node of the MongoDB replica cluster;
[0007] Sending a state adjustment instruction to the target node to adjust the target node to a target state, wherein the target node suspends data synchronization with the master node in the target state;
[0008] Sending a backup instruction to the target node so that the target node backs up the data in the target node to a target storage device;
[0009] After receiving a feedback message indicating that the target node has completed the backup, an unlock instruction is sent to the target node to release the target node from the target state.
[0010] Optionally, sending a backup instruction to the target node so that the target node backs up the data in the target node to a target storage device includes:
[0011] A backup instruction for the metadata and basic data is sent to the target node, so that the target node backs up the metadata and basic data on the target node to a target storage device.
[0012] Optionally, the sending a backup instruction for metadata backup and basic data to the target node includes:
[0013] Sending a metadata backup instruction to the target node so that the target node backs up the metadata to a target storage device;
[0014] In response to receiving a first feedback message indicating that the metadata backup is completed, sending a basic data backup instruction to the target node, so that the target node backs up the metadata to a target storage device;
[0015] After receiving the feedback message that the target node has completed the backup, sending an unlock instruction to the target node so that the target node releases the target state includes:
[0016] After receiving the first feedback message indicating that the metadata backup is completed, an unlock instruction is sent to the target node.
[0017] Optionally, the target node generates a backup cursor in the target state, and when the backup cursor exists, the target node is prohibited from deleting and modifying the basic data;
[0018] The method further comprises:
[0019] After receiving the first feedback message indicating that the basic data backup is completed, a release instruction is sent to the target node, so that the target node releases the backup cursor.
[0020] Optionally, before sending the backup instruction for the metadata and the basic data to the target node, the method further includes:
[0021] Sending an acquisition instruction to the target node so that the target node returns the data storage address in its service configuration;
[0022] The sending a backup instruction for metadata and basic data to the target node includes:
[0023] Based on the data storage address, a backup instruction for the metadata and basic data is sent to the target node.
[0024] Optionally, the sending a backup instruction for the metadata to the target node based on the data storage address includes:
[0025] Sending a metadata packaging instruction to the target node, so that the target node packages the metadata in the data storage address and generates a metadata backup file;
[0026] The metadata backup file is stored on a target storage device.
[0027] Optionally, the sending a backup instruction for basic data to the target node based on the data storage address includes:
[0028] Sending a basic data packaging instruction to the target node, so that the target node packages and compresses the basic data in the data storage address to generate a basic data backup file;
[0029] The basic data backup file is stored on a target storage device.
[0030] In a second aspect, the present disclosure provides a database online backup device, comprising:
[0031] A connection module, used to connect to a target node in a MongoDB replica cluster, wherein the target node is used to synchronize data of a master node of the MongoDB replica cluster;
[0032] A locking module, used for sending a state adjustment instruction to the target node to adjust the target node to a target state, and the target node suspends data synchronization with the master node in the target state;
[0033] A backup module, used for sending a backup instruction to the target node, so that the target node backs up the data in the target node to a target storage device;
[0034] The unlocking module is used to send an unlocking instruction to the target node after receiving a feedback message that the target node has completed the backup, so that the target node releases the target state.
[0035] Optionally, when the backup module sends a backup instruction to the target node so that the target node backs up the data in the target node to the target storage device, the backup module is specifically used to send a backup instruction for metadata and basic data to the target node so that the target node backs up the metadata and basic data on the target node to the target storage device.
[0036] Optionally, when the backup module sends the backup instruction for metadata backup and basic data to the target node, it is specifically used to send the metadata backup instruction to the target node, so that the target node backs up the metadata to the target storage device; in response to receiving the first feedback message of the end of the metadata backup, send the basic data backup instruction to the target node, so that the target node backs up the metadata to the target storage device;
[0037] After receiving the feedback message that the target node has completed the backup, the unlocking module sends an unlocking instruction to the target node to release the target node from the target state. Specifically, it is used to send the unlocking instruction to the target node after receiving the first feedback message that the metadata backup is completed.
[0038] Optionally, the target node generates a backup cursor in the target state, and when the backup cursor exists, the target node is prohibited from deleting and modifying the basic data;
[0039] The unlocking module is further configured to send a release instruction to the target node after receiving a second feedback message indicating that the basic data backup is completed, so that the target node releases the backup cursor.
[0040] Optionally, the device further comprises an acquisition module, which is used to send an acquisition instruction to the target node before sending a backup instruction for the metadata and basic data to the target node, so that the target node returns the data storage address in its service configuration;
[0041] When the backup module sends the backup instruction for the metadata and basic data to the target node, the backup module is specifically configured to send the backup instruction for the metadata and basic data to the target node based on the data storage address.
[0042] Optionally, when the backup module sends a backup instruction for the metadata to the target node based on the data storage address, the backup module is specifically used to send a metadata packaging instruction to the target node so that the target node packages the metadata in the data storage address to generate a metadata backup file; and stores the metadata backup file on the target storage device.
[0043] Optionally, when the backup module sends a backup instruction for the basic data to the target node based on the data storage address, the backup module is specifically used to send a basic data packaging instruction to the target node, so that the target node packages and compresses the basic data in the data storage address to generate a basic data backup file; and stores the basic data backup file on the target storage device.
[0044] In a third aspect, the present disclosure provides an electronic device, including:
[0045] Memory;
[0046] Processor; and
[0047] Computer programs;
[0048] The computer program is stored in the memory and is configured to be executed by the processor to implement the method described in any one of the first aspects.
[0049] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method as described in any one of the first aspects.
[0050] Compared with the prior art, the technical solution provided by the present invention has the following advantages:
[0051] The database online backup method, device, equipment and medium provided by the present disclosure connect the target node that synchronizes data with the master node in the MongoDB replica cluster, and send a state adjustment instruction to the target node to adjust the target node to the target state, and then send a backup instruction to the target node to make the target node back up the data in the target node to the target storage device, and finally send an unlock instruction to the target node after receiving the feedback message that the target node has completed the backup, so that the target node releases the target state. During the backup process, because the target node suspends data synchronization with the master node when it is in the target state, the data of the target node will not be modified concurrently when backing up the data of the target node, so the backup data of the target node is in a consistent state, ensuring the consistency of the physical backup data, and the master node in the MongoDB replica cluster is not shut down, thereby realizing the online consistent physical backup of the MongoDB replica cluster. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] 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.
[0053] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0054] Figure 1 A flowchart of a database online backup method provided by an embodiment of the present disclosure;
[0055] Figure 2A schematic diagram of an application scenario provided by an embodiment of the present disclosure;
[0056] Figure 3 A flowchart of a database online backup method provided by another embodiment of the present disclosure;
[0057] Figure 4 A schematic diagram of the structure of a database online backup device provided by an embodiment of the present disclosure;
[0058] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0059] 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 in the embodiments can be combined with each other without conflict.
[0060] 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.
[0061] Figure 1 This is a flow chart of a database online backup method provided by an embodiment of the present disclosure. The method can be executed by a database online backup device. The database online backup device can be implemented in software and / or hardware. The database online backup device can be configured in a terminal, wherein the terminal includes electronic devices such as computers and mobile phones. The method includes the following steps:
[0062] S101. Connect to a target node in a MongoDB replica cluster. The target node is used to synchronize data of a primary node in the MongoDB replica cluster.
[0063] MongoDB is an open source, high-performance non-relational database, also known as NoSQL database, which provides a rich query language and flexible data model. The MongoDB replica cluster includes the primary node, secondary node and hidden node. The primary node is the control center of the entire cluster, responsible for processing all write operations and replying to client confirmation requests. In the event of failure, restart or downtime of the primary node, a new primary node will be re-elected; the slave node can only perform read operations, and often uses the replication mechanism to keep data synchronized with the primary node. If the primary node fails, the slave node will be able to participate in the re-election process and then be promoted to the primary node; the hidden node refers to the member hidden in the replica set. They will not publish their own status and data and cannot be directly read, written or queried. The data and documents stored in the hidden node are synchronized with other nodes, but will not be passed to the client as a copy of the data returned from the reference server.
[0064] Figure 2 A schematic diagram of an application scenario provided for an embodiment of the present disclosure, the scenario includes a MongoDB replica cluster 210 and a computer 220, wherein the MongoDB replica cluster 210 is composed of a primary node 211, a secondary node 212, and a hidden node 213, and each node occupies a server exclusively.
[0065] Exemplarily, the embodiment of the present disclosure performs a one-time backup of a physical snapshot through a hidden node 213, that is, the target node in the embodiment of the present disclosure is a hidden node in a MongoDB replica cluster. The computer 220 connects to the MongoDB service of the hidden node 213 through a MongoDB Shell client installed thereon. The MongoDB Shell client is the default command line tool used by MongoDB. The MongoDB Shell client can be used to interact with the database. The MongoDB service is a daemon or background process used to run, manage, and maintain the MongoDB database.
[0066] S102: Send a state adjustment instruction to the target node to adjust the target node to a target state. The target node suspends data synchronization with the master node in the target state.
[0067] The disclosed embodiment encapsulates three internal commands by modifying the MongoDB code, namely, a state adjustment command (fbackup), an unlock command (fbackupUnlock), and a release command (fbackupEnd).
[0068] The state adjustment instruction is used to adjust the target node to the target state. In the target state, the database of the target node is locked and data synchronization is suspended. In some embodiments, the target node simultaneously applies for a backup cursor of the storage engine (e.g., the WiredTiger engine) in the target state. When the backup cursor exists, the target node is prohibited from deleting and changing the basic data. In other words, during the existence of the backup cursor, the existing data in the underlying data file in the storage engine of the target node will no longer change, and new data will only continue to be stored incrementally based on the existing file structure. Correspondingly, the release instruction is used to release the backup cursor of the target node. The unlock instruction is used to unlock the database of the target node locked by the state adjustment instruction, so that the target node can synchronize data from other nodes.
[0069] Exemplarily, after the computer 220 connects to the MongoDB service of the hidden node 213 through the MongoDB Shell client, the MongoDB Shell client is used to send a state adjustment instruction to the hidden node 213, the hidden node 213 is adjusted to the target state, and the database of the hidden node 213 is locked. At this time, the hidden node 213 suspends data synchronization with the main node 211, that is, the data stored in the hidden node 213 in the target state will not change.
[0070] S103: Send a backup instruction to the target node, so that the target node backs up the data in the target node to the target storage device.
[0071] Computer 220 sends a backup instruction to hidden node 213 through MongoDB Shell client. After receiving the backup instruction, hidden node 213 physically backs up the data in the database and backs up the data in the database to the target storage device, which is the memory of the server where hidden node 213 is located. Since the database is locked when hidden node 213 physically backs up the data in the database, the physical backup generated by hidden node 213 is a consistent backup. Consistent backup means that when backing up data, it is necessary to ensure that the backed-up data is in a consistent state, usually referring to the backed-up data coming from the same system time and without concurrent modification operations. In addition, hidden node 213 does not shut down when backing up data, and can still participate in the voting for the master node election by the secondary node 212 in MongoDB replica cluster 210.
[0072] In some embodiments, sending a backup instruction to a target node so that the target node backs up data in the target node to a target storage device includes: sending a backup instruction for metadata and basic data to the target node so that the target node backs up the metadata and basic data on the target node to a target storage device.
[0073] Metadata is a data used to describe database objects (such as collections, indexes, and documents), including the name, size, index, storage location, and other information of each collection. Basic data is the data actually stored in the MongoDB database, which is usually stored in the form of JSON documents. In MongoDB, basic data is organized in the form of documents. Each document is a piece of data with a fixed format, consisting of one or more fields, and each field has a corresponding value. In other words, basic data is usually the data stored by the user after format conversion.
[0074] In order to reduce the time required for backup, the computer 220 sends a backup instruction for metadata and basic data to the hidden node 213, so that the target node backs up the metadata and basic data to the target storage device, and the database of the hidden node 213 can be quickly restored through the consistent backup of the metadata and basic data. Data that records database execution operations, such as log data and operating status data, do not need to be backed up, thereby reducing the amount of backup data and further reducing the time required for backup.
[0075] The disclosed embodiment sends a backup instruction for metadata and basic data to the target node, so that the target node backs up the metadata and basic data on the target node to the target storage device, thereby reducing the amount of data to be backed up and further reducing the time required for backup.
[0076] S104. After receiving a feedback message indicating that the target node has completed the backup, an unlock instruction is sent to the target node to release the target node from the target state.
[0077] When the hidden node 213 completes the backup, it will return a feedback message of the backup completion to the MongoDB Shell client of the computer 220. After receiving the feedback message of the backup completion, the computer 220 sends an unlock instruction to the hidden node 213 to release the target state of the hidden node 213, that is, unlock the database of the hidden node 213. At this time, the hidden node 213 can continue to synchronize data from the main node 211.
[0078] The disclosed embodiment connects to the target node that synchronizes data with the master node in the MongoDB replica cluster, sends a state adjustment instruction to the target node to adjust the target node to the target state, then sends a backup instruction to the target node to enable the target node to back up the data in the target node to the target storage device, and finally sends an unlock instruction to the target node after receiving a feedback message that the target node has completed the backup, so that the target node releases the target state. During the backup process, because the target node suspends data synchronization with the master node when it is in the target state, the data of the target node will not be modified concurrently when backing up the data of the target node, so the backup data of the target node is in a consistent state, ensuring the consistency of the physical backup data, and the master node in the MongoDB replica cluster is not shut down, thereby realizing the online consistent physical backup of the MongoDB replica cluster.
[0079] Figure 3 This is a flowchart of a database online backup method provided by another embodiment of the present disclosure. Figure 3 As shown, the method comprises the following steps:
[0080] S301. Connect to a target node in a MongoDB replica cluster, where the target node is used to synchronize data of a primary node in the MongoDB replica cluster.
[0081] The implementation process and principle of S301 and S101 are the same and will not be described here.
[0082] S302, sending a state adjustment instruction to the target node to adjust the target node to the target state, and the target node suspends data synchronization with the master node in the target state; the target node generates a backup cursor in the target state, and when the backup cursor exists, the target node is prohibited from deleting and changing the basic data.
[0083] In the target state, the hidden node not only suspends data synchronization with the main node, but also generates a backup cursor. Specifically, the state adjustment instruction locks the database of the target node, preventing the target node from continuing to write, suspending data synchronization, and simultaneously applying for the backup cursor of the storage engine. During the period when the target node has the backup cursor, the existing data in the underlying data file of the database storing the basic data will no longer change, and new data will only continue to be stored incrementally based on the existing structure of the underlying data file. In other words, the basic data of the target node will not be deleted or changed, and new data will only be stored incrementally in the existing underlying data file.
[0084] S303: Send a metadata backup instruction to the target node, so that the target node backs up the metadata to the target storage device.
[0085] After sending the metadata backup instruction to the hidden node, the database of the hidden node is locked when the hidden node backs up the metadata, that is, the hidden node will not perform concurrent modification operations during the metadata backup, ensuring the consistency of the physical backup of the metadata.
[0086] S304: After receiving the first feedback message indicating that the metadata backup is completed, send an unlock instruction to the target node.
[0087] After the hidden node completes the metadata backup, it will return the first feedback message of the metadata backup completion. After receiving the first feedback message, the terminal that initiated the backup will send an unlock command to the hidden node to unlock the database of the hidden node, so that the hidden node can continue to synchronize data from other nodes. At this time, the hidden node has a backup cursor, and when synchronizing data, it will only increment to store new data, and the existing basic data will not be changed or deleted, that is, the basic data corresponding to the metadata backup will not change.
[0088] S305 . In response to receiving the first feedback message indicating that the metadata backup is completed, send a basic data backup instruction to the target node, so that the target node backs up the metadata to the target storage device.
[0089] After sending the basic data backup instruction to the hidden node, when the hidden node backs up the basic data, because the hidden node has a backup cursor at this time, it will only add new basic data, and the existing basic data will not be changed or deleted. Therefore, the basic data backup corresponding to the metadata backup file in the basic data backup file is a consistent physical backup. In this way, when using the metadata backup file and the basic data backup file to restore the database of the hidden node, you only need to keep the basic data backup corresponding to the metadata backup file in the basic data backup file, and delete the new basic data added when the hidden node synchronizes the data when backing up the basic data. You can get a consistent physical backup of the metadata and basic data, so that you can use the consistent physical backup of the metadata and basic data to quickly restore the database of the hidden node.
[0090] Because the amount of metadata is small, the hidden node's database is unlocked after the metadata backup is completed, which not only makes the hidden node lock the database for a short time, but also can obtain a consistent physical backup of metadata and basic data. The hidden node does not shut down when backing up data and can still participate in the MongoDB election vote.
[0091] S306: After receiving the second feedback message indicating that the basic data backup is completed, send a release instruction to the target node so that the target node releases the backup cursor.
[0092] After the hidden node completes the basic data backup, it will return a second feedback message indicating that the basic data backup is completed. After receiving the second feedback message, the terminal that initiated the backup will send a release instruction to the hidden node to release the backup cursor in the hidden node. In this way, the online backup of the database of the MongoDB replica set is completed. When synchronizing data, the hidden node can synchronize the modification operations of the primary node on the existing data before the backup.
[0093] The disclosed embodiment sends a state adjustment instruction to the target node, so that the target node generates a backup cursor when locking the database, and then sends a metadata backup instruction to the target node, so that the target node can be unlocked after the target node completes the metadata backup, allowing the target node to continue to synchronize data, and at the same time send a basic data backup instruction. At this time, because there is a backup cursor, the existing basic data of the target node will not be deleted or changed when synchronizing data, so the basic data backup corresponding to the metadata backup file in the backup file of the basic data is a consistent physical backup. Finally, after receiving the second feedback message of the end of the basic data backup, a release instruction is sent to the target node to release the backup cursor, and the online backup of the database of the MongoDB replica set is ended. Because the amount of metadata data is small, the database of the hidden node is unlocked after the metadata backup is completed, which not only makes the hidden node lock the database for a short time, but also can obtain a consistent physical backup of the metadata and basic data. In addition, the target node does not shut down when backing up data, and can still participate in the voting of the MongoDB master node election.
[0094] In some implementations, before sending a backup instruction for metadata and basic data to the target node, the method further includes: sending a get instruction to the target node so that the target node returns a data storage address in its service configuration;
[0095] Sending a backup instruction for the metadata and basic data to the target node includes: sending a backup instruction for the metadata and basic data to the target node based on the data storage address.
[0096] Exemplarily, after the computer 220 initiates an online database backup to the hidden node 213, that is, after the computer 220 sends a state adjustment instruction to the hidden node 213, the computer 220 uses the MongoDB Shell client to send an acquisition instruction to the hidden node 213, so that the hidden node 213 returns the data storage address configured by the MongoDB service, that is, the address of the data directory. Then, the backup instruction sent by the computer 220 to the hidden node 213 includes the data storage address, so that the hidden node 213 backs up the metadata and basic data in the data storage address.
[0097] In this case, based on the data storage address, a backup instruction for the metadata is sent to the target node, including: sending a metadata packaging instruction to the target node so that the target node packages the metadata in the data storage address and generates a metadata backup file; and storing the metadata backup file on the target storage device.
[0098] Exemplarily, the computer 220 uses the MongoDB Shell client to send a metadata backup instruction to the hidden node 213, thereby entering the hidden node 213, finding the data storage address configured by the MongoDB Shell service of the hidden node 213, and packaging the storage engine metadata in the data storage address. Exemplarily, the following shell command can be used:
[0099] tar-cvf meta.tar WiredTiger*--exclude=WiredTiger.lock
[0100] Among them, tar is a packaging command. Specifically, in the tar-cvf instruction, c means packaging multiple files or directories, v means displaying the packaging process, f means the file name of the specified package, meta.tar is the specified file package name (it can also be a storage address), WiredTiger* means the WiredTiger engine file, exclude is an exclusion instruction, and exclude=WiredTiger.lock means excluding the file with the suffix .lock in the WiredTiger engine. In this way, the storage engine metadata is packaged through the shell command in the metadata packaging instruction to generate a physical snapshot of the metadata. The physical snapshot of the metadata is the metadata backup file, and then the metadata backup file is stored in meta.tar on the storage device of the server where the hidden node 213 is located.
[0101] The embodiment of the present disclosure uses a packing instruction to pack metadata in the data storage address of the target node and generates a metadata backup file to complete the metadata backup of the target node.
[0102] In this case, based on the data storage address, a backup instruction for the basic data is sent to the target node, including: sending a basic data packaging instruction to the target node so that the target node packages and compresses the basic data in the data storage address to generate a basic data backup file; and storing the basic data backup file on the target storage device.
[0103] Exemplarily, the computer 220 uses the MongoDB Shell client to send a basic data backup instruction to the hidden node 213, thereby entering the hidden node 213, finding the data storage address configured by the MongoDB Shell service of the hidden node 213, and packaging all basic data of the storage engine in the data storage address. For example, the following shell command can be used:
[0104] tar --use-compress-program=pigz-cvpf / data / snapshot. / *--exclude=journal
[0105] Among them, tar is a packaging command. Specifically, in the tar-cvpf instruction, p means using the original attributes of the original file (i.e., the file attributes will not change according to the user), use-compress-program=pigz means using the compression program pigz, / data / snapshot is the specified storage address, . / * means all files, and exclude=journal means excluding log files. In this way, all basic data in the storage engine are packaged through the shell command in the basic data packaging instruction to generate a physical snapshot of the basic data, and the physical snapshot of the basic data is compressed to generate a basic data backup file, and the basic data backup file is stored in the file / data / snapshot on the storage device of the server where the hidden node 213 is located.
[0106] During the backup of basic data, the disclosed embodiment uses a compression program to compress the packaged files in parallel, which can speed up the backup of data with a large amount of data, such as basic data.
[0107] Figure 4 The structure diagram of the online database backup device provided in the embodiment of the present disclosure is as follows. The online database backup device may be a component or assembly in the terminal of the above embodiment. The online database backup device provided in the embodiment of the present disclosure may execute the processing flow provided in the online database backup method embodiment, such as Figure 4 As shown, the database online backup device 400 includes:
[0108] A connection module 401 is used to connect to a target node in a MongoDB replica cluster, and the target node is used to synchronize data of a master node in the MongoDB replica cluster;
[0109] The locking module 402 is used to send a state adjustment instruction to the target node so that the target node is adjusted to a target state, and the target node suspends data synchronization with the master node in the target state;
[0110] The backup module 403 is used to send a backup instruction to the target node so that the target node backs up the data in the target node to the target storage device;
[0111] The unlocking module 404 is used to send an unlocking instruction to the target node after receiving a feedback message indicating that the target node has completed the backup, so that the target node releases the target state.
[0112] In some embodiments, when the backup module 403 sends a backup instruction to the target node so that the target node backs up the data in the target node to the target storage device, it is specifically used to send a backup instruction for metadata and basic data to the target node so that the target node backs up the metadata and basic data on the target node to the target storage device.
[0113] In some embodiments, when the backup module 403 sends the backup instruction for metadata backup and basic data to the target node, it is specifically used to send the metadata backup instruction to the target node so that the target node backs up the metadata to the target storage device; in response to receiving the first feedback message of the end of metadata backup, send the basic data backup instruction to the target node so that the target node backs up the metadata to the target storage device;
[0114] After receiving the feedback message that the target node has completed the backup, the unlocking module 404 sends an unlocking instruction to the target node to release the target node from the target state. Specifically, it is used to send the unlocking instruction to the target node after receiving the first feedback message that the metadata backup is completed.
[0115] In some embodiments, the target node generates a backup cursor in the target state, and when the backup cursor exists, the target node is prohibited from deleting and changing the basic data;
[0116] The unlocking module 404 is further configured to send a release instruction to the target node after receiving a second feedback message indicating that the basic data backup is completed, so that the target node releases the backup cursor.
[0117] In some embodiments, the apparatus further includes an acquisition module 405, which is used to send an acquisition instruction to the target node before sending a backup instruction for metadata and basic data to the target node, so that the target node returns the data storage address in its service configuration;
[0118] When the backup module 403 sends the backup instruction for the metadata and basic data to the target node, it is specifically used to send the backup instruction for the metadata and basic data to the target node based on the data storage address.
[0119] In some embodiments, when the backup module 403 sends a backup instruction for metadata to the target node based on the data storage address, it is specifically used to send a metadata packaging instruction to the target node so that the target node packages the metadata in the data storage address and generates a metadata backup file; and stores the metadata backup file on the target storage device.
[0120] In some embodiments, when the backup module 403 sends a backup instruction for basic data to the target node based on the data storage address, it is specifically used to send a basic data packaging instruction to the target node, so that the target node packages and compresses the basic data in the data storage address to generate a basic data backup file; and stores the basic data backup file on the target storage device.
[0121] Figure 4 The database online backup device of the illustrated embodiment can be used to execute the technical solution of the above method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.
[0122] Figure 5 The electronic device provided in the embodiment of the present disclosure can execute the processing flow provided in the embodiment of the online database backup method, such as Figure 5 As shown, the electronic device 500 includes: a memory 501, a processor 502, a computer program and a communication interface 503; wherein the computer program is stored in the memory 501 and is configured to be executed by the processor 502 to perform the above-mentioned database online backup method. In a specific embodiment, the memory 501 can be a non-volatile solid-state memory. In a specific embodiment, the memory 501 includes a read-only memory ROM (Read-Only Memory). In appropriate cases, the ROM can be a mask-programmed ROM, a programmable ROM (Programmable ROM, PROM), an erasable PROM (Electrical Programmable ROM, EPROM), an electrically erasable PROM (Electrically Erasable Programmable ROM, EEPROM), an electrically alterable ROM (Electrically Alterable ROM, EAROM) or a flash memory, or a combination of two or more of these.
[0123] In addition, the embodiment of the present disclosure further provides a computer-readable storage medium on which a computer program is stored, and the computer program is executed by a processor to implement the database online backup method described in the above embodiment. The storage medium can be a non-volatile / non-temporary computer-readable storage medium, for example, the non-volatile / non-temporary computer-readable storage medium can be a ROM, a random access memory (Random Access Memory, RAM), a compact disc read-only memory (Compact Disc ROM, CD-ROM), a magnetic tape, a floppy disk, and an optical data storage device.
[0124] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0125] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be 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 will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A database online backup method, It is characterized in that include: Connecting to a target node in a MongoDB replica cluster, the target node being used to synchronize data of a master node of the MongoDB replica cluster; Sending a state adjustment instruction to the target node to adjust the target node to a target state, wherein the target node suspends data synchronization with the master node in the target state; Sending a backup instruction to the target node so that the target node backs up the data in the target node to a target storage device; After receiving a feedback message indicating that the target node has completed the backup, an unlock instruction is sent to the target node to release the target node from the target state.
2. The method according to claim 1, It is characterized in that The sending of a backup instruction to the target node so that the target node backs up the data in the target node to a target storage device includes: A backup instruction for the metadata and basic data is sent to the target node, so that the target node backs up the metadata and basic data on the target node to a target storage device.
3. The method according to claim 2, It is characterized in that The sending of a backup instruction for metadata backup and basic data to the target node includes: Sending a metadata backup instruction to the target node so that the target node backs up the metadata to a target storage device; In response to receiving a first feedback message indicating that the metadata backup is completed, sending a basic data backup instruction to the target node, so that the target node backs up the metadata to a target storage device; After receiving the feedback message that the target node has completed the backup, sending an unlock instruction to the target node so that the target node releases the target state includes: After receiving the first feedback message indicating that the metadata backup is completed, an unlock instruction is sent to the target node.
4. The method according to claim 3, It is characterized in that The target node generates a backup cursor in the target state, and when the backup cursor exists, the target node is prohibited from deleting and modifying the basic data; The method further comprises: After receiving the second feedback message indicating that the basic data backup is completed, a release instruction is sent to the target node, so that the target node releases the backup cursor.
5. The method according to claim 2, It is characterized in that Before sending the backup instruction for metadata and basic data to the target node, the method further includes: Sending an acquisition instruction to the target node so that the target node returns the data storage address in its service configuration; The sending a backup instruction for metadata and basic data to the target node includes: Based on the data storage address, a backup instruction for the metadata and basic data is sent to the target node.
6. The method according to claim 5, It is characterized in that The step of sending a backup instruction for metadata to the target node based on the data storage address includes: Sending a metadata packaging instruction to the target node, so that the target node packages the metadata in the data storage address and generates a metadata backup file; The metadata backup file is stored on a target storage device.
7. The method according to claim 5, It is characterized in that The sending a backup instruction for basic data to the target node based on the data storage address includes: Sending a basic data packaging instruction to the target node, so that the target node packages and compresses the basic data in the data storage address to generate a basic data backup file; The basic data backup file is stored on a target storage device.
8. A database online backup device, It is characterized in that include: A connection module, used to connect to a target node in a MongoDB replica cluster, wherein the target node is used to synchronize data of a master node of the MongoDB replica cluster; A locking module, used for sending a state adjustment instruction to the target node to adjust the target node to a target state, and the target node suspends data synchronization with the master node in the target state; A backup module, used for sending a backup instruction to the target node, so that the target node backs up the data in the target node to a target storage device; The unlocking module is used to send an unlocking instruction to the target node after receiving a feedback message that the target node has completed the backup, so that the target node releases the target state.
9. An electronic device, It is characterized in that include: Memory; processor; as well as Computer programs; The computer program is stored in the memory and is configured to be executed by the processor to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
