Data backup method, device, node device and readable storage medium

By using LSM storage engine and hard link technology in the database storage system, the problem of low data backup efficiency when the database storage system is upgraded is solved, instant backup and rapid recovery of data files are realized, and data security is improved.

CN111831475BInactive Publication Date: 2024-09-20BEIJING DIDI INFINITY TECH & DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910471293.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-05-31
Publication Date
2024-09-20
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing data backup methods are inefficient and untimely when upgrading database storage systems. Especially when storage resources and bandwidth are limited, it is difficult to effectively solve the problem of data loss.

Method used

Use node devices based on LSM storage engines to detect when the database storage system is upgraded, back up log files and relay data information to the node devices, and use hard links to back up data files to reduce storage resource usage and improve backup efficiency; when needed During rollback, historical snapshot information is used to restore data.

Benefits of technology

It achieves instant backup and rapid recovery of data files, reduces storage and I/O resource usage, improves backup efficiency and data security, and avoids data loss.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111831475B
    Figure CN111831475B
Patent Text Reader

Abstract

The embodiments of the present application provide a data backup method, device, node device and readable storage medium, which relate to the field of data storage technology. The data backup method includes: when it is detected that the database storage system where the node device is located is upgraded, the log file and relay data information are backed up locally on the node device, and the hard link corresponding to the data file is backed up locally on the node device. In the above-mentioned backed up data, the amount of data occupied by the log file and relay data information is relatively small, and the data files that need to occupy a large amount of storage space are backed up using the hard links corresponding to the data files. Since the storage resources occupied by the hard links are very small, when performing data backup, the local storage resources of the node device can meet the data backup requirements, and the I / O resources occupied when writing the backup data are relatively small, and the time to complete the writing is also short, so that the real-time backup of the data files can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data storage, and in particular to a data backup method, apparatus, node device and readable storage medium. Background Art

[0002] Currently, after upgrading, database storage systems may face risks such as data format incompatibility or data being deleted by mistake, resulting in data loss. Data loss is an important indicator for measuring the performance of database storage systems, and it is an inevitable problem involved in database storage system upgrades. In order to avoid data loss caused by database storage system upgrades, the database storage system needs to have data security backup and data rollback functions after the upgrade.

[0003] Most of the current data backup is to store data regularly in local storage media or remote storage media (for example, distributed file systems (Hadoop Distributed File System)). However, when local storage resources are limited, the storage resources may not be able to meet the data that needs to be backed up, resulting in the inability to perform local data backup and low backup efficiency. Using remote storage media for backup also takes up more bandwidth resources. When bandwidth resources are limited, it takes a long time to perform remote data backup, and the timeliness of data backup is poor. Therefore, the above two methods cannot solve the problem of data backup very well. Summary of the invention

[0004] In order to at least overcome the above-mentioned deficiencies in the prior art, one of the purposes of the present application is to provide a data backup method, apparatus, node device and readable storage medium to solve the technical problems of low data backup efficiency and untimely backup in the current data backup process.

[0005] According to one aspect of an embodiment of the present application, a node device is provided, which may include one or more storage media and one or more processors communicating with the storage media. The one or more storage media store machine-readable instructions executable by the processor. When the node device is running, the processor communicates with the storage medium via a bus, and the processor executes the machine-readable instructions to perform the following data backup method.

[0006] According to another aspect of an embodiment of the present application, a data backup method is provided, which is applied to a node device based on an LSM storage engine, and the method includes: detecting whether a database storage system where the node device is located is upgraded, wherein data files, log files and relay data information are stored in the node device, the log file includes data that has not yet been written to the node device memory, and the relay data information includes data metadata and data file configuration; when it is detected that the database storage system where the node device is located is upgraded, the log file and relay data information are backed up in the node device, and the hard links corresponding to the data files are backed up in the node device.

[0007] In some embodiments of the present application, before detecting whether the database storage system where the node device is located is upgraded, the method further includes: writing the data in the data file into the log file; then writing the data written in the log file into the memory; and when the memory is full or the disk space of the hierarchical storage in the disk is full, merging the data files in the memory or the hierarchical storage disk space into the disk space of the next level in the disk, and generating relay data information during the merging and writing process. Since the amount of data occupied by the log file and the relay data information in the backed up data is small, and the data files that need to occupy a large amount of storage space are backed up using hard links corresponding to the data files, and since the storage resources occupied by the hard links are very small, when performing data backup, the local storage resources of the node device can meet the needs of data backup, and the I / O resources occupied when the backup data is written are also relatively small, and the time to complete the writing is also short, so that the real-time backup of the data files can be achieved.

[0008] In some embodiments of the present application, the step of merging and writing data files in the memory or hierarchically stored disk space into the disk space of the next level in the disk includes: merging the data files written in the memory or disk space with the data files in the next level of disk space to generate a new data file; and deleting the old data files corresponding to the merged new data files.

[0009] In some embodiments of the present application, the method also includes: detecting whether the storage engine is started; when the storage engine is started, storing the changed log files and relay data information, and retaining historical snapshot information of the log files and relay data information, wherein the historical snapshot information includes the time and content of changes in the log files and relay data information.

[0010] In some embodiments of the present application, the method also includes: when data rollback is required, searching for the log files and relay data information corresponding to the most recent historical snapshot information by detecting the historical snapshot information of the log files and relay data information; and copying the most recently backed up data to the corresponding data storage location based on the found log files, relay data information, and hard links corresponding to the data files.

[0011] In some embodiments of the present application, the step of copying the most recently backed-up data to a corresponding data storage location based on the found log files, relay data information, and hard links corresponding to the data files includes: finding the data storage location of the data to be restored based on the found relay data information and the hard links corresponding to the data files; obtaining the data to be restored that has not yet been written to the disk in the memory from the found log files, and copying the data to be restored to the data storage location to achieve data rollback.

[0012] According to another aspect of an embodiment of the present application, a data backup method is provided, which is applied to a database storage system based on an LSM storage engine, wherein the database storage system includes multiple node devices, and the method includes: when the database storage system is upgraded, the log files and relay data information corresponding to the data files stored in the node device are backed up in the node device, and the hard links corresponding to the data files are backed up in the node device, wherein the log files include data that have not yet been written to the memory of the node device, and the relay data information includes data metadata and file configuration.

[0013] In some embodiments of the present application, the database storage system includes a master node device and multiple slave node devices, and the steps of backing up the log files and relay data information corresponding to the data files stored in the node device in the node device, and backing up the hard links corresponding to the data files in the node device, include: backing up the log files and relay data information corresponding to the data files stored in each slave node device to the corresponding slave node device, and backing up the hard links corresponding to the data files to the corresponding slave node devices to complete the data backup of the slave node devices; after completing the backup of the slave node devices, switching the master node device to the slave node device, so that the switched slave node device executes the above-mentioned data backup steps to complete the data backup of the master node device.

[0014] In some embodiments of the present application, the method also includes: when the database storage system requires data rollback, searching the slave node device for the most recent backup log file and relay data information; based on the slave node device according to the found log file, relay data information and hard links corresponding to the data files, copying the most recent backup data to the corresponding data storage location in the slave node device to complete the data rollback of the slave node device; switching the master node device to a slave node device, so that the switched slave node device executes the above-mentioned data rollback steps to complete the data rollback on the master node device.

[0015] In some embodiments of the present application, the database storage system includes multiple node device groups consisting of a master node device and at least one slave node device, and the steps of backing up the log files and relay data information corresponding to the data files stored in the node device in the node device, and backing up the hard links corresponding to the data files in the node device, include: backing up the log files and relay data information corresponding to the data files stored in each slave node device in the node device group to the corresponding slave node device, and backing up the hard links corresponding to the data files to the corresponding slave node devices, so as to complete the data backup of each slave node device in the node device group; after completing the data backup of the slave node devices, switching the master node device in the node device group to a slave node device, so that the switched slave node device executes the above-mentioned data backup steps to complete the data backup of the master node device in the node device group.

[0016] In some embodiments of the present application, the method also includes: when the database storage system requires data rollback, the slave node device in the node device group searches for the log file and relay data information of the most recent backup; based on the found log file, relay data information and hard links corresponding to the data files, the slave node device copies the most recent backup data to the corresponding data storage location in the slave node device to complete the data rollback of the slave node devices in the node device group; the master node device in the node device group is switched to a slave node device, so that the switched slave node device in the node device group executes the above-mentioned data rollback steps to complete the rollback of the data on the master node device in the node device group.

[0017] According to another aspect of an embodiment of the present application, a data backup device is provided, which is applied to a node device based on an LSM storage engine, and the device includes: a detection module, which is used to detect whether the database storage system where the node device is located is upgraded, wherein the node device stores data files, log files and relay data information, the log files include data that have not yet been written to the node device memory, and the relay data information includes data metadata and data file configuration; a backup module, which is used to back up the log files and relay data information in the node device when it is detected that the database storage system where the node device is located is upgraded, and to back up the hard links corresponding to the data files in the node device.

[0018] In some embodiments of the present application, the device also includes: a data writing module, which is used to write the data in the data file into the log file, and write the data written in the log file into the memory; a data file merging module, which is used to merge the data files in the memory or the hierarchically stored disk space into the disk space of the next level in the disk when the memory is full or the hierarchically stored disk space in the disk is full, and generate relay data information during the merging and writing process.

[0019] In some embodiments of the present application, the data file merging module is specifically used to: merge the data files written in the memory or disk space with the data files in the next-level disk space to generate new data files; and delete the old data files corresponding to the merged new data files.

[0020] In some embodiments of the present application, the device also includes a storage module; the detection module is also used to detect whether the storage engine is started; the storage module is also used to store the changed log files and relay data information when the storage engine is started, and retain the historical snapshot information of the log files and relay data information, and the historical snapshot information includes the time and content of the changes in the log files and relay data information.

[0021] In some embodiments of the present application, the device also includes: a search module, which is used to search for the log files and relay data information corresponding to the most recent historical snapshot information by detecting the historical snapshot information of the log files and relay data information when data rollback is required; a rollback module, which is used to copy the most recently backed up data to the corresponding data storage location based on the found log files, relay data information and hard links corresponding to the data files.

[0022] In some embodiments of the present application, the rollback module is specifically used to: find the data storage location of the data to be recovered based on the relay data information found and the hard link corresponding to the data file; obtain the data to be recovered that has not yet been written to the disk in the memory from the found log file, and copy the data to be recovered to the data storage location to realize data rollback.

[0023] According to another aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned data backup method are executed.

[0024] Based on any of the above aspects, in an embodiment of the present application, when it is detected that the database storage system where the node device is located is upgraded, the log file and relay data information are backed up locally on the node device, and the hard link corresponding to the data file is backed up locally on the node device. In the above-mentioned backed up data, the amount of data occupied by the log file and relay data information is relatively small (generally several hundred MB), and the data files that need to occupy a large amount of storage space are backed up using the hard link corresponding to the data file. Since the storage resources occupied by the hard link are very small, when performing data backup, the total amount of data required to be backed up will be greatly reduced, and the local storage resources of the node device are sufficient to meet the needs of data backup. At the same time, due to the small amount of backup data, the I / O resources of the node device are also less occupied during the writing process, and the writing rate is faster, so that data backup can be realized in real time.

[0025] In order to make the above-mentioned purposes, features and advantages of the embodiments of the present application more obvious and easy to understand, the embodiments will be described in detail below in conjunction with the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0027] Figure 1 A schematic diagram of a database storage system provided by an embodiment of the present application is shown;

[0028] Figure 2 A schematic diagram of a process of merging data files based on an LSM storage engine is shown;

[0029] Figure 3 The embodiment of the present application provides Figure 1 A schematic diagram of exemplary hardware and software components of a mid-node device;

[0030] Figure 4 A schematic diagram of a process flow of a data backup method provided in an embodiment of the present application is shown;

[0031] Figure 5 A specific data file merging schematic diagram provided in an embodiment of the present application is shown;

[0032] Figure 6 Another schematic diagram of a data backup method according to an embodiment of the present application is shown;

[0033] Figure 7 A functional module diagram of a data backup device provided in an embodiment of the present application is shown;

[0034] Figure 8 Another functional module diagram of the data backup device provided in the embodiment of the present application is shown.

[0035] Icons: 100-node device; 200-network; 101-network port; 102-processor; 103-communication bus; 104-storage medium; 105-I / O interface; 110-data backup device; 1101-detection module; 1102-backup module; 1103-data writing module; 1104-data file merging module; 1105-storage module; 1106-search module; 1107-rollback module. DETAILED DESCRIPTION

[0036] To make the purpose, technical scheme and advantages of the embodiment of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. It should be understood that the drawings in the present application only serve the purpose of explanation and description and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn in real proportion. The flowchart used in this application shows the operations implemented according to some embodiments of the embodiment of the present application. It should be understood that the operations of the flowchart can be implemented out of order, and the steps without logical context can be reversed in order or implemented simultaneously. In addition, those skilled in the art can add one or more other operations to the flowchart under the guidance of the content of the present application, or remove one or more operations from the flowchart.

[0037] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope protected by the present application.

[0038] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.

[0039] In order to solve the technical problems mentioned in the above background technology, the embodiments of the present application provide a data backup method, device, node device and readable storage medium. When it is detected that the database storage system where the node device is located is upgraded, the log file and relay data information are backed up locally on the node device, and the hard link corresponding to the data file is backed up locally on the node device. In the above-mentioned backed up data, the amount of data occupied by the log file and relay data information is relatively small, and the data files that need to occupy a large amount of storage space are backed up using the hard links corresponding to the data files. Since the storage resources occupied by the hard links are very small, when performing data backup, the total amount of data required to be backed up will be greatly reduced. The data can be completely backed up locally on the node device, and will not be limited by the bandwidth during the remote backup process. At the same time, due to the small amount of backup data, the I / O resources of the node device are also less occupied during the writing process, and the writing rate is faster, so that data backup can be realized instantly.

[0040] Figure 1 A schematic diagram of a database storage system provided by an alternative embodiment of the present application. The database storage system includes a plurality of node devices 100 , and different node devices 100 communicate with each other via a network 200 .

[0041] In the embodiment of the present application, the database storage system uses a log-structured merged-tree (LSM) storage engine for data storage. When the node device 100 uses the LSM storage engine to write data, it builds an ordered tree. All data will be written to the log and memory first. Specifically, an ordered small tree is built in the memory of the node device 100. As the data continues to increase, the small tree in the memory will exceed the capacity threshold of the memory. After exceeding the capacity threshold of the memory, a part of the tree in the memory is refreshed to the disk of the node device 100, and the tree on the disk is regularly merged and normalized to form a large tree with larger capacity.

[0042] Please refer to Figure 2 , Figure 2 The schematic diagram of the data file merging process based on the LSM storage engine is shown. For the specific merging order, refer to Figure 2 2a-2d in the figure. The data files stored based on the LSM storage engine are stored hierarchically in the storage space of the node device 100, for example Figure 2 As shown, in the node device 100, data files are hierarchically stored in storage spaces of Level0 to Level3, wherein Level0 may correspond to the memory storage space of the node device 100, and Level1 to Level3 may correspond to the disk storage space of the node device 100. Figure 2 In 2a, the newly written data file will be written to Level 0 first. When the data written to Level 0 exceeds the capacity threshold of Level 0, the LSM storage engine will be triggered to merge the data files. Figure 2 In 2b, the LSM storage engine merges the data files in Level0 with the data files in Level1 to form a new data file. The new data file ( Figure 2 The black oval box in 2c represents the new data file) will be stored in Level1, and the old files in Level0 and Level1 will be deleted. When the data in Level1 exceeds the capacity threshold of Level1, the LSM storage engine will be triggered to merge the data files in Level1 with the data files in Level2. After the merger, a new data file will be formed. The new data file ( Figure 2 The black oval box in 2d represents the new data file) will be stored in Level2, and the old files in Level1 and Level2 will be deleted. Figure 2 2d in.

[0043] In the embodiment of the present application, the node device 100 may include any terminal device with data storage capability (eg, a mobile device, a tablet computer, a laptop computer, etc., or any combination thereof) and a server.

[0044] When the node device 100 is a server, the node device 100 may be a single server or a server group. The server group may be centralized or distributed. In some embodiments of the present application, the node device 100 may also be implemented on a cloud platform; as an example only, the cloud platform may include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an inter-cloud, a multi-cloud, etc., or any combination thereof. In an embodiment of the present application, the node device 100 is preferably a single server or a terminal device.

[0045] The network 200 can be used for the exchange of information and / or data. In some embodiments, one or more components (e.g., node device 100) in the application scenario can send information and / or data to other components. For example, a node device 100 can send data to another node device 100 via the network 200. In some embodiments of the present application, the network 200 can be any type of wired or wireless network, or a combination thereof. As an example only, the network 200 can include a wired network, a wireless network, a fiber optic network, a telecommunication network, an intranet, the Internet, a local area network (LAN), a wide area network (WAN), a wireless local area network (WLAN), a metropolitan area network (MAN), a wide area network (WAN), a public switched telephone network (PSTN), a Bluetooth network, a ZigBee network, or a near field communication (NFC) network, etc., or any combination thereof. In some embodiments of the present application, the network 200 may include one or more network access points. For example, network 200 may include wired or wireless network access points, such as base stations and / or network switching nodes. Figure 1 One or more node devices 100 in the application scenario can be connected to the network 200 through the access point to exchange data and / or information.

[0046] Please refer to Figure 3 , Figure 3 A schematic diagram showing exemplary hardware and software components of a node device 100 that can implement the concepts of the present application according to some embodiments of the present application.

[0047] The node device 100 may be a general-purpose computer or a special-purpose computer. The present application takes the node device 100 as a computer as an example for description.

[0048] In an embodiment of the present application, the node device 100 may include a network port 101 connected to the network 200, one or more processors 102 for executing program instructions, a communication bus 103, and storage media 104 in different forms, such as a disk, ROM, or RAM, or any combination thereof. Exemplarily, the node device 100 may also include program instructions stored in ROM, RAM, or other types of non-temporary storage media, or any combination thereof. The data backup method provided in the present application can be implemented according to these program instructions. The node device 100 may also include an input / output (I / O) interface 105 between a computer and other input / output devices (such as a keyboard, a display screen), and the writing of data files or the backup of data is implemented through the I / O interface 105.

[0049] For ease of description, only one processor 102 is described in the node device 100. However, it should be noted that the node device 100 in the present application may also include multiple processors 102, so the steps performed by one processor 102 described in the present application may also be performed jointly or individually by multiple processors 102. For example, if the processor 102 of the node device 100 performs step A and step B, it should be understood that step A and step B may also be performed jointly by two different processors 102 or individually in one processor 102. For example, the first processor performs step A, the second processor performs step B, or the first processor and the second processor perform steps A and B together.

[0050] Please refer to Figure 4 , Figure 4 A schematic diagram showing a data backup method according to some embodiments of the present application is shown. The data backup method may be performed by Figure 3 It should be understood that in other embodiments, the order of some steps in the data backup method described in the embodiment of the present application can be exchanged according to actual needs, or some steps can be omitted or deleted. The detailed steps of the data backup method are introduced as follows.

[0051] Step S401, detecting whether the database storage system where the node device is located is upgraded.

[0052] In an embodiment of the present application, the node device 100 uses an LSM storage engine for data storage, and the data stored in the node device 100 includes the following information: data files, log files (log files) and relay data information (meta information). Among them, the relay data information is used to save data meta information and data file configuration information, and the relay data information is mainly used to describe the information of the properties (property) of the stored data, and is used to support functions such as indicating storage location, historical data, resource search, and data file records. The log file includes data written to the pre-write log that has not yet been written to the memory of the node device 100 (i.e., data that has not yet been dropped to the disk). The data file is the actual data stored, and generally, the data file is stored in binary form. The storage space occupied by the log file and the relay data information is relatively small (generally a few hundred MB), and the storage space occupied by the data file is larger (generally TB level).

[0053] Step S402, when it is detected that the database storage system where the node device is located is upgraded, the log file and relay data information are backed up in the node device, and the hard link corresponding to the data file is backed up in the node device.

[0054] In an embodiment of the present application, log files and relay data information that occupy less storage resources are directly backed up to the node device. For data files that occupy more storage resources, hard links corresponding to the data files are used for backup. Among them, hard links (Hard Link) are also called symbolic links. Hard links are used to solve the sharing problem of data files in Linux systems. They have the advantages of hiding data file paths, increasing permission security, and saving storage. Data files are stored on file data blocks (Data Block) in node device 100. The file data blocks where the corresponding data files are located can be found by describing the index node number (inode number) in the metadata of the data file. If an index node number corresponds to multiple file names, these file names are called hard links. In other words, a hard link is a file that uses multiple aliases. A hard link can be created by the command link or ln. For example, taking the creation of a hard link for the data file oldfile as an example, the specific creation command can be:

[0055] link oldfile newfile; or

[0056] ln oldfile newfile.

[0057] Since hard links have the same inode number but different file names, hard links have the following characteristics:

[0058] 1) Hard links to the same data file have the same inode number and file data block;

[0059] 2) The system can only create hard links to existing data files;

[0060] 3) Deleting a hard link does not affect other hard links with the same inode number as the hard link.

[0061] In the embodiment of the present application, after a hard link is created for a data file, the hard link will be established to point to the file data block stored in the data file, without the need to copy and store the stored data file separately, so that the problem of large storage resource space required for backing up the data file and insufficient disk storage space of the node device 100 can be avoided. The process of establishing a hard link is simply to set a reference count (file name) for the data file stored in the node device 100, and the storage resources of the node device 100 occupied are quite small. The node device 100 stores data based on the LSM storage engine. When merging data files in the disk space, a new data file will be generated and the old data file will be deleted. In this way, it can be avoided that when the data files stored in the node device 100 are modified, the data backup result will be affected, and the backed-up data will always maintain a historical data.

[0062] In the above scheme, the amount of data occupied by log files and relay data information in the backed up data is relatively small (generally a few hundred MB), while the data files that require a large amount of storage space are backed up using hard links corresponding to the data files. Since hard links occupy very few storage resources, the total amount of data required for backup will be greatly reduced when performing data backup. The local storage resources of the node device can meet the needs of data backup, and there is no need to perform data backup through remote data backup. Since the amount of data to be backed up is small, the I / O resources occupied when writing the backup data are also relatively small, and the time to complete the writing is also short, so that the data files can be backed up instantly.

[0063] The data backup method provided in the embodiment of the present application may further include the following steps.

[0064] First, write the data in the data file into the log file;

[0065] Next, the data written in the log file is written into the memory of the node device 100;

[0066] Finally, when the memory is full or the disk space of the hierarchical storage is full, the data files in the memory or the hierarchical storage disk space are merged and written to the disk space of the next level in the disk, and relay data information is generated during the merge writing process.

[0067] The above data writing process is described in detail below, taking the database storage system LevelDB as an example.

[0068] Under the LevelDB architecture, LSM-tree is divided into three types of files. The first is two memtables in memory, one is the normal memtable that receives write requests, and the other is the immutable memtable that cannot be modified; the other part is the SStable (Sorted String Table) on the disk. The ordered strings in the ordered string table are the keys of the data.

[0069] When writing, first write the data of the data file to be written into the log file; next, write the data in the log file into the memtable. When the memtable is full, switch the memtable to the immutable memtable, and open a new memtable to receive new write requests. The immutable memtable can be flushed to the disk space. Since data files are stored in layers in the disk space of the node device 100, when the disk space of the upper layer is full, the LSM storage engine will be triggered to merge the data files in the upper layer of disk space that are full of data with the data files in the lower layer of disk space. It should be noted that when merging data files, it is not necessary to merge all data files in the upper layer of disk space with all data files in the lower layer of disk space. In the actual merge, the data files in the upper layer of disk space and the data files in the lower layer of disk space can only partially participate in the merge. Please refer to Figure 5 , combined with the following, Figure 5 Let's use a specific example to illustrate.

[0070] When an immutable memtable is flushed to Level0, the LSM storage engine will trigger the merger of data files at Level0 and Level1. Assume that the data files corresponding to the filled boxes are the data files involved in this file merger (Level0 (a = 2, e = 3); Level1 (a = 5, b = 3), (e = 1, f = 6)). After the data files are merged, the data file (a = 2, e = 3) in Level0 is deleted, the data file (a = 5, b = 3) in Level1 is updated to (a = 2, b = 3), and the data file (e = 1, f = 6) is updated to (e = 3, f = 6). The data in Level1 remains globally ordered, and the data order of the three files is always abcdef.

[0071] In the embodiment of the present application, the data backup method provided in the embodiment of the present application may also include the following steps.

[0072] First, check whether the storage engine is started;

[0073] Next, when the storage engine is started, the changed log files and relay data information are stored, and the historical snapshot information of the log files and relay data information is retained. The historical snapshot information includes the time and content of the changes in the log files and relay data information.

[0074] Specifically, in the present application, when data is stored, the LSM storage engine will start and store the data in order. During each data storage process, the log file and relay data information will change. The node device 100 retains these changed log files and relay data information to form historical snapshot information of the log files and relay data information, which is convenient for data rollback after data loss due to human reasons (such as misoperation) or system reasons (such as incompatible data formats) during subsequent system upgrades. The historical snapshot information includes the time and content of changes in the log file and relay data information.

[0075] Please refer to Figure 6 When data rollback is required, the data backup method provided in the embodiment of the present application may further include the following steps.

[0076] Step S601 : searching for the log file and relay data information corresponding to the most recent historical snapshot information by detecting the historical snapshot information of the log file and relay data information.

[0077] The historical snapshot information records the time and content of changes in the log file and relay data information. The most recent change time relative to the request time can be determined based on the request time of the rollback operation, and the log file and relay data information at the time of the most recent change can be obtained based on the determined most recent change time.

[0078] Step S602: based on the found log file, relay data information and hard links corresponding to the data files, the most recently backed up data is copied to the corresponding data storage location.

[0079] Optionally, in the embodiment of the present application, step S602 may be implemented by the following steps:

[0080] First, find the data storage location of the data to be restored based on the found relay data information and the hard link corresponding to the data file;

[0081] Next, the data to be recovered that has not been written to the disk in the memory is obtained from the found log file, and the data to be recovered is copied to the data storage location to implement data rollback.

[0082] Furthermore, the index node number in the relay data information is found through the hard link corresponding to the data file, and the file data block where the corresponding data file is located can be found according to the index node number. At the same time, data rollback can be achieved by copying the data that has not been written to the disk storage space in the most recent backup in the log file to the corresponding file data block.

[0083] The present application also provides a data backup method, which is applied to a database storage system based on an LSM storage engine, and the database storage system includes multiple node devices. The data backup method includes:

[0084] When the database storage system is upgraded, the log files and relay data information corresponding to the data files stored in the node device are backed up in the node device, and the hard links corresponding to the data files are backed up in the node device, wherein the log files include data that have not yet been written into the memory of the node device, and the relay data information includes data metadata and file configuration.

[0085] Relay data information is used to store information such as data metadata and data file configuration. Relay data information is mainly used to describe information about the properties of stored data, and is used to support functions such as indicating storage location, historical data, resource search, and data file recording. The log file includes data written to the pre-write log that has not yet been written to the memory of the node device 100 (i.e., data that has not yet been written to the disk). The data file is the actual data stored, and generally, the data file is stored in binary form. The storage space occupied by log files and relay data information is relatively small (generally a few hundred MB), and the storage space occupied by data files is larger (generally TB level).

[0086] Log files and relay data information that occupy less storage resources are backed up directly to the node device. For data files that occupy more storage resources, hard links corresponding to the data files are used for backup. The amount of data occupied by log files and relay data information in the backed up data is relatively small (generally several hundred MB), while data files that require a large amount of storage space are backed up using hard links corresponding to the data files. Since hard links occupy very few storage resources, the total amount of data required for backup is greatly reduced during data backup. The local storage resources of the node device can meet the needs of data backup. The amount of backup data is small, and the I / O resources occupied when writing the backup data are relatively small. The time to complete the writing is also short, and the real-time backup of data files can be achieved.

[0087] The following describes a solution for performing data backup and data rollback on each node device 100 in the database storage system in combination with different application scenarios.

[0088] The first application scenario is when the data security requirements for the database storage system are relatively high and the node device 100 is not allowed to be unavailable or erroneous. In this scenario, the main method for performing data backup and data rollback for all node devices 100 in the entire database storage system is to perform data backup and data rollback on a single node device 100 as a unit.

[0089] In the database storage system, each node device 100 is divided into a master node device and a slave node device according to whether it can perform read and write operations. In the first application scenario, the way in which each node device 100 in the database storage system performs data backup is to first perform data backup on the slave node device in the database storage system, and then perform data backup on the master node device in the database storage system. The specific process is as follows:

[0090] First, the log files and relay data information corresponding to the data files stored in each slave node device are backed up to the corresponding slave node device, and the hard links corresponding to the data files are backed up to the corresponding slave node device to complete the data backup of the slave node device;

[0091] Next, after completing the data backup of the slave node device, switch the master node device to the slave node device, and back up the log files and relay data information corresponding to the data files stored in the switched slave node device (the original master node device) to the switched slave node device, and back up the hard links corresponding to the data files stored in the switched slave node device to the switched slave node device to complete the data backup of the original master node device.

[0092] In the first application scenario, data is first backed up on the slave node device, and then the master node is switched to the slave node device for data backup. The node device cannot perform read and write operations during data backup to ensure that no data errors occur during the data backup process.

[0093] Furthermore, in the first application scenario, each node device 100 in the database storage system performs data rollback in the following manner: first, data rollback is performed on the slave node device in the database storage system, and then data rollback is performed on the master node device in the database storage system. The specific process is as follows:

[0094] First, when data is lost due to human or system reasons after the database storage system is upgraded and data rollback is required, each slave node device searches for the log file and relay data information most recently backed up by the slave node device.

[0095] Next, based on the log file, relay data information and hard links corresponding to the data files found in the slave node device, the most recently backed up data is copied to the corresponding data storage location in the slave node device to complete the data rollback of the slave node device.

[0096] Specifically, based on the relay data information found and the hard link corresponding to the data file, the data storage location of the data to be recovered is found; the data to be recovered that has not yet been written to the disk in the memory is obtained from the found log file, and the data to be recovered is copied to the data storage location to realize data rollback from the node device.

[0097] Finally, the master node device is switched to a slave node device, so that the switched slave node device (the original master node device) copies the most recently backed up data to the corresponding data storage location in the switched slave node device based on the found log files, relay data information, and hard links corresponding to the data files, to complete the data rollback on the original master node device.

[0098] In the first application scenario, first roll back the data of the slave node device, then switch the master node to the slave node device for data rollback. The node device cannot read or write when backing up data. After completing the data rollback of all node devices, switch the original master node device (switched slave node device) back to the master node device, and the master node device and slave node device will restore the historical data before the upgrade.

[0099] Next, the second application scenario is introduced, which is a scenario of data upgrade with improved tolerance. In this scenario, the main method of performing data backup and data rollback for all node devices 100 in the entire database storage system is to perform data backup and data rollback in units of node device groups.

[0100] The database storage system includes multiple node device groups, each of which includes a master node device and at least one slave node device. In the second application scenario, the database storage system uses node device groups as units to perform data backup. First, data is backed up for the slave node devices in each node device group in the database storage system, and then data is backed up for the master node devices in each node device group in the database storage system. The specific process is as follows:

[0101] First, the log files and relay data information corresponding to the data files stored in each slave node device in the node device group are backed up to the corresponding slave node device, and the hard links corresponding to the data files are backed up to the corresponding slave node device to complete the data backup of each slave node device in the node device group;

[0102] Next, after completing the data backup of the slave node devices in the node device group, switch the master node device in the node device group to a slave node device, and back up the log files and relay data information corresponding to the data files stored in the switched slave node device (the master node device in the original node device group) to the switched slave node device, and back up the hard links corresponding to the data files stored in the switched slave node device to the corresponding slave node device to complete the data backup of the original master node device in the node device group.

[0103] In the second application scenario, data is first backed up for the slave node devices in the node device group, and then the master node device in the node device group is switched to the slave node device for data backup. The slave node device is switched to the master node device to receive online requests. After the master node device is switched to the slave node device, data backup can continue. In this way, data backup of a node device group is completed. The database storage system is divided into multiple node device groups for simultaneous data backup, and the speed and impact of data backup will be relatively small.

[0104] Furthermore, in the second application scenario, each node device 100 in the node device group of the database storage system performs data rollback in the following manner: first, data rollback is performed on the slave node devices in each node device group of the database storage system, and then data rollback is performed on the master node devices in each node device group of the database storage system. The specific process is as follows:

[0105] First, when data is lost due to human or system reasons after the database storage system is upgraded and data rollback is required, the slave node device in each node device group searches for the log file and relay data information most recently backed up by the slave node device.

[0106] Next, based on the log files, relay data information and hard links corresponding to the data files found in the slave node device in the node device group, the most recently backed up data is copied to the corresponding data storage location in the slave node device to complete the data rollback of the slave node device in the node device group.

[0107] Specifically, based on the relay data information found and the hard link corresponding to the data file, the data storage location of the data to be recovered is found; the data to be recovered that has not yet been written to the disk in the memory is obtained from the found log file, and the data to be recovered is copied to the data storage location to realize data rollback from the node device in the node device group.

[0108] Finally, the master node device in the node device group is switched to a slave node device, so that the switched slave node device (the original master node device) copies the most recently backed-up data to the corresponding data storage location in the switched slave node device based on the found log files, relay data information, and hard links corresponding to the data files, to complete the data rollback on the original master node device in the node device group.

[0109] In the second application scenario, data is first rolled back for slave node devices in each node device group, and then the master node in the node device group is switched to a slave node device for data rollback. In the above scenario, the node devices in the database storage system are divided into multiple node device groups, and the node devices in each node device group perform data backup or data rollback at the same time, which can greatly save the time of data backup or data rollback and prevent the operation and maintenance difficulties caused by too long data backup or data rollback time.

[0110] Please refer to Figure 7 , Figure 7 The functional block diagram of the data backup device 110 of some embodiments of the present application is shown. The functions implemented by the data backup device 110 correspond to the steps performed by the above-mentioned data backup method. The device can be understood as the above-mentioned node device 100, or the processor of the node device 100, or can also be understood as a functional component that implements the functions of the present application under the control of the node device 100, independent of the node device 100 or the processor, such as Figure 7 As shown, the data backup device 110 may include a detection module 1101 and a backup module 1102 .

[0111] The detection module 1101 can be used to detect whether the database storage system where the node device 100 is located is upgraded.

[0112] In an embodiment of the present application, the node device 100 uses an LSM storage engine for data storage, and the data stored in the node device 100 includes the following information: data files, log files (log files) and relay data information (meta information). Among them, the relay data information is used to save data meta information and data file configuration information, and the relay data information is mainly used to describe the information of the properties (property) of the stored data, and is used to support functions such as indicating storage location, historical data, resource search, and data file records. The log file includes data written to the pre-write log that has not yet been written to the memory of the node device 100 (i.e., data that has not yet been dropped to the disk). The data file is the actual data stored, and generally, the data file is stored in binary form. The storage space occupied by the log file and the relay data information is relatively small (generally a few hundred MB), and the storage space occupied by the data file is larger (generally TB level).

[0113] The backup module 1102 can be used to back up the log file and relay data information in the node device 100 and back up the hard link corresponding to the data file in the node device 100 when it is detected that the database storage system where the node device 100 is located is upgraded.

[0114] It can be understood that the backup module 1102 can be used to execute the above step S402. The detailed implementation of the backup module 1102 can refer to the above-mentioned content of step S402.

[0115] In the above scheme, the amount of data occupied by log files and relay data information in the backed up data is relatively small (generally a few hundred MB), while the data files that require a large amount of storage space are backed up using hard links corresponding to the data files. Since hard links occupy very few storage resources, the total amount of data required for backup will be greatly reduced during data backup. The local storage resources of the node device can meet the needs of data backup. The amount of backup data is small, the I / O resources occupied when writing the backup data are relatively small, and the time to complete the writing is also short, which can achieve instant backup of data files.

[0116] Please refer to Figure 8 In the embodiment of the present application, the data backup device 110 may further include a data writing module 1103 and a data file merging module 1104 .

[0117] The data writing module 1103 may be used to write the data in the data file into the log file, and write the data written in the log file into the memory.

[0118] The data file merging module 1104 can be used to merge the data files in the memory or the hierarchical storage disk space into the disk space of the next level in the disk when the memory is full or the hierarchical storage disk space in the disk is full, and generate relay data information during the merging and writing process.

[0119] In an embodiment of the present application, the data file merging module 1104 is specifically used to: merge the data file written in the memory or disk space with the data file in the next-level disk space to generate a new data file; and delete the old data file corresponding to the merged new data file.

[0120] Please refer again Figure 8 In the embodiment of the present application, the data backup device 110 may further include a storage module 1105;

[0121] The detection module 1101 is also used to detect whether the storage engine is started;

[0122] The storage module 1105 is also used to store the changed log files and relay data information when the storage engine is started, and retain the historical snapshot information of the log files and relay data information, wherein the historical snapshot information includes the time and content of the changes in the log files and relay data information.

[0123] Specifically, in the present application, when data is stored, the LSM storage engine will start and store the data in order. During each data storage process, the log file and relay data information will change. The node device 100 retains these changed log files and relay data information to form historical snapshot information of the log files and relay data information, which is convenient for data rollback after data loss due to human reasons (such as misoperation) or system reasons (such as incompatible data formats) during subsequent system upgrades. The historical snapshot information includes the time and content of changes in the log file and relay data information.

[0124] Please refer again Figure 8 In the embodiment of the present application, the data backup device 110 may further include: a search module 1106 and a rollback module 1107 .

[0125] The search module 1106 can be used to search for the log file and relay data information corresponding to the most recent historical snapshot information by detecting the historical snapshot information of the log file and relay data information when data rollback is required.

[0126] Specifically, the historical snapshot information records the time and content of changes in the log files and relay data information. The search module 1106 can determine the change time most recent to the request time according to the request time of the rollback operation, and obtain the log files and relay data information at the time of the most recent change based on the determined most recent change time.

[0127] The rollback module 1107 can be used to copy the most recently backed up data to the corresponding data storage location according to the found log files, relay data information and hard links corresponding to the data files.

[0128] Specifically, in an embodiment of the present application, the rollback module 1107 can first find the data storage location of the data to be recovered based on the relay data information found and the hard link corresponding to the data file; then, obtain the data to be recovered that has not yet been written to the disk in the memory from the found log file, and copy the data to be recovered to the data storage location to realize data rollback.

[0129] An embodiment of the present application further provides a readable storage medium, wherein the readable storage medium stores computer executable instructions, and the computer executable instructions can execute the data backup method in any of the above method embodiments.

[0130] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the method embodiment, and will not be repeated in this application. In the several embodiments provided in this application, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.

[0131] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0132] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0133] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard drives, ROM, RAM, magnetic disks, or optical disks.

[0134] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A data backup method, characterized in that: Applied to a node device based on an LSM storage engine, the method comprises: Detecting whether the database storage system where the node device is located is upgraded, wherein the node device stores data files, log files and relay data information, the log files include data that have not been written into the memory of the node device, and the relay data information includes data meta information and data file configuration; When it is detected that the database storage system where the node device is located is upgraded, the log file and relay data information are backed up in the node device, and the hard link corresponding to the data file is backed up in the node device.

2. The method according to claim 1, characterized in that Before detecting whether the database storage system where the node device is located is upgraded, the method further includes: Write the data in the data file into the log file; Then write the data written in the log file into the memory; When the memory is full or the hierarchical storage disk space in the disk is full, the data files in the memory or the hierarchical storage disk space are merged and written into the disk space of the next level in the disk, and relay data information is generated during the merge writing process.

3. The method according to claim 2, characterized in that The step of merging and writing the data files in the memory or the hierarchical storage disk space into the disk space of the next level in the disk comprises: Merging the data file written in the memory or disk space with the data file in the next level of disk space to generate a new data file; The old data file corresponding to the merged new data file is deleted.

4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Check whether the storage engine is started; When the storage engine is started, the changed log files and relay data information are stored, and the historical snapshot information of the log files and relay data information is retained, wherein the historical snapshot information includes the time and content of the changes in the log files and relay data information.

5. The method according to claim 4, characterized in that The method further comprises: When data rollback is required, the log files and relay data information corresponding to the most recent historical snapshot information are found by detecting the historical snapshot information of the log files and relay data information; Based on the found log files, relay data information, and hard links corresponding to the data files, the most recently backed up data is copied to the corresponding data storage location.

6. The method according to claim 5, characterized in that The step of copying the most recently backed up data to the corresponding data storage location according to the found log file, relay data information and hard links corresponding to the data files comprises: Find the data storage location of the data to be restored based on the found relay data information and the hard link corresponding to the data file; The data to be recovered that has not been written to the disk in the memory is obtained from the found log file, and the data to be recovered is copied to the data storage location to realize data rollback.

7. A data backup method, characterized in that: Applied to a database storage system based on an LSM storage engine, the database storage system includes a plurality of node devices, and the method includes: When the database storage system is upgraded, the log files and relay data information corresponding to the data files stored in the node device are backed up in the node device, and the hard links corresponding to the data files are backed up in the node device, wherein the log files include data that have not yet been written to the node device memory, and the relay data information includes data metadata and file configuration.

8. The method according to claim 7, characterized in that The database storage system includes a master node device and multiple slave node devices, and the steps of backing up the log files and relay data information corresponding to the data files stored in the node device in the node device, and backing up the hard links corresponding to the data files in the node device include: Back up the log files and relay data information corresponding to the data files stored in each slave node device to the corresponding slave node device, and back up the hard links corresponding to the data files to the corresponding slave node device to complete the data backup of the slave node device; After completing the backup of the slave node device, the master node device is switched to the slave node device, and the switched slave node device executes the above data backup steps to complete the data backup of the master node device.

9. The method according to claim 8, characterized in that The method further comprises: When the database storage system needs data rollback, the slave node device searches for the most recently backed up log file and relay data information; Based on the found log files, relay data information and hard links corresponding to the data files, the slave node device copies the most recently backed up data to the corresponding data storage location in the slave node device to complete the data rollback of the slave node device; The master node device is switched to a slave node device, and the switched slave node device is made to execute the above data rollback steps to complete the data rollback on the master node device.

10. The method according to claim 7, characterized in that The database storage system includes a plurality of node device groups consisting of a master node device and at least one slave node device, and the steps of backing up the log files and relay data information corresponding to the data files stored in the node device in the node device, and backing up the hard links corresponding to the data files in the node device include: Back up the log files and relay data information corresponding to the data files stored in each slave node device in the node device group to the corresponding slave node device, and back up the hard links corresponding to the data files to the corresponding slave node device to complete the data backup of each slave node device in the node device group; After completing the data backup of the slave node device, the master node device in the node device group is switched to a slave node device, and the switched slave node device executes the above data backup steps to complete the data backup of the master node device in the node device group.

11. The method according to claim 10, characterized in that The method further comprises: When the database storage system needs data rollback, the slave node device in the node device group searches for the most recently backed up log file and relay data information; Based on the found log files, relay data information and hard links corresponding to the data files, the slave node device copies the most recently backed up data to the corresponding data storage location in the slave node device to complete the data rollback of the slave node device in the node device group; The master node device in the node device group is switched to a slave node device, and the switched slave node device in the node device group executes the above data rollback step to complete the rollback of the data on the master node device in the node device group.

12. A data backup device, characterized in that: Applied to a node device based on an LSM storage engine, the device comprises: A detection module, used to detect whether the database storage system where the node device is located is upgraded, wherein the node device stores data files, log files and relay data information, the log files include data that have not been written into the memory of the node device, and the relay data information includes data meta information and data file configuration; The backup module is used to back up the log file and relay data information in the node device and back up the hard link corresponding to the data file in the node device when it is detected that the database storage system where the node device is located is upgraded.

13. A node device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the node device is running, the processor communicates with the storage medium through the bus, and the processor executes the machine-readable instructions to perform the steps of the data backup method as described in any one of claims 1-6.

14. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data backup method according to any one of claims 1 to 6 are executed.