Database recovery method and device
By using LSN and time-related logs in the database to record the LSN at each moment, the problem that the database flashback mechanism cannot support multiple recovery at any point in time is solved, and flexible database recovery is realized, avoiding the discarding of logs after the recovery time, and expanding the The scope of application of flashback.
Patent Information
- Application Number
- CN202310323023.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-29
- Publication Date
- 2024-10-15
AI Technical Summary
The database flashback mechanism has high application limitations, especially in supporting multiple recoveries at any point in time, because it discards the redo logs after the recovery moment, making it impossible to flash back to that point in time again.
By correlating the log sequence number (LSN) with time, the log records the LSN at each moment in the database. After receiving the recovery instruction, the LSN at the specified time is queried to obtain the corresponding recovery data, and the LSN at the current moment is used as the starting point for recovery to ensure recovery. The subsequent LSNs do not conflict, thus supporting multiple recovery at any point in time.
It realizes multiple point-in-time recovery of the database, improves the flexibility of recovery, and avoids discarding redo logs after the recovery moment, thereby expanding the application scope of database flashback.
Smart Images

Figure CN118779147A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a database recovery method and device. Background Art
[0002] Database recovery technology is used to restore a database to its previous state (historical point in time). There are currently two main database recovery mechanisms, one is the database point-in-time recovery (PITR) mechanism, and the other is the database flashback mechanism. When using the database point-in-time recovery mechanism, each time a database is restored, a new database instance must be restored using a full database backup, and then the database incremental backup is applied to the new database instance to restore the database to the specified point in time, which requires a large amount of storage space. The database flashback mechanism is a database recovery mechanism that rolls back the database from the current state to the historical state. There is no need to create a new database instance, but to restore the current database to a historical database. Therefore, compared with the database point-in-time recovery mechanism, the storage space required is smaller.
[0003] Currently, there are two startup modes for database flashback, including read-only mode and read-write mode. If the database flashback is started in read-only mode, the restored database supports reading data but not writing data. If the database flashback is started in read-write mode, the restored database supports both reading and writing data, but the backup data after the historical time point of the flashback will be discarded, resulting in the loss of some historical data. Therefore, the current application of the database flashback mechanism is relatively limited. Summary of the invention
[0004] The present application provides a database recovery method and device, which can solve the problem that the current database flashback mechanism has high application limitations.
[0005] In a first aspect, a database recovery method is provided. The method includes: in response to receiving a first recovery instruction for a database at a first moment, a computer device queries a first LSN corresponding to the first recovery moment from a log sequence number (LSN) and time association log according to the first recovery moment indicated by the first recovery instruction. The LSN and time association log is used to record the LSNs corresponding to multiple moments in the database. The first recovery moment is located before the first moment in time sequence. The computer device obtains the first recovery data of the database according to the first LSN. The computer device uses the first recovery data to perform data recovery on the database to obtain a database corresponding to the first recovery moment. The starting LSN used for the database corresponding to the first recovery moment is greater than the LSN corresponding to the first moment.
[0006] In the present application, the current database is rolled back to a certain historical moment according to the recovery instruction for the current database. The LSN corresponding to the historical moment is no longer used as the starting point, but the LSN corresponding to the current moment is used as the starting point. An LSN greater than the LSN corresponding to the current moment is further used to identify the redo log generated by the database rolled back to after the historical moment. The LSN jump mechanism is used to ensure that the LSN used after the database is restored does not conflict with the LSN used before the database is restored. In this way, there is no need to discard the redo log after the recovery moment after the database is restored, so that the database supports multiple recovery (flashback) at any time point, thereby improving the flexibility of database recovery.
[0007] Optionally, the starting LSN used for the database corresponding to the first recovery moment is the next LSN of the LSN corresponding to the first moment.
[0008] Optionally, after the computer device uses the first recovery data to recover the database and obtains the database corresponding to the first recovery moment, in response to receiving an operation instruction for the database corresponding to the first recovery moment, the computer device executes the operation instruction and generates a redo log corresponding to the operation instruction, and the LSN of the redo log is greater than the LSN corresponding to the first moment.
[0009] Optionally, a computer device obtains the first recovery data of the database according to the first LSN, including: the computer device obtains the first full backup snapshot from the full backup of the database according to the first LSN, the LSN of the first full backup snapshot is less than the first LSN; the computer device obtains the first redo log set from the incremental backup of the database according to the LSN of the first full backup snapshot and the first LSN, the first redo log set includes redo logs whose LSN is between the LSN of the first full backup snapshot and the first LSN. Correspondingly, the computer device uses the first recovery data to recover the database and obtain the implementation process of the database corresponding to the first recovery moment, including: the computer device updates the database to the first database recovered by using the first full backup snapshot; the computer device uses the redo logs in the first redo log set to perform forward recovery processing on the first database in order from small to large LSNs to obtain the database corresponding to the first recovery moment.
[0010] In this implementation, the computer device can use a database restored from a full backup snapshot whose LSN is smaller than the first LSN corresponding to the first recovery time to replace the original database, and then use the redo log to forward restore the restored database to the database corresponding to the first recovery time to achieve database recovery at a historical time point.
[0011] Optionally, another implementation method for a computer device to obtain the first recovery data of a database according to the first LSN includes: the computer device obtains a second full backup snapshot from the full backup of the database according to the first LSN, and the LSN of the second full backup snapshot is greater than the first LSN; the computer device obtains a second redo log set from the incremental backup of the database according to the first LSN and the LSN of the second full backup snapshot, and the second redo log set includes redo logs whose LSNs are between the first LSN and the LSN of the second full backup snapshot. Correspondingly, the computer device uses the first recovery data to perform data recovery on the database to obtain the implementation process of the database corresponding to the first recovery moment, including: the computer device updates the database to the second database obtained by recovering the second full backup snapshot; the computer device uses the redo logs in the second redo log set to perform reverse recovery processing on the second database in descending order of LSN to obtain the database corresponding to the first recovery moment.
[0012] In this implementation, the computer device can use a database restored from a full backup snapshot whose LSN is greater than the first LSN corresponding to the first recovery time to replace the original database, and then use the redo log to reversely restore the restored database to the database corresponding to the first recovery time to achieve database recovery at a historical time point.
[0013] Optionally, another implementation method of the computer device acquiring the first recovery data of the database according to the first LSN includes: the computer device acquires a third full backup snapshot from the full backup of the database according to the first LSN, and the LSN of the third full backup snapshot is equal to the first LSN. Accordingly, the computer device uses the first recovery data to recover the database to obtain the implementation process of the database corresponding to the first recovery time, including: the computer device updates the database to a third database obtained by recovering the third full backup snapshot, and uses the third database as the database corresponding to the first recovery time.
[0014] In this implementation, when there is a full backup snapshot corresponding to the first recovery time in the full backup of the database, the database corresponding to the first recovery time can be directly restored based on the full backup snapshot, and the database recovery efficiency is high.
[0015] Optionally, the first recovery instruction is a first recovery instruction for the database. Another implementation method for the computer device to obtain the first recovery data of the database according to the first LSN includes: the computer device obtains a third redo log set from the incremental backup of the database according to the first LSN and the LSN corresponding to the first moment, and the third redo log set includes redo logs whose LSNs are between the first LSN and the LSN corresponding to the first moment. Correspondingly, the computer device uses the first recovery data to recover the database to obtain the implementation method of the database corresponding to the first recovery moment, including: the computer device uses the redo logs in the third redo log set to perform reverse recovery processing on the database in order from large to small LSNs to obtain the database corresponding to the first recovery moment.
[0016] In this implementation, there is no need to use a full backup of the database. The database can be reversely restored to the database corresponding to the first recovery time using only the redo log. Therefore, there is no need to perform a full backup of the database, which can save storage resources.
[0017] Optionally, the first recovery instruction is the nth recovery instruction for the database, n≥2. Another implementation method for the computer device to obtain the first recovery data of the database according to the first LSN includes: the computer device obtains a fourth redo log set from the incremental backup of the database according to the first LSN and the LSN corresponding to the first moment, and the fourth redo log set includes redo logs whose LSN is between the starting LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment and redo logs whose LSN is between the LSN corresponding to the last recovery moment and the first LSN. Correspondingly, the computer device uses the first recovery data to recover the database to obtain the implementation process of the database corresponding to the first recovery moment, including: the computer device uses the redo logs between the starting LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment in order from large to small LSNs to perform reverse recovery processing on the database in sequence to obtain the database corresponding to the last recovery moment; the computer device uses the redo logs whose LSN is between the LSN corresponding to the last recovery moment and the first LSN to recover the database corresponding to the last recovery moment to obtain the database corresponding to the first recovery moment.
[0018] In this implementation, the computer device does not need to use a full backup of the database. It can restore the database to any historical time point multiple times by using the redo log, without the need to perform a full backup of the database, which can save storage resources.
[0019] Optionally, after the computer device uses the first recovery data to perform data recovery on the database and obtains the database corresponding to the first recovery time, the computer device, in response to receiving a second recovery instruction for the database at the second time, queries the second LSN corresponding to the second recovery time from the LSN and time association log according to the second recovery time indicated by the second recovery instruction, and the second recovery time is located before the second time in terms of time sequence. The computer device obtains the second recovery data of the database according to the second LSN. The computer device uses the second recovery data to perform data recovery on the database and obtains the database corresponding to the second recovery time, and then the starting LSN used for the database corresponding to the second recovery time is greater than the LSN corresponding to the second time.
[0020] Optionally, the second recovery time is located after the first recovery time in time sequence, and the second recovery time is located before the first time sequence. In other words, the present application supports the database to be recovered to any time point after the last recovery time.
[0021] Optionally, the computer device may also add database recovery timeline information corresponding to the first recovery moment in the timeline log, the database recovery timeline information including a recovery LSN, a start LSN and an end LSN, wherein the recovery LSN is the first LSN, the start LSN is the starting LSN used for the database corresponding to the first recovery moment, and the end LSN is the LSN corresponding to the end moment of the next recovery instruction.
[0022] In this application, the timeline information in the timeline log can be used for data filtering. For example, when executing a database task, the data and / or redo log of one timeline can be loaded into the memory for operation at a time to avoid confusing database tasks of different timelines.
[0023] In a second aspect, a database recovery device is provided. The device includes multiple functional modules, and the multiple functional modules interact with each other to implement the method in the first aspect and its respective embodiments. The multiple functional modules can be implemented based on software, hardware, or a combination of software and hardware, and the multiple functional modules can be arbitrarily combined or divided based on specific implementations.
[0024] In a third aspect, a database recovery device is provided, including a memory and a processor, wherein the memory stores program instructions, and the processor runs the program instructions to execute the method in the first aspect and its various embodiments.
[0025] In a fourth aspect, a computer-readable storage medium is provided, comprising program instructions, which, when executed on a computer device, causes the computer device to execute the method in the above-mentioned first aspect and its various embodiments.
[0026] In a fifth aspect, a computer program product is provided. When the computer program product runs on a computer, the computer executes the method in the above-mentioned first aspect and its various embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 is a schematic diagram of a timeline of database flashback provided by an embodiment of the present application;
[0028] Figure 2 This is a schematic diagram of an application scenario provided by an embodiment of the present application;
[0029] Figure 3 It is a schematic diagram of an implementation flow of a database recovery method provided in an embodiment of the present application;
[0030] Figure 4 It is a structural schematic diagram of a database recovery device provided in an embodiment of the present application;
[0031] Figure 5 It is a schematic diagram of the architecture of a database recovery device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0033] In order to facilitate the reader's understanding of the present application, some terms involved in the embodiments of the present application are first explained.
[0034] 1. Transaction: A transaction in a database refers to a series of operations performed as a single logical unit of work, which is either executed completely or not executed at all. Transaction processing ensures that data-oriented resources are not permanently updated unless all operations within the transactional unit are completed successfully. By combining a set of related operations into a unit that either succeeds or fails, error recovery can be simplified and applications can be made more reliable. For a logical unit of work to become a transaction, it must meet the so-called atomicity, consistency, isolation, and durability (ACID for short). Simply put, once a transaction is committed, data cannot be lost.
[0035] 2. Redo log: Redo log is an important mechanism to ensure transaction durability. At present, database storage engines usually manage storage space in units of pages. Any add, delete, modify, and query operation in the database will eventually operate a complete page, load the entire page on the disk into the buffer pool in the memory, and then modify the records that need to be modified in the buffer pool. The page (that is, block) of the database is the unit that stores physical records on the disk. The data page in the memory that is inconsistent with the disk is called a dirty page. The process of writing dirty pages in the memory to the disk is called the dirty flushing process. In order to improve performance, relational databases generally write transaction data to the redo log and the buffer pool before committing it, rather than writing it to the page file on the disk. In addition, the dirty flushing process in the database is asynchronous, that is, after the record that needs to be modified is modified in the buffer pool, it will not be refreshed to the disk immediately. Since the data in the buffer pool will be lost when the database crashes, the redo log is introduced to ensure transaction durability. The redo log is used to record the operation content in the buffer pool. Every time an operation is completed in the buffer pool, a redo log is generated. The log content records which page, how many offsets, and what data has been changed. In this way, if the database crashes when there are dirty pages in the memory that have not been written to the disk, the lost dirty page data in the buffer pool can be restored through the redo log. The redo log can be stored directly on the disk as a group of files. Since the data structure of the redo log file is simpler than that of the page file, it can ensure a higher disk write efficiency. In addition, the redo log is written to the disk sequentially.
[0036] 3. Log Sequence Number (LSN): LSN is an increasing integer that indicates the total amount of bytes written to the redo log by a transaction. Since LSN is always increasing, it can be used as a unique identifier to indicate transactions written at different times. LSN is mainly used to recover data when a database crashes. LSN not only exists in the redo log, but also in the header of each data page. The LSN in the header of the data page is used to record the LSN value of the last modification of the current page, and is used to compare the LSN value of the redo log during data recovery to determine whether to recover the data for the page. In addition, checkpoints also have LSNs. In other words, data pages, redo logs, and checkpoints all have LSNs. The LSN value can connect the process of a transaction from start to recovery.
[0037] 4. Full database backup: Full backup is to back up all the data in the database. A complete database can be restored using the database full backup file. Each full backup is associated with an LSN, which is used to identify the backup data of the full backup.
[0038] 5. Database incremental backup: Incremental backup refers to the backup of incremental data from the last full database backup to the next full database backup. The incremental data in the database is usually recorded in redo logs.
[0039] Database recovery technology is used to restore a database to its previous state (historical time point). There are two main database recovery mechanisms. One is the database point-in-time recovery mechanism, which uses database full backup and database incremental backup. The execution process of database point-in-time recovery is as follows: the user specifies the historical time point to be restored to the database; finds a database full backup that is less than the historical time point from the database full backup set; uses the database full backup to restore a new database instance; obtains redo logs from the database incremental backup, and applies the redo logs to the new database instance until the historical time point specified by the user is restored. The database point-in-time recovery mechanism usually adopts the forward recovery method, but each recovery requires a complete copy of the database full backup to create a new database instance, which has a high demand for storage resources. The other is the database flashback mechanism. The database flashback mechanism is a database recovery mechanism that rolls back the database from the current state to the historical state. Compared with the database point-in-time recovery mechanism, the database flashback mechanism does not need to create a new database instance, requires less storage resources, and is generally more efficient in database recovery.
[0040] Currently, databases that provide database flashback functions usually use a reverse recovery method. If you want to flash back from time point A to time point B, the database can execute a database recovery (recover database) command, apply the incremental data from time point A to time point B, and reversely restore the data in the database from time point A to time point B. There are two startup modes for database flashback. One startup mode is read-only mode, and the recovered database supports reading data at time point B but cannot modify the data. The other startup mode is read-write mode, and the recovered database supports reading and writing data, but will discard backup data after time point B. Accordingly, the database can no longer flash back to any time point between time point B and time point A. Therefore, the current application limitations of the database flashback mechanism are relatively high.
[0041] For example, a common database flashback architecture includes a Recover Writer (RVWR) process, a Log Writer (LGWR) process, flashback database logs, redo logs, and a flash recovery area. Once the database flashback function is enabled, the RVWR process and the LGWR process will start. The RVWR process is responsible for writing flashback database logs to the flash recovery area. The flashback database logs include the before-images of data blocks. The LGWR process is responsible for writing redo logs. The redo logs include the before-images and after-images of data blocks. Among them, the before-image of a data block refers to the content of the data block before it is changed, and the after-image of a data block refers to the content of the data block after it is changed.
[0042] For example, assume that the default value of column C1 in table T in the database is null, and Structured Query Language (SQL) commands are executed on column C1 in table T at multiple time points. Then, the flashback database logs and redo logs as shown in Table 1 can be obtained.
[0043] Table 1
[0044] Time SQL statement for column C1 of table T Flashback Database Log Redo Log 09:00:00 Update T set C1 = 1; The value before the change is null The value before the change is null, and the value after the change is 1 09:10:00 Update T set C1 = 2; Value before change 1 The value before the change is 1, the value after the change is 2 09:15:00 Update T set C1 = 3; Value before change 2 The value before the change is 2, and the value after the change is 3 09:20:00 Update T set C1 = 4; Value before change 3 The value before the change is 3, and the value after the change is 4
[0045] When starting database flashback, records in the flashback database logs are retrieved sequentially from the tail to the head and applied to the database. Referring to Table 1, for example, if the current time is 09:20:00 and the value of column C1 in table T is 4, when it is necessary to flash back to 09:10:00 when the value of column C1 in table T is 2, starting from applying the logs from the tail, first retrieve the value C1 = 3 to overwrite C1 = 4, and then continue to retrieve the value C1 = 2 to overwrite C1 = 3. At this time, it is found that the condition is already met, so the application of the flashback database logs is stopped.
[0046] Currently, if database flashback is performed in read-write mode, historical data after the recovery time point will be discarded, resulting in the fact that database flashback does not support flashback to multiple arbitrary time points. For example Figure 1 shows the timeline of database flashback, where the arrow indicates the time sequence direction, that is, T1 < T2 < T3 < T4 < T5. As Figure 1As shown, after flashing back to time point T2 in read-write mode at time point T4, the redo logs between time point T2 and time point T4 will be discarded, so it is impossible to flash back to time point T3 between time point T2 and time point T4 at time point T5. The reason for this shortcoming is that the LSN of the redo log is sequentially increasing by default and cannot be repeated. The LSN of the redo log generated at time point T is recorded as LSN(T). When the database flashes back from time point T4 to time point T2, the LSN of the redo log generated from time point T4 starts from LSN(T2)+1, which conflicts with the LSN of the redo log originally generated between time point T2 and time point T4. Therefore, the redo log after time point T2 needs to be discarded after the flashback. In other words, the LSN of the redo log generated after the database is flashed back in read-write mode conflicts with the LSN of the redo log generated after the flashback time point, which is the fundamental reason why the database flashback cannot be flashed back to any time point multiple times.
[0047] Based on this, the present application provides a technical solution, which can realize flashback of the database at any time point multiple times, that is, the database recovery method provided by the embodiment of the present application can be used to realize database flashback. The LSN corresponding to each moment in the database is recorded through the LSN and time association log. When a recovery instruction for the current database is received, the LSN corresponding to the recovery moment can be queried from the LSN and time association log according to the recovery moment indicated by the recovery instruction, and then the corresponding recovery data can be obtained according to the LSN corresponding to the recovery moment. The recovery data may include a full database backup and / or an incremental database backup, and the recovery data is further used to perform data recovery on the current database to obtain the database corresponding to the recovery moment. After that, the starting LSN used for the database corresponding to the recovery moment is greater than the LSN corresponding to the current moment. That is to say, in the present application, the current database is rolled back to a certain historical moment according to the recovery instruction for the current database. The LSN corresponding to the historical moment is no longer used as the starting point, but the LSN corresponding to the current moment is used as the starting point. An LSN greater than the LSN corresponding to the current moment is further used to identify the redo log generated by the database rolled back to after the historical moment. The LSN jump mechanism is used to ensure that the LSN used after the database is recovered does not conflict with the LSN used before the database is recovered. In this way, there is no need to discard the redo log after the recovery moment after the database is recovered, so that the database supports multiple recovery at any time point, thereby improving the flexibility of database recovery.
[0048] The technical solution of this application is described in detail below from multiple angles such as application scenarios, method flow, virtual devices, hardware devices, etc.
[0049] The following is an illustration of the application scenarios involved in the embodiments of the present application.
[0050] The database recovery method provided in the embodiment of the present application can be applied to a stand-alone database or a distributed database. For example, Figure 2 This is a schematic diagram of an application scenario provided by an embodiment of the present application. Figure 2 As shown, the application scenario includes a terminal 201, a database system 202, and a data recovery device 203. The terminal 201 is connected to the database system 202 in communication. The database system 202 is connected to the data recovery device 203 in communication. Figure 2 The database system shown is a stand-alone database deployment form.
[0051] The user can access the database system 202 through the terminal 201. The database system 202 includes a computing system and a storage system. The storage system is used to store data, and the computing system is used to call the storage system to complete the execution of the database task. The storage system includes a controller and a storage medium, wherein the storage medium is used to store data, for example, see Figure 2 , the storage medium is used to store data including but not limited to data files and redo log files. The controller is used to read data from the storage medium or write data to the storage medium to cooperate with the computing system to complete the execution of database tasks. The computing system calls the storage system, which can be understood as the computing system performing a series of operations on the storage system, including but not limited to read operations, write operations, rename operations, create operations or delete operations. The read operation is used to read data from the storage system. The write operation is used to write data to the storage system in an overwrite manner. The rename operation is used to rename data or files in the storage system. The create operation is used to create a new file or storage volume in the storage system to write new data. The delete operation is used to delete the original data in the storage system. For example, see Figure 2 The computing system includes an SQL query engine and a storage engine. The terminal 201 can write data through the SQL query engine, and the storage engine can write the data to the data files and redo log files in the storage medium through the controller in the storage system. Database recovery in the embodiment of the present application refers to the recovery of data files in the storage medium.
[0052] The data recovery device 203 is responsible for restoring the database. The data recovery device 203 and the database system 202 can be deployed on two independent devices, or can be integrated and deployed on the same device. Figure 2 The data recovery device 203 may include multiple functional modules, including but not limited to a full backup module, an incremental backup module, a state maintenance module, and a recovery execution module. The functional modules in the data recovery device 203 may be added or deleted according to actual needs. For example, the data recovery device 203 may not include a full backup module. The embodiment of the present application does not limit the number and type of functional modules included in the data recovery device 203. Please continue to refer to Figure 2 , the data recovery device 203 also maintains archived redo log files and metadata files. The archived redo log files are used to store the backup of the redo log files in the database system 202, that is, the archived redo log files are used to store the incremental backup of the database. The metadata files are used to store the backup of the data files in the database system 202, that is, the metadata files are used to store the full backup of the database. The archived redo files and metadata files are used as the recovery data for the data recovery device to recover the database.
[0053] The full backup module is responsible for the full backup of data files. It can adopt the file system snapshot backup method to improve the efficiency of full backup and recovery, so that the backup or recovery of snapshots can be completed in seconds. Each full backup snapshot is associated with an LSN, which can uniquely identify the corresponding full backup snapshot. The full backup module can store the full backup log in the metadata file, and the log structure is "full backup snapshot, LSN". The full backup module is used to create a full backup snapshot of the data files in the database system 202, and generate a full backup log and write it into the metadata file.
[0054] The incremental backup module is responsible for backing up the redo log files. The incremental backup module is used to continuously back up the redo log files in the database system 202 and store them in archived redo log files in the data recovery device 203.
[0055] The state maintenance module is responsible for maintaining the recovery state of the database. The state maintenance module can be used to obtain the current LSN and the current time from the database system 202 every second, and write the LSN and time association log in the metadata file, and the log structure is "time, LSN". The state maintenance module can also be used to call the full backup module regularly (such as every 10 minutes) to create a full backup snapshot of the data files in the database system 202. The state maintenance module can also be used to regularly clean up unnecessary backup data in the metadata file and the archived redo log file, such as the full backup snapshot and redo log that are not within the recovery window. The recovery window refers to the earliest recoverable time, which can be set and modified by the user. One implementation method of the state maintenance module cleaning up the backup data is: first determine the earliest recoverable time, then query the LSN corresponding to the earliest time in the LSN and time association log, then delete the redo log whose LSN in the archived redo log file is less than the LSN corresponding to the earliest time, and find the full backup snapshot whose associated LSN is less than the LSN corresponding to the earliest time from the full backup log, retain only one of the snapshots, and delete the redundant snapshots.
[0056] The recovery execution module is responsible for the execution of database recovery. The recovery execution module is used to query the LSN corresponding to the recovery moment from the LSN and time association log according to the specified recovery moment, and then obtain the corresponding recovery data from the metadata file and / or archived redo log file according to the LSN corresponding to the recovery moment, and use the recovery data to perform database recovery. The recovery execution module can also store the timeline log in the metadata file, and the log structure is "number, recovery LSN, start LSN, end LSN". Each time the recovery execution module executes a database recovery, the corresponding database recovery timeline information can be added to the timeline log. Among them, the recovery LSN is the LSN corresponding to the recovery moment, the start LSN is the start LSN used from the recovery moment, and the end LSN is the LSN corresponding to the trigger moment of the next database recovery. For example, the LSN of the redo log generated at time point T is recorded as LSN(T). Table 2 shows a timeline log.
[0057] Table 2
[0058] serial number Recover LSN Starting LSN End LSN Timeline 1 none 0 LSN(T4) Timeline 2 LSN(T2) LSN(T4)+1 LSN(T5) Timeline 3 LSN(T3) LSN(T5)+1 / (unknown)
[0059] Referring to Table 2, the first timeline is created when the database is started for the first time, and is numbered as Timeline 1. The starting LSN of Timeline 1 is 0. After receiving the recovery instruction to restore to time point T2 at time point T4, LSN (T4) is used as the ending LSN of Timeline 1, and the second timeline is created, numbered as Timeline 2. The recovery LSN of Timeline 2 is LSN (T2), and the starting LSN is LSN (T4) + 1. After receiving the recovery instruction to restore to time point T3 at time point T6, LSN (T5) is used as the ending LSN of Timeline 2, and the third timeline is created, numbered as Timeline 3. The recovery LSN of Timeline 3 is LSN (T3), and the starting LSN is LSN (T5) + 1. The timelines in Table 2 are as follows: Figure 1 The timeline shown. In this way, the LSN of the redo log generated by the database will not conflict on the entire timeline, and can support the recovery of the database at any time point multiple times. The specific function implementation of the recovery execution module can be referred to as follows Figure 3 An embodiment of the method is shown.
[0060] The following is an example of the method flow of the embodiment of the present application.
[0061] For example, Figure 3 is a schematic diagram of the implementation flow of a database recovery method provided in an embodiment of the present application. The method can be applied to a computer device, which can be Figure 2 The data recovery device 203 in the application scenario shown or the recovery execution module in the data recovery device 203. Figure 3As shown, the method includes but is not limited to the following steps 301 to 303, and for example may also include the following steps 304 to 306.
[0062] Step 301: In response to receiving a first recovery instruction for a database at a first moment, the computer device queries a first LSN corresponding to the first recovery moment from an LSN and time association log according to the first recovery moment indicated by the first recovery instruction.
[0063] Among them, the first recovery moment is located before the first moment in time sequence, that is, the first recovery instruction is used to trigger the database to recover from the current state to the historical state. The LSN and time association log is used to record the LSNs corresponding to multiple moments in the database. For example, the current LSN and the current time are obtained from the database every second, and the current LSN and the current time are associated and stored in the LSN and time association log. The current time here refers to the natural time. In the embodiment of the present application, the LSN in the database is monotonically increasing in natural time sequence, that is, the LSN used in the database increases with time, such as the LSN of the redo log generated at the current moment is 1, and the LSN of the redo log generated at the next moment is 2. The correspondence between the moment and the LSN stored in the LSN and time association log can be one moment corresponding to one LSN, or when the database does not use a new LSN for multiple consecutive moments, that is, the LSN remains unchanged, it can also be one time period corresponding to one LSN. For example, Table 3 shows a log associated with LSN.
[0064] Table 3
[0065]
[0066]
[0067] As shown in Table 3, the LSN corresponding to time 08:00:00 is 0. The LSN corresponding to time 08:00:01 is 1. The LSN corresponding to the time period 08:00:02-08:00:05, that is, the LSNs corresponding to time 08:00:02, 08:00:03, 08:00:04, and 08:00:05 are all 2, indicating that no new LSNs are used in the database at the three time points of 08:00:03, 08:00:04, and 08:00:05, reflecting that the data in the database has not changed. The LSN corresponding to time 08:00:06 is 3.
[0068] Step 302: The computer device obtains first recovery data from the database according to the first LSN.
[0069] Optionally, the first recovery data includes full data and / or incremental data. In the embodiment of the present application, there are multiple implementations of the computer device performing database recovery. In combination with different implementations of database recovery, there are also multiple implementations of the computer device obtaining the first recovery data of the database according to the first LSN. For details, refer to the following four implementations.
[0070] In a first implementation, a computer device obtains a first full backup snapshot from a full backup of a database according to a first LSN, and the LSN of the first full backup snapshot is less than the first LSN. The computer device obtains a first redo log set from an incremental backup of the database according to the LSN of the first full backup snapshot and the first LSN. The first redo log set includes redo logs whose LSNs are between the LSN of the first full backup snapshot and the first LSN. In other words, the redo logs in the first redo log set satisfy: the LSN of the redo log is greater than the LSN of the first full backup snapshot, and is less than or equal to the first LSN.
[0071] Since the LSN used by the database in the embodiment of the present application is monotonically increasing in natural time series, the first redo log set obtained by the computer device is the incremental data of the database at the first recovery moment compared to the first full backup snapshot.
[0072] Optionally, the first full backup snapshot is a full backup snapshot whose LSN is less than the first LSN and closest to the first LSN in the full backup of the database. In this way, the incremental data of the acquired database at the first recovery time compared to the first full backup snapshot can be reduced as much as possible to improve the database recovery efficiency.
[0073] In a second implementation, the computer device obtains a second full backup snapshot from the full backup of the database according to the first LSN, and the LSN of the second full backup snapshot is greater than the first LSN. The computer device obtains a second redo log set from the incremental backup of the database according to the first LSN and the LSN of the second full backup snapshot. The second redo log set includes redo logs whose LSNs are between the first LSN and the LSN of the second full backup snapshot. In other words, the redo logs in the second redo log set satisfy: the LSN of the redo log is greater than the first LSN, and less than or equal to the LSN of the second full backup snapshot.
[0074] Since the LSN used by the database in the embodiment of the present application is monotonically increasing in natural time series, the second redo log set obtained by the computer device, that is, the second full backup snapshot, is the incremental data of the database at the first recovery moment.
[0075] Optionally, the second full backup snapshot is a full backup snapshot in the full backup of the database whose LSN is greater than the first LSN and closest to the first LSN. In this way, the incremental data of the acquired second full backup snapshot compared to the database at the first recovery time can be reduced as much as possible, so as to improve the efficiency of database recovery.
[0076] In a third implementation manner, the computer device obtains a third full backup snapshot from the full backup of the database according to the first LSN, and the LSN of the third full backup snapshot is equal to the first LSN.
[0077] In a first possible case of the fourth implementation, the first recovery instruction is a first recovery instruction for the database. Then the computer device obtains a third redo log set from the incremental backup of the database according to the first LSN and the LSN corresponding to the first moment. The third redo log set includes redo logs whose LSNs are between the first LSN and the LSN corresponding to the first moment. In other words, the redo logs in the first redo log set satisfy: the LSN of the redo log is greater than the first LSN, and less than or equal to the LSN corresponding to the first moment.
[0078] Since the LSN used by the database in the embodiment of the present application is monotonically increasing in natural time series, the redo log of the third redo log set obtained by the computer device is the incremental data of the database at the first moment compared to the first recovery moment.
[0079] In the second possible situation of the fourth implementation, the first recovery instruction is the nth recovery instruction for the database, and n≥2. Then the computer device obtains the fourth redo log set from the incremental backup of the database according to the first LSN and the LSN corresponding to the first moment. The fourth redo log set includes redo logs whose LSN is between the starting LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment, and redo logs whose LSN is between the LSN corresponding to the last recovery moment and the first LSN. Among them, the LSN of the redo log is between the starting LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment, that is, the LSN of the redo log is greater than the starting LSN used by the database corresponding to the last recovery moment, and is less than or equal to the LSN corresponding to the first moment.
[0080] Since the LSN used by the database in the embodiment of the present application is monotonically increasing in natural time series, the redo log whose LSN in the fourth redo log set obtained by the computer device is between the starting LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment, that is, the incremental data of the database at the first moment compared to the last recovery moment.
[0081] In the second possible case, if the first recovery time is after the last recovery time in terms of time sequence, then the fourth redo log set includes redo logs whose LSN is between the LSN corresponding to the last recovery time and the first LSN, i.e., the LSN of the redo log is greater than the LSN corresponding to the last recovery time and is less than or equal to the first LSN. If the first recovery time is before the last recovery time in terms of time sequence, then the fourth redo log set includes redo logs whose LSN is between the LSN corresponding to the last recovery time and the first LSN, i.e., the LSN of the redo log is greater than the first LSN and is less than or equal to the LSN corresponding to the last recovery time.
[0082] Step 303: The computer device uses the first recovery data to recover the database to obtain a database corresponding to the first recovery moment. Then, the starting LSN used for the database corresponding to the first recovery moment is greater than the LSN corresponding to the first moment.
[0083] The starting LSN used for the database corresponding to the first recovery moment is the LSN that starts to be used after the database is restored to the historical state corresponding to the first recovery moment. For example, if the LSN corresponding to the first moment is 10 and the LSN corresponding to the first recovery moment is 5, then the LSN that starts to be used after the database is restored to the historical state corresponding to the first recovery moment is greater than 10. In other words, after the computer device restores the database to the historical state corresponding to the first recovery moment, in response to receiving an operation instruction for the database corresponding to the first recovery moment, the computer device executes the operation instruction and generates a redo log corresponding to the operation instruction, and the LSN of the redo log is greater than the LSN corresponding to the first moment.
[0084] Optionally, the starting LSN used for the database corresponding to the first recovery moment is the next LSN of the LSN corresponding to the first moment. For example, if the LSN corresponding to the first moment is 10, the LSN used after the database is restored to the historical state corresponding to the first recovery moment is 11.
[0085] Before the computer device uses the first recovery data to recover the database, it first closes the database.
[0086] In combination with the first implementation in step 302, the implementation process of step 303 includes: the computer device updates the database to the first database restored by using the first full backup snapshot. The computer device performs forward recovery processing on the first database in order of LSN from small to large using the redo logs in the first redo log set to obtain the database corresponding to the first recovery time.
[0087] For example, referring to the example in Table 2, after the computer device receives a recovery instruction to restore to time point T2 at time point T4, assuming that a full backup snapshot with LSN LSN(T1) is obtained from the full backup, the computer device can use the full backup snapshot to restore the database, and then apply the redo logs from LSN(T1) to LSN(T2) in sequence to the restored database, so as to forward restore the database from time point T1 to time point T2. Further, after the computer device receives a recovery instruction to restore to time point T3 at time point T5, assuming that a full backup snapshot with LSN LSN(T2) is obtained from the full backup, the computer device can use the full backup snapshot to restore the database, and then apply the redo logs from LSN(T2) to LSN(T3) in sequence to the restored database, so as to forward restore the database from time point T2 to time point T3.
[0088] In this implementation, the computer device can use a database restored from a full backup snapshot whose LSN is smaller than the first LSN corresponding to the first recovery time to replace the original database, and then use the redo log to forward restore the restored database to the database corresponding to the first recovery time to achieve database recovery at a historical time point.
[0089] In combination with the second implementation in step 302, the implementation process of step 303 includes: the computer device updates the database to the second database restored by using the second full backup snapshot. The computer device uses the redo logs in the second redo log set to perform reverse recovery processing on the second database in descending order of LSN to obtain the database corresponding to the first recovery time.
[0090] For example, referring to the example in Table 2, after the computer device receives a recovery instruction to restore to time point T2 at time point T4, assuming that a full backup snapshot with LSN LSN(T3) is obtained from the full backup, the computer device can use the full backup snapshot to restore the database, and then use the redo logs from LSN(T3) to LSN(T2) to play back the restored database in sequence, so as to reversely restore the database from time point T3 to time point T2. Further, after the computer device receives a recovery instruction to restore to time point T3 at time point T5, assuming that a full backup snapshot with LSN LSN(T4) is obtained from the full backup, the computer device can use the full backup snapshot to restore the database, and then use the redo logs from LSN(T4) to LSN(T3) to play back the restored database in sequence, so as to reversely restore the database from time point T4 to time point T3.
[0091] In this implementation, the computer device can use a database restored from a full backup snapshot whose LSN is greater than the first LSN corresponding to the first recovery time to replace the original database, and then use the redo log to reversely restore the restored database to the database corresponding to the first recovery time to achieve database recovery at a historical time point.
[0092] In combination with the third implementation method in step 302, the implementation process of step 303 includes: the computer device updates the database to a third database restored by using the third full backup snapshot, and uses the third database as the database corresponding to the first recovery time.
[0093] In this implementation, when there is a full backup snapshot corresponding to the first recovery time in the full backup of the database, the database corresponding to the first recovery time can be directly restored based on the full backup snapshot, and the database recovery efficiency is high.
[0094] In combination with the first possible situation of the fourth implementation method in step 302, the implementation process of step 303 includes: the computer device uses the redo logs in the third redo log set to perform reverse recovery processing on the database in order of LSN from large to small, and obtains the database corresponding to the first recovery time.
[0095] For example, referring to the example in Table 2, after the computer device receives the recovery instruction to restore to time point T2 at time point T4, it uses the redo logs from LSN (T4) to LSN (T2) to replay the database at time point T4 in sequence to reversely restore the database from time point T4 to time point T2.
[0096] In this implementation, there is no need to use a full backup of the database. The database can be reversely restored to the database corresponding to the first recovery time using only the redo log. Therefore, there is no need to perform a full backup of the database, which can save storage resources.
[0097] In combination with the second possible situation of the fourth implementation manner in step 302, the implementation process of step 303 includes: the computer device uses the redo logs between the starting LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment to perform reverse recovery processing on the database in descending order of LSN, and obtains the database corresponding to the last recovery moment. The computer device uses the redo logs between the LSN corresponding to the last recovery moment and the first LSN to perform recovery processing on the database corresponding to the last recovery moment, and obtains the database corresponding to the first recovery moment.
[0098] If the first recovery moment is after the last recovery moment in terms of time sequence, the computer device uses the redo logs between the LSN corresponding to the last recovery moment and the first LSN to perform recovery processing on the database corresponding to the last recovery moment in the implementation method that the computer device uses the redo logs between the LSN corresponding to the last recovery moment and the first LSN in the order of LSN from small to large to perform forward recovery processing on the database corresponding to the last recovery moment in sequence. For example, referring to the example in Table 2, after the computer device receives the recovery instruction to restore to the time point T3 at the time point T5, the computer device first uses the redo logs from LSN (T5) to LSN (T4) + 1 to play back the database at the time point T5 in sequence to obtain the database at the time point T2, and then applies the redo logs from LSN (T2) to LSN (T3) in sequence to the database at the time point T2, so as to forwardly restore the database from the time point T2 to the time point T3.
[0099] If the first recovery moment is before the last recovery moment in terms of time sequence, the computer device may use the redo logs between the LSN corresponding to the last recovery moment and the first LSN to perform recovery processing on the database corresponding to the last recovery moment in the order of LSN from large to small, and use the redo logs between the LSN corresponding to the last recovery moment and the first LSN to perform reverse recovery processing on the database corresponding to the last recovery moment in sequence. For example, referring to the example in Table 2, after the computer device receives the recovery instruction to restore to the time point T1 at the time point T5, the computer device first uses the redo logs from LSN (T5) to LSN (T4) + 1 to play back the database at the time point T5 in sequence to obtain the database at the time point T2, and then uses the redo logs from LSN (T2) to LSN (T1) to play back the database at the time point T2 in sequence to obtain the database at the time point T1.
[0100] In this implementation, the computer device does not need to use a full backup of the database. It can restore the database to any historical time point multiple times by using the redo log, without the need to perform a full backup of the database, which can save storage resources.
[0101] Optionally, after the computer device receives the first recovery instruction for the database at the first moment, it can also add the database recovery timeline information corresponding to the first recovery moment in the timeline log. The database recovery timeline information includes a recovery LSN, a start LSN, and an end LSN. Among them, the recovery LSN in the database recovery timeline information corresponding to the first recovery moment is the first LSN, the start LSN is the starting LSN used for the database corresponding to the first recovery moment, and the end LSN is the LSN corresponding to the end moment of the next recovery instruction. If the computer device receives the recovery instruction for the database again at the second moment, the end LSN in the database recovery timeline information corresponding to the first recovery moment is the LSN corresponding to the second moment. Referring to the example in Table 2, if the first moment is time point T4 and the first recovery moment is time point T2, the database recovery timeline information corresponding to the first recovery moment may be the timeline information numbered as timeline 2 in Table 2. If the first moment is time point T5 and the first recovery moment is time point T3, the database recovery timeline information corresponding to the first recovery moment may be the timeline information numbered as timeline 3 in Table 2.
[0102] In the embodiment of the present application, the timeline information in the timeline log can be used for data filtering. For example, when executing a database task, the data and / or redo log of one timeline can be loaded into the memory for operation each time to avoid confusing database tasks of different timelines.
[0103] Optionally, after executing the above steps 301 to 303, the computer device may further continue to execute the following steps 304 to 306.
[0104] Step 304: In response to receiving a second recovery instruction for the database at a second time, the computer device queries the LSN and time association log for a second LSN corresponding to the second recovery time according to the second recovery time indicated by the second recovery instruction.
[0105] The second restoration moment is before the second moment in terms of time sequence, that is, the second restoration instruction is used to trigger the database to be restored from the current state to the historical state. The second restoration instruction is the next restoration instruction of the first restoration instruction.
[0106] Optionally, the second recovery time is located after the first recovery time in time sequence, and the second recovery time is located before the first time sequence. The embodiment of the present application supports the database to be recovered to any time point after the last recovery time.
[0107] Step 305: The computer device obtains second recovery data from the database according to the second LSN.
[0108] Step 306: The computer device uses the second recovery data to recover the database to obtain a database corresponding to the second recovery time. Then, the starting LSN used for the database corresponding to the second recovery time is greater than the LSN corresponding to the second time.
[0109] The implementation process of the above steps 304 to 306 can refer to the implementation process of the above steps 301 to 303, and the embodiments of the present application will not be repeated here.
[0110] In the database recovery method provided in the embodiment of the present application, the LSN corresponding to each moment in the database is recorded through the LSN and time association log. When the computer device receives the recovery instruction for the current database, it can query the LSN corresponding to the recovery moment from the LSN and time association log according to the recovery moment indicated by the recovery instruction, and then obtain the corresponding recovery data according to the LSN corresponding to the recovery moment. The recovery data may include a full database backup and / or an incremental database backup, and the recovery data is further used to perform data recovery on the current database to obtain the database corresponding to the recovery moment. Afterwards, the starting LSN used for the database corresponding to the recovery moment is greater than the LSN corresponding to the current moment. That is to say, in the embodiment of the present application, the computer device rolls back the current database to a certain historical moment according to the recovery instruction for the current database, and no longer takes the LSN corresponding to the historical moment as the starting point, but takes the LSN corresponding to the current moment as the starting point, and further adopts an LSN greater than the LSN corresponding to the current moment to identify the redo log generated by the database rolled back to after the historical moment, and through the LSN jump mechanism, ensures that the LSN used after the database recovery does not conflict with the LSN used before the database recovery, so that after the database is recovered, there is no need to discard the redo log after the recovery moment, so that the database supports multiple recovery at any time point, thereby improving the flexibility of database recovery.
[0111] It should be noted that the sequence of the steps of the database recovery method provided in the embodiment of the present application can be adjusted appropriately, and the steps can be increased or decreased accordingly according to the situation. Any technician familiar with the technical field can easily think of a change within the technical scope disclosed in this application, and all of them should be included in the protection scope of this application.
[0112] The following is an example of a virtual device in an embodiment of the present application.
[0113] For example, Figure 4 Schematic diagram of a database recovery device provided in an embodiment of the present application. Figure 4 As shown, the database recovery device 400 includes but is not limited to a query module 401, an acquisition module 402 and a data recovery module 403. Figure 4The database recovery device 400 also includes one or more of an instruction execution module 404, a generation module 405 or an information adding module 406.
[0114] The query module 401 is used for, in response to receiving a first recovery instruction for the database at a first moment, querying the first LSN corresponding to the first recovery moment from the log sequence number LSN and time association log according to the first recovery moment indicated by the first recovery instruction, the LSN and time association log is used to record the LSNs corresponding to multiple moments in the database, and the first recovery moment is located before the first moment in time sequence. Here, the query module 401 is specifically used to execute the above step 301.
[0115] The acquisition module 402 is used to acquire the first restored data of the database according to the first LSN. Here, the acquisition module 402 is specifically used to execute the above step 302.
[0116] The data recovery module 403 is used to recover the database using the first recovery data to obtain the database corresponding to the first recovery time, and then the starting LSN used for the database corresponding to the first recovery time is greater than the LSN corresponding to the first time. Here, the data recovery module 403 is specifically used to perform the above step 303.
[0117] Optionally, the starting LSN used for the database corresponding to the first recovery moment is the next LSN of the LSN corresponding to the first moment.
[0118] Optionally, the instruction execution module 404 is used to perform data recovery on the database using the first recovery data to obtain the database corresponding to the first recovery moment, and then, in response to receiving the operation instruction for the database corresponding to the first recovery moment, execute the operation instruction. The generation module 405 is used to generate a redo log corresponding to the operation instruction, and the LSN of the redo log is greater than the LSN corresponding to the first moment.
[0119] Optionally. The acquisition module 402 is specifically used to acquire a first full backup snapshot from the full backup of the database according to the first LSN, the LSN of the first full backup snapshot is less than the first LSN; according to the LSN of the first full backup snapshot and the first LSN, acquire a first redo log set from the incremental backup of the database, the first redo log set includes redo logs whose LSNs are between the LSN of the first full backup snapshot and the first LSN. The data recovery module 403 is specifically used to update the database to the first database recovered by using the first full backup snapshot; in order of LSN from small to large, use the redo logs in the first redo log set to perform forward recovery processing on the first database in sequence to obtain the database corresponding to the first recovery moment.
[0120] Alternatively, the acquisition module 402 is specifically used to obtain a second full backup snapshot from the full backup of the database according to the first LSN, the LSN of the second full backup snapshot is greater than the first LSN; according to the first LSN and the LSN of the second full backup snapshot, obtain a second redo log set from the incremental backup of the database, the second redo log set includes redo logs whose LSNs are between the first LSN and the LSN of the second full backup snapshot. The data recovery module 403 is specifically used to update the database to a second database recovered by using the second full backup snapshot; in descending order of LSN, use the redo logs in the second redo log set to perform reverse recovery processing on the second database in turn to obtain the database corresponding to the first recovery moment.
[0121] Alternatively, the acquisition module 402 is specifically used to obtain a third full backup snapshot from the full backup of the database according to the first LSN, and the LSN of the third full backup snapshot is equal to the first LSN. The data recovery module 403 is specifically used to update the database to a third database recovered by using the third full backup snapshot, and use the third database as the database corresponding to the first recovery time.
[0122] Alternatively, the first recovery instruction is the first recovery instruction for the database. The acquisition module 402 is specifically used to acquire a third redo log set from the incremental backup of the database according to the first LSN and the LSN corresponding to the first moment, and the third redo log set includes redo logs whose LSNs are between the first LSN and the LSN corresponding to the first moment. The data recovery module 403 is specifically used to perform reverse recovery processing on the database in sequence according to the order of LSN from large to small using the redo logs in the third redo log set to obtain the database corresponding to the first recovery moment.
[0123] Alternatively, the first recovery instruction is the nth recovery instruction for the database, n≥2. The acquisition module 402 is specifically used to obtain a fourth redo log set from the incremental backup of the database according to the first LSN and the LSN corresponding to the first moment, the fourth redo log set including the redo logs between the starting LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment, and the redo logs between the LSN corresponding to the last recovery moment and the first LSN. The data recovery module 403 is specifically used to perform reverse recovery processing on the database in descending order of LSN, using the redo logs between the starting LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment, to obtain the database corresponding to the last recovery moment; and perform recovery processing on the database corresponding to the last recovery moment using the redo logs between the LSN corresponding to the last recovery moment and the first LSN, to obtain the database corresponding to the first recovery moment.
[0124] Optionally, the query module 401 is also used to recover the database using the first recovery data and obtain the database corresponding to the first recovery moment, and in response to receiving a second recovery instruction for the database at a second moment, query the second LSN corresponding to the second recovery moment from the LSN and time association log according to the second recovery moment indicated by the second recovery instruction, and the second recovery moment is located before the second moment in time sequence. The acquisition module 402 is also used to obtain the second recovery data of the database according to the second LSN. The data recovery module 403 is also used to recover the database using the second recovery data and obtain the database corresponding to the second recovery moment, and then the starting LSN used for the database corresponding to the second recovery moment is greater than the LSN corresponding to the second moment. Here, the query module 401 is specifically used to execute the above step 304. The acquisition module 402 is specifically used to execute the above step 305. The data recovery module 403 is specifically used to execute the above step 306.
[0125] Optionally, the second restoration moment is located after the first restoration moment in time sequence, and the second restoration moment is located before the first moment in time sequence.
[0126] Optionally, the information adding module 406 is used to add database recovery timeline information corresponding to the first recovery moment in the timeline log, and the database recovery timeline information includes a recovery LSN, a start LSN and an end LSN, wherein the recovery LSN is the first LSN, the start LSN is the starting LSN used for the database corresponding to the first recovery moment, and the end LSN is the LSN corresponding to the end moment of the next recovery instruction.
[0127] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0128] The following is an illustration of the hardware device of the embodiment of the present application.
[0129] An embodiment of the present application provides a database recovery device, which may be a computer device. Figure 5 A possible architecture diagram of a database recovery device is provided as an example. Figure 5 As shown, the database recovery device 500 may include a processor 501, a memory 502, a communication interface 503 and a bus 504. In the database recovery device, the number of the processor 501 may be one or more. Figure 5Only one of the processors 501 is shown. Optionally, the processor 501 may be a central processing unit (CPU). If the database recovery device has multiple processors 501, the types of the multiple processors 501 may be different or the same. Optionally, the multiple processors of the database recovery device may also be integrated into a multi-core processor.
[0130] The memory 502 is used to store computer instructions and data. The memory 502 can store computer instructions and data required to implement the database recovery method provided in the present application. The memory 502 can be any one or any combination of the following storage media: non-volatile memory (such as read-only memory (ROM), solid state disk (SSD), hard disk drive (HDD, etc.), optical disk, volatile memory.
[0131] The communication interface 503 may be any one or any combination of the following devices: a network interface (such as an Ethernet interface), a wireless network card, or other devices with a network access function.
[0132] The communication interface 503 is used for the database recovery device 500 to perform data communication with other devices or components.
[0133] Figure 5 A bus 504 is also exemplarily drawn. The bus 504 can connect the processor 501 with the memory 502 and the communication interface 503. Thus, through the bus 504, the processor 501 can access the memory 502, and can also use the communication interface 503 to exchange data with other devices or components.
[0134] In the present application, the database recovery device 500 executes the computer instructions in the memory 502 to implement the database recovery method provided by the present application. For example, in response to receiving the first recovery instruction for the database at the first moment, according to the first recovery moment indicated by the first recovery instruction, the first LSN corresponding to the first recovery moment is queried from the LSN and time association log. The LSN and time association log is used to record the LSNs corresponding to multiple moments in the database. The first recovery moment is located before the first moment in time sequence; the first recovery data of the database is obtained according to the first LSN; the database is restored using the first recovery data to obtain the database corresponding to the first recovery moment, and then the starting LSN used for the database corresponding to the first recovery moment is greater than the LSN corresponding to the first moment. In addition, the implementation process of the steps of the database recovery method provided by the present application by the database recovery device 500 executing the computer instructions in the memory 502 can refer to the corresponding description in the above method embodiment.
[0135] The embodiment of the present application also provides a computer-readable storage medium, which is a non-volatile computer-readable storage medium. The computer-readable storage medium includes program instructions. When the program instructions are executed on a computer device, the computer device executes the database recovery method provided in the embodiment of the present application.
[0136] The embodiment of the present application also provides a computer program product including instructions. When the computer program product is run on a computer, the computer executes the database recovery method provided by the embodiment of the present application.
[0137] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0138] In the embodiments of the present application, the terms “first”, “second” and “third” are used for descriptive purposes only and should not be understood as indicating or implying relative importance.
[0139] The term "and / or" in this application is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0140] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0141] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the concept and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A database recovery method, characterized in that: The method comprises: In response to receiving a first recovery instruction for a database at a first moment, according to the first recovery moment indicated by the first recovery instruction, querying a first LSN corresponding to the first recovery moment from a log sequence number LSN and a time association log, the LSN and time association log being used to record LSNs corresponding to a plurality of moments in the database, respectively, the first recovery moment being before the first moment in terms of time sequence; Acquire first recovery data of the database according to the first LSN; The database is restored using the first recovery data to obtain a database corresponding to the first recovery moment, and then a starting LSN used for the database corresponding to the first recovery moment is greater than the LSN corresponding to the first moment.
2. The method according to claim 1, characterized in that The starting LSN used by the database corresponding to the first recovery moment is the next LSN of the LSN corresponding to the first moment.
3. The method according to claim 1 or 2, characterized in that: After recovering the database using the first recovery data to obtain the database corresponding to the first recovery time, the method further includes: In response to receiving an operation instruction for the database corresponding to the first recovery moment, the operation instruction is executed, and a redo log corresponding to the operation instruction is generated, where the LSN of the redo log is greater than the LSN corresponding to the first moment.
4. The method according to any one of claims 1 to 3, characterized in that: The acquiring the first restored data of the database according to the first LSN includes: Acquire a first full backup snapshot from the full backup of the database according to the first LSN, where the LSN of the first full backup snapshot is smaller than the first LSN; According to the LSN of the first full backup snapshot and the first LSN, obtaining a first redo log set from the incremental backup of the database, the first redo log set including redo logs whose LSNs are between the LSN of the first full backup snapshot and the first LSN; The using the first recovery data to perform data recovery on the database to obtain the database corresponding to the first recovery time includes: Updating the database to a first database restored by using the first full backup snapshot; In the order of LSN from small to large, the first database is forward recovered in sequence using the redo logs in the first redo log set to obtain the database corresponding to the first recovery time.
5. The method according to any one of claims 1 to 3, characterized in that: The acquiring the first restored data of the database according to the first LSN includes: Acquire a second full backup snapshot from the full backup of the database according to the first LSN, where the LSN of the second full backup snapshot is greater than the first LSN; According to the first LSN and the LSN of the second full backup snapshot, obtaining a second redo log set from the incremental backup of the database, wherein the second redo log set includes redo logs whose LSNs are between the first LSN and the LSN of the second full backup snapshot; The using the first recovery data to perform data recovery on the database to obtain the database corresponding to the first recovery time includes: Updating the database to a second database restored by using the second full backup snapshot; In descending order of LSN, reverse recovery processing is performed on the second database in sequence using the redo logs in the second redo log set to obtain the database corresponding to the first recovery time.
6. The method according to any one of claims 1 to 3, characterized in that: The acquiring the first restored data of the database according to the first LSN includes: Obtaining a third full backup snapshot from the full backup of the database according to the first LSN, where the LSN of the third full backup snapshot is equal to the first LSN; The using the first recovery data to perform data recovery on the database to obtain the database corresponding to the first recovery time includes: The database is updated to a third database restored by using the third full backup snapshot, and the third database is used as the database corresponding to the first restoration time.
7. The method according to any one of claims 1 to 3, characterized in that: The first recovery instruction is a first recovery instruction for the database, and the acquiring first recovery data of the database according to the first LSN includes: According to the first LSN and the LSN corresponding to the first moment, a third redo log set is obtained from the incremental backup of the database, wherein the third redo log set includes redo logs whose LSNs are between the first LSN and the LSN corresponding to the first moment; The using the first recovery data to perform data recovery on the database to obtain the database corresponding to the first recovery time includes: In descending order of LSN, the database is sequentially reversely recovered using the redo logs in the third redo log set to obtain the database corresponding to the first recovery time.
8. The method according to any one of claims 1 to 3, characterized in that: The first recovery instruction is an nth recovery instruction for the database, where n≥2, and the acquiring first recovery data of the database according to the first LSN includes: According to the first LSN and the LSN corresponding to the first moment, a fourth redo log set is obtained from the incremental backup of the database, the fourth redo log set including redo logs whose LSNs are between the start LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment and redo logs whose LSNs are between the LSN corresponding to the last recovery moment and the first LSN; The using the first recovery data to perform data recovery on the database to obtain the database corresponding to the first recovery time includes: In descending order of LSN, the database is reversely recovered in sequence using redo logs whose LSNs are between the starting LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment, to obtain the database corresponding to the last recovery moment; The database corresponding to the last recovery moment is recovered by using a redo log whose LSN is between the LSN corresponding to the last recovery moment and the first LSN, so as to obtain the database corresponding to the first recovery moment.
9. The method according to any one of claims 1 to 8, characterized in that: After recovering the database using the first recovery data to obtain the database corresponding to the first recovery time, the method further includes: In response to receiving a second recovery instruction for the database at a second moment, querying a second LSN corresponding to the second recovery moment from the LSN-time association log according to the second recovery moment indicated by the second recovery instruction, the second recovery moment being before the second moment in terms of time sequence; Acquire second recovery data of the database according to the second LSN; The database is restored using the second recovery data to obtain a database corresponding to the second recovery time, and then a starting LSN used for the database corresponding to the second recovery time is greater than the LSN corresponding to the second time.
10. The method according to claim 9, characterized in that The second restoration time is located after the first restoration time in terms of time sequence, and the second restoration time is located before the first time sequence in terms of time sequence.
11. The method according to any one of claims 1 to 10, characterized in that: The method further comprises: Add database recovery timeline information corresponding to the first recovery moment in the timeline log, wherein the database recovery timeline information includes a recovery LSN, a start LSN, and an end LSN, wherein the recovery LSN is the first LSN, the start LSN is the starting LSN used for the database corresponding to the first recovery moment, and the end LSN is the LSN corresponding to the end time of the next recovery instruction.
12. A database recovery device, characterized in that: The device comprises: a query module, configured to, in response to receiving a first recovery instruction for a database at a first moment, query a first LSN corresponding to the first recovery moment from a log sequence number LSN and time association log according to a first recovery moment indicated by the first recovery instruction, wherein the LSN and time association log is used to record LSNs corresponding to a plurality of moments in the database, respectively, and the first recovery moment is located before the first moment in terms of time sequence; An acquisition module, configured to acquire first restored data of the database according to the first LSN; A data recovery module is used to recover the database using the first recovery data to obtain the database corresponding to the first recovery moment, and then the starting LSN used for the database corresponding to the first recovery moment is greater than the LSN corresponding to the first moment.
13. The device according to claim 12, characterized in that The starting LSN used by the database corresponding to the first recovery moment is the next LSN of the LSN corresponding to the first moment.
14. The device according to claim 12 or 13, characterized in that The device also includes: an instruction execution module, configured to, after recovering the database using the first recovery data to obtain the database corresponding to the first recovery moment, execute the operation instruction in response to receiving the operation instruction for the database corresponding to the first recovery moment; A generation module is used to generate a redo log corresponding to the operation instruction, where the LSN of the redo log is greater than the LSN corresponding to the first moment.
15. The device according to any one of claims 12 to 14, characterized in that: The acquisition module is configured to acquire a first full backup snapshot from the full backup of the database according to the first LSN, the LSN of the first full backup snapshot being smaller than the first LSN; and acquire a first redo log set from the incremental backup of the database according to the LSN of the first full backup snapshot and the first LSN, the first redo log set including redo logs whose LSNs are between the LSN of the first full backup snapshot and the first LSN; The data recovery module is used to update the database to the first database restored by using the first full backup snapshot; and perform forward recovery processing on the first database in sequence using the redo logs in the first redo log set in the order of LSN from small to large, to obtain the database corresponding to the first recovery time.
16. The device according to any one of claims 12 to 14, characterized in that The acquisition module is configured to acquire a second full backup snapshot from the full backup of the database according to the first LSN, wherein the LSN of the second full backup snapshot is greater than the first LSN; According to the first LSN and the LSN of the second full backup snapshot, obtaining a second redo log set from the incremental backup of the database, wherein the second redo log set includes redo logs whose LSNs are between the first LSN and the LSN of the second full backup snapshot; The data recovery module is used to update the database to a second database restored by using the second full backup snapshot; and to perform reverse recovery processing on the second database in descending order of LSN using the redo logs in the second redo log set to obtain the database corresponding to the first recovery time.
17. The device according to any one of claims 12 to 14, characterized in that The acquisition module is configured to acquire a third full backup snapshot from the full backup of the database according to the first LSN, wherein the LSN of the third full backup snapshot is equal to the first LSN; The data recovery module is used to update the database to a third database restored by using the third full backup snapshot, and use the third database as the database corresponding to the first recovery moment.
18. The device according to any one of claims 12 to 14, characterized in that: The first recovery instruction is the first recovery instruction for the database. The acquisition module is used to acquire a third redo log set from the incremental backup of the database according to the first LSN and the LSN corresponding to the first moment, wherein the third redo log set includes redo logs whose LSNs are between the first LSN and the LSN corresponding to the first moment; The data recovery module is used to perform reverse recovery processing on the database in sequence according to the order of LSN from large to small using the redo logs in the third redo log set to obtain the database corresponding to the first recovery time.
19. The device according to any one of claims 12 to 14, characterized in that The first recovery instruction is the nth recovery instruction for the database, where n≥2. The acquisition module is used to acquire a fourth redo log set from the incremental backup of the database according to the first LSN and the LSN corresponding to the first moment, wherein the fourth redo log set includes redo logs whose LSN is between the start LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment and redo logs whose LSN is between the LSN corresponding to the last recovery moment and the first LSN; The data recovery module is used to perform reverse recovery processing on the database in descending order of LSN, using redo logs between the starting LSN used by the database corresponding to the last recovery moment and the LSN corresponding to the first moment, to obtain the database corresponding to the last recovery moment; and to perform recovery processing on the database corresponding to the last recovery moment using redo logs between the LSN corresponding to the last recovery moment and the first LSN, to obtain the database corresponding to the first recovery moment.
20. The device according to any one of claims 12 to 19, characterized in that The query module is further configured to, after recovering the database using the first recovery data to obtain the database corresponding to the first recovery time, in response to receiving a second recovery instruction for the database at a second time, query the LSN and time association log for a second LSN corresponding to the second recovery time according to the second recovery time indicated by the second recovery instruction, wherein the second recovery time is before the second time in terms of time sequence; The acquisition module is further used to acquire the second restored data of the database according to the second LSN; The data recovery module is further used to use the second recovery data to recover the database to obtain the database corresponding to the second recovery moment, and then the starting LSN used for the database corresponding to the second recovery moment is greater than the LSN corresponding to the second moment.
21. The device according to claim 20, characterized in that The second restoration time is located after the first restoration time in terms of time sequence, and the second restoration time is located before the first time sequence in terms of time sequence.
22. The device according to any one of claims 12 to 21, characterized in that The device also includes: An information adding module is used to add the database recovery timeline information corresponding to the first recovery moment in the timeline log, the database recovery timeline information includes a recovery LSN, a start LSN and an end LSN, wherein the recovery LSN is the first LSN, the start LSN is the starting LSN used for the database corresponding to the first recovery moment, and the end LSN is the LSN corresponding to the end moment of the next recovery instruction.
23. A database recovery device, characterized in that: The method comprises a memory and a processor, wherein the memory stores program instructions, and the processor runs the program instructions to execute the method according to any one of claims 1 to 11.
24. A computer-readable storage medium, characterized in that: The method comprises program instructions, and when the program instructions are executed on a computer device, the computer device is caused to execute the method according to any one of claims 1 to 11.
25. A computer program product, characterized in that When the computer program product is executed on a computer, the computer is enabled to execute the method according to any one of claims 1 to 11.
Citation Information
Cited By
Database recovery method and apparatus
EP4685650A1
Database recovery method and apparatus
WO2024198878A1
Data recovery method, and system and device
WO2026208821A1
