Database recovery method and device, electronic equipment and storage medium
By obtaining target files and some log files, quickly recovering the database to the target moment, solving the problem of low database version recovery efficiency in the existing technology, and achieving efficient database version recovery.
Patent Information
- Application Number
- CN202411247216.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-05
- Publication Date
- 2024-12-17
AI Technical Summary
The existing database version recovery method is inefficient and requires playing back a large number of log files one by one, resulting in low database recovery efficiency.
By receiving the version recovery instructions of the target database, you can obtain the target file and some log files based on the target moment, so as to quickly restore the version of the database to the target moment, and play back only a small piece of log files.
Improves the efficiency of database version recovery, reduces the number of log files playback, and improves recovery speed.
Smart Images

Figure CN119149519A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a database recovery method, device, electronic device and storage medium. Background Art
[0002] With the development of information technology, most companies usually store data through databases. With the continuous increase in data volume and changes in business needs, database versions need to be restored in many cases. Therefore, how to better realize the recovery of database versions is a problem that needs to be solved at present. In the solutions of the prior art, when performing version recovery, if the target restored version is not backed up, it is often necessary to first obtain the log files that modified the database within a certain period of time, and then restore the database to the backed-up version, and then replay these log files to the restored version to achieve the purpose of restoring to the target recovery version. However, in actual operation, the process of replaying each log file often requires replaying one by one, which is low in overall efficiency, and thus leads to low efficiency of database recovery. Summary of the invention
[0003] The purpose of this application is to solve at least one of the above technical defects. The technical solutions provided by the embodiments of this application are as follows: In a first aspect, an embodiment of the present application provides a database recovery method, characterized by comprising: Receiving a version recovery instruction for a target database, wherein the version recovery instruction includes a target time to be recovered; At least one second target file is obtained from a plurality of first target files stored in a preset database based on a target time; wherein each first target file is generated based on at least two first log files for a target database, the first target file includes a time zone, and the time zone is determined based on the generation time of each first log file that generates the first target file; and the end time of the time zone of each second target file is before the target time; If the target time is different from the end time of the time zone of each stored first target file, then obtaining at least one second log file from the preset database based on the target time and each end time; At least one second target file is input into the target database, and each second log file is replayed to restore the target database to a version corresponding to the target time.
[0004] In an optional embodiment of the present application, based on the target time and each termination time, obtaining at least one second log file from a preset database specifically includes: Determine a third target file from each second target file; the end time of the third target file is before the target time and is closest to the target time; At least one second log file whose generation time is between the end time of the time zone of the third target file and the target time is obtained.
[0005] In an optional embodiment of the present application, the first target file is generated in the following manner: Scan the target database to obtain at least two first log files for the target database; The first log files are integrated to generate a first target file, and the first target file is stored in a preset database.
[0006] In an optional embodiment of the present application, the first log files are integrated to generate a first target file, specifically including: Obtaining the key-value pairs contained in each first log file, and sorting each key-value pair based on the key and generation time of each key-value pair; For any key-value pair, if there are other key-value pairs that are the same as the key-value pair, then delete the other key-value pairs; A first target file is generated based on the sorting order of the remaining key-value pairs.
[0007] In an optional embodiment of the present application, after generating the first target file, the method further specifically includes: Verifying the first target file, and if the verification result is passed, storing the first target file in a preset database; If the verification result is not passed, the step of generating the first target file is executed again.
[0008] In an optional embodiment of the present application, verifying the first target file specifically includes: If the first target file meets any of the following conditions, a verification result indicating that the verification failed is returned, otherwise a verification result indicating that the verification passed is returned; Any of the following conditions may apply: The first total number of key-value pairs existing in the first target file is not equal to the difference between the second total number of key-value pairs contained in each first log file and the third total number of key-value pairs of each key-value pair that has been deleted; A first total length of each key-value pair existing in the first target file is not equal to a difference between a second total length of each key-value pair included in each first log file and a third total length of each key-value pair that has been deleted; The first operation result obtained after performing cyclic redundancy operation on each key-value pair existing in the first target file is different from the second operation result obtained after performing cyclic redundancy operation on each key-value pair contained in each first log file and the third operation result obtained by XORing the deleted key-value pairs.
[0009] In an optional embodiment of the present application, the method further specifically includes: receiving a modification instruction for a first target file; The data unit or the corresponding time area stored in the first target file is modified based on the modification instruction to obtain a modified first target file.
[0010] In an optional embodiment of the present application, after the first target file is generated, the following steps are specifically included: Based on the first target file, generating identification information corresponding to the first target file; the identification information includes the first log files integrated when generating the first target file, the file areas involved when generating the first target file, and the statistical information when generating the first target file; the identification information is used to find the first target file; The identification information is stored in a preset database.
[0011] In an optional embodiment of the present application, the method further specifically includes: In response to a target file acquisition instruction input by a user, a target file acquisition interface is displayed to the user, wherein the target file acquisition interface includes each first target file and identification information corresponding to each first target file; In response to a selection instruction input by a user for any first target file in the target file acquisition interface, any first target file is sent to the user.
[0012] In a second aspect, an embodiment of the present application provides a database recovery device, including: An instruction receiving module, used to receive a version recovery instruction for a target database, wherein the version recovery instruction includes a target time to be recovered; A target file acquisition module is used to acquire at least one second target file from a plurality of first target files stored in a preset database based on a target time; wherein each first target file is generated based on at least two first log files for a target database, the first target file includes a time zone, and the time zone is determined based on the generation time of each first log file that generates the first target file; and the end time of the time zone of each second target file is before the target time; A log file acquisition module, configured to acquire at least one second log file from a preset database based on the target time and each end time if the target time and the end time of the time zone of each stored first target file are different; The version recovery module is used to input at least one second target file into the target database and replay each second log file to restore the target database to the version corresponding to the target time.
[0013] In an optional embodiment of the present application, the log file acquisition module is specifically used to: Determine a third target file from each second target file; the end time of the third target file is before the target time and is closest to the target time; At least one second log file whose generation time is between the end time of the time zone of the third target file and the target time is obtained.
[0014] In an optional embodiment of the present application, the device further includes a target file generation module, which is specifically used to: Scan the target database to obtain at least two first log files for the target database; The first log files are integrated to generate a first target file, and the first target file is stored in a preset database.
[0015] In an optional embodiment of the present application, the target file generation module is specifically used to: Obtaining the key-value pairs contained in each first log file, and sorting each key-value pair based on the key and generation time of each key-value pair; For any key-value pair, if there are other key-value pairs that are the same as the key-value pair, then delete the other key-value pairs; A first target file is generated based on the sorting order of the remaining key-value pairs.
[0016] In an optional embodiment of the present application, the device further includes a target file verification module, which is specifically used to: Verifying the first target file, and if the verification result is passed, storing the first target file in a preset database; If the verification result is not passed, the step of generating the first target file is executed again.
[0017] In an optional embodiment of the present application, the target file verification module is specifically used to: If the first target file meets any of the following conditions, a verification result indicating that the verification failed is returned, otherwise a verification result indicating that the verification passed is returned; Any of the following conditions may apply: The first total number of key-value pairs existing in the first target file is not equal to the difference between the second total number of key-value pairs contained in each first log file and the third total number of key-value pairs of each key-value pair that has been deleted; A first total length of each key-value pair existing in the first target file is not equal to a difference between a second total length of each key-value pair included in each first log file and a third total length of each key-value pair that has been deleted; The first operation result obtained after performing cyclic redundancy operation on each key-value pair existing in the first target file is different from the second operation result obtained after performing cyclic redundancy operation on each key-value pair contained in each first log file and the third operation result obtained by XORing the deleted key-value pairs.
[0018] In an optional embodiment of the present application, the device further includes a target file modification module, which is specifically used to: receiving a modification instruction for a first target file; The data unit or the corresponding time area stored in the first target file is modified based on the modification instruction to obtain a modified first target file.
[0019] In an optional embodiment of the present application, the device further includes an identification information generating module, which is specifically used to: Based on the first target file, generating identification information corresponding to the first target file; the identification information includes the first log files integrated when generating the first target file, the file areas involved when generating the first target file, and the statistical information when generating the first target file; the identification information is used to find the first target file; The identification information is stored in a preset database.
[0020] In an optional embodiment of the present application, the device further includes a target file display module, which is specifically used to: In response to a target file acquisition instruction input by a user, a target file acquisition interface is displayed to the user, wherein the target file acquisition interface includes each first target file and identification information corresponding to each first target file; In response to a selection instruction input by a user for any first target file in the target file acquisition interface, any first target file is sent to the user.
[0021] In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory; The processor executes the computer program to implement the method provided in the embodiment of the first aspect or any optional embodiment of the first aspect.
[0022] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method provided in the embodiment of the first aspect or any optional embodiment of the first aspect is implemented.
[0023] The beneficial effects of the technical solution provided by the embodiment of the present application are: The solution provided by the present application, when version recovery is required, obtains one or more stored target files and part of the log files, inputs the obtained target files into the target database, so that the target database can be quickly restored to the database version at the time corresponding to the multiple target files, and then replays a small section of the log file to achieve database version recovery. There is no need to replay a large number of log files one by one, which can effectively improve the efficiency of database version recovery. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in describing the embodiments of the present application are briefly introduced below.
[0025] Figure 1 A flowchart of a database recovery method provided in an embodiment of the present application; Figure 2 A flowchart of a method for generating a target file in an example of an embodiment of the present application; Figure 3 This is a schematic diagram of the architecture comparison of a database recovery method in an example of an embodiment of the present application; Figure 4 A structural block diagram of a database recovery device provided in an embodiment of the present application; Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] The embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.
[0027] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation as other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" may be implemented as "A", or as "B", or as "A and B".
[0028] 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.
[0029] The following describes several exemplary embodiments to illustrate the technical solutions of the embodiments of the present application and the technical effects produced by the technical solutions of the present application. It should be noted that the following embodiments can refer to, draw on or combine with each other, and the same terms, similar features and similar implementation steps in different embodiments will not be described repeatedly.
[0030] Figure 1 A flowchart of a database recovery method is provided for an embodiment of the present application. The execution subject of the method may be a terminal (such as a computer, a mobile phone, etc.). Figure 1 As shown, the method may include: Step S101: receiving a version recovery instruction for a target database, wherein the version recovery instruction includes a target time to be recovered.
[0031] The version recovery instruction may be initiated by a user, and the user specifies the target time to which the target database needs to be restored through the terminal. The terminal may search for the historical version number information of the database corresponding to the target time according to the target time.
[0032] Step S102, obtaining at least one second target file from multiple first target files stored in a preset database based on the target time; wherein each first target file is generated based on at least two first log files for the target database, the first target file includes a time area, and the time area is determined based on the generation time of each first log file that generates the first target file; the end time of the time area of each second target file is before the target time.
[0033] Among them, the preset database can be used to store other information such as the target file, log file, etc. of the target database. In the embodiment of the present application, the preset can be other databases independent of the target database, or the target database itself, or a hardware external storage device, etc., which is not limited in the present application. The first target file is a sst (Static Sorted Table, a database storage format) format file, which can be a snapshot backup file used to record the target database version within a period of time (i.e., the corresponding time zone), and the file can be obtained by integrating several first log files in the corresponding time zone. The specific time zone of each target file can be determined by the generation time of each first log file used when integrating the first target file. Specifically, the earliest generation time integrated into each first log file can be used as the starting time of the time zone, and the latest generation time integrated into each first log file can be used as the end time of the time zone. The generation time of each first log file can be the timestamp corresponding to the log file. When the database receives the target file, it can quickly restore the database to the corresponding version according to the snapshot backup corresponding to the target file. The first target file can be generated according to preset conditions, such as every preset time interval, when the log files accumulate to a certain number, etc., which are not limited in this application. The end time is the last moment in the time zone.
[0034] Specifically, after receiving the version recovery instruction, the terminal selects one or more second target files from the first target files stored in the preset database according to the target time, and through these second target files, the target database can be quickly restored to the corresponding historical backup version. It can be understood that when performing database recovery at the target time, the data content before the target time is often required. Therefore, the time corresponding to the data content of each second target file obtained by this application should be before the target time, and the time representing the data content corresponding to the target file is the time zone of the target file.
[0035] Step S103: if the target time is different from the end time of the time zone of each stored first target file, then at least one second log file is obtained from a preset database based on the target time and each end time.
[0036] It is understandable that if there is a moment that is the same as the target moment among the stored termination moments, then the first target file corresponding to the termination moment of the same moment can be directly obtained and used as the second target file. When the target moment is different from the stored termination moments, the database can be restored to the version before the target moment, and then a small log file can be replayed. Specifically, the log file between the two timestamps (i.e., the second target file) can be obtained based on the termination moment and the target moment of the selected second target file.
[0037] Step S104: input at least one second target file into the target database, and replay each second log file to restore the target database to a version corresponding to the target time.
[0038] Specifically, for each second target file and second log file obtained in the above steps S102-S103, each second target file is first input into the target database, so that the target database is first restored to the corresponding historical backup version, and then a short segment of the second log file is replayed on the restored historical backup version, so that the target database can be quickly restored to the historical version at the target moment.
[0039] The solution provided by the present application, when version recovery is required, obtains one or more stored target files and part of the log files, inputs the obtained target files into the target database, so that the target database can be quickly restored to the database version at the time corresponding to the multiple target files, and then replays a small section of the log file to achieve database version recovery. There is no need to replay a large number of log files one by one, which can effectively improve the efficiency of database version recovery.
[0040] In an optional embodiment of the present application, based on the target time and each termination time, obtaining at least one second log file from a preset database specifically includes: Determine a third target file from each second target file; the end time of the third target file is before the target time and is closest to the target time; At least one second log file whose generation time is between the end time of the time zone of the third target file and the target time is obtained.
[0041] Specifically, in order to improve the efficiency of database version recovery, the solution provided in the embodiment of the present application adopts the strategy of inputting as many target files as possible into the target database and replaying as few log files as possible. Therefore, in order to ensure that the number of log files that need to be replayed is the least, a third target file whose end time is closest to the target time and before the target time can be selected, and then each second log file between the end time of the third target file and the target time can be selected.
[0042] In an optional embodiment of the present application, the first target file is generated in the following manner: Scan the target database to obtain at least two first log files for the target database; The first log files are integrated to generate a first target file, and the first target file is stored in a preset database.
[0043] Specifically, Figure 2 As shown, whenever the first target file needs to be generated, the target database needs to be scanned first to obtain each log file within the corresponding time range, and then these log files are integrated and compressed to obtain the corresponding first target file, and then the integrated first target file is stored in the preset database. Optionally, in an embodiment of the present application, after the first target file is generated, each log file used to generate the first target file can be deleted to save storage space of the preset database.
[0044] It should be noted that in the embodiment of the present application, the timing of generating the first target file can be set by the user. For example, the target file can be generated once every time period (the log files between this moment and the last generation moment are integrated), or the target file can be generated once the accumulated log files reach a certain number (all log files between the log files generated at this time and the log files corresponding to the last generation moment are integrated). The present application does not limit this.
[0045] In an optional embodiment of the present application, the first log files are integrated to generate a first target file, specifically including: Obtaining the key-value pairs contained in each first log file, and sorting each key-value pair based on the key and generation time of each key-value pair; For any key-value pair, if there are other key-value pairs that are the same as the key-value pair, then delete the other key-value pairs; A first target file is generated based on the sorting order of the remaining key-value pairs.
[0046] The key may be a data attribute stored in the database, the key value corresponding to the key is a specific value of the data attribute, and each key-value pair may represent a specific value corresponding to a data attribute. The key-value pair included in the first log file may be a modification record of the key value in the target database.
[0047] Specifically, after obtaining several first log files, first extract the key-value pairs contained in these log files, and sort them according to the keys and generation time of these key-value pairs. Specifically, you can prioritize sorting according to the first letter of each key name in alphabetical order, for example (according to A, B, C, D...), if the first letter is the same, sort it according to the order of the second letter, and so on. If all the letters are the same, you can sort them from early to late according to the generation time of each key-value pair or other custom methods. Since there may be some duplications caused by retries in the log files, after the sorting is completed, the duplicate key-value pairs need to be cleaned up, and finally the remaining key-value pairs are generated into the first target file in the order previously sorted.
[0048] In an optional embodiment of the present application, after generating the first target file, the method further specifically includes: Verifying the first target file, and if the verification result is passed, storing the first target file in a preset database; If the verification result is not passed, the step of generating the first target file is executed again.
[0049] Specifically, in the embodiment of the present application, each time after the first target file is generated, it is necessary to verify whether the first target file generated this time is correct, so it is necessary to perform a check. When the check result passes, the generated first target file can be stored in a preset database. When the check result fails, it is necessary to regenerate the first target file once again and perform a check again until the check result passes.
[0050] In an optional embodiment of the present application, verifying the first target file specifically includes: If the first target file meets any of the following conditions, a verification result indicating that the verification failed is returned, otherwise a verification result indicating that the verification passed is returned; Any of the following conditions may apply: The first total number of key-value pairs existing in the first target file is not equal to the difference between the second total number of key-value pairs contained in each first log file and the third total number of key-value pairs of each key-value pair that has been deleted; A first total length of each key-value pair existing in the first target file is not equal to a difference between a second total length of each key-value pair included in each first log file and a third total length of each key-value pair that has been deleted; The first operation result obtained after performing cyclic redundancy operation on each key-value pair existing in the first target file is different from the second operation result obtained after performing cyclic redundancy operation on each key-value pair contained in each first log file and the third operation result obtained by XORing the deleted key-value pairs.
[0051] Specifically, the verification method provided in the present application mainly checks the correctness of the target file from three aspects. Only when all three aspects meet the preset conditions, the verification of the target file is considered to be passed. Specifically, on the first hand, the number of key-value pairs contained in the integrated first target file (the first total number of key-value pairs) should be equal to the sum of the number of key-value pairs of all the first log files used in this integration (the second total number of key-value pairs), minus the number of deduplicated key-value pairs (the third total number of key-value pairs); on the second hand, the total length of all key-value pairs contained in the integrated first target file (the first total length) should be equal to the sum of the lengths of the key-value pairs of all the first log files used in this integration (the second total length), minus the sum of the total lengths of the deduplicated key-value pairs (the third total length); on the third hand, the XOR sum (i.e., the first operation result) of all the key-value pairs in the integrated first target file calculated by the CRC (Cyclic Redundancy Check) 64 Hash algorithm should be equal to the XOR value of all the deduplicated key-value pairs (i.e., the third operation result) of the XOR sum (i.e., the second operation result) of all the key-value pairs in the first log file used in this integration calculated by the CRC64 Hash (i.e., 64-bit cyclic redundancy check hash) algorithm. If any of the above three aspects is not met, the verification result of failure will be returned.
[0052] In an optional embodiment of the present application, the method further specifically includes: receiving a modification instruction for a first target file; The data unit or the corresponding time area stored in the first target file is modified based on the modification instruction to obtain a modified first target file.
[0053] The modification instruction may be used to indicate metadata of the first target file, where the metadata is used to manage the content included in the first target file, such as the specific log file content and the corresponding time zone.
[0054] Specifically, after the first target file is generated, it is often necessary to modify the generated first target file according to actual needs (for example, modify the data and time range contained in the first target file). Therefore, the embodiment of the present application provides a way to directly modify the first target file. By inputting the corresponding modification instructions, the first target file can be directly modified according to the modification instructions without repeating the integration and compression operations.
[0055] In an optional embodiment of the present application, after the first target file is generated, the following steps are specifically included: Based on the first target file, generating identification information corresponding to the first target file; the identification information includes the first log files integrated when generating the first target file, the file areas involved when generating the first target file, and the statistical information when generating the first target file; the identification information is used to find the first target file; The identification information is stored in a preset database.
[0056] The identification information may be implemented through a Compaction Meta (compression metadata file). Each time a target file is generated, an identification information may be generated to record the relevant data of this generation step.
[0057] Specifically, each time the first target file is generated, the process of generating the first target file can be recorded, and the record includes the log files used in the process of generating the first target file, the file areas involved in the process of generating the first target file (the area of the log file, the area of outputting the first target file, etc.), and other statistical information, etc. After generation, the identification information is stored in the preset database, and the identification information can be used to facilitate the user to find out by searching the preset database when the user needs it.
[0058] In an optional embodiment of the present application, the method further specifically includes: In response to a target file acquisition instruction input by a user, a target file acquisition interface is displayed to the user, wherein the target file acquisition interface includes each first target file and identification information corresponding to each first target file; In response to a selection instruction input by a user for any first target file in the target file acquisition interface, any first target file is sent to the user.
[0059] Specifically, in the embodiment of the present application, for the convenience of the user, a method for the user to customize the selection of the required target file is also provided. Specifically, when the user needs to obtain the target file by himself, the target file acquisition instruction can be initiated through the terminal. In actual operation, it can be to click the relevant control that is pre-set and displayed to the user. After receiving the instruction, the terminal displays to the user an interface containing each stored first target file and the identification information of each first target file. The user can view the specific information of each first target file and each first target file on the interface, and then select the first target file he wants according to the specific information. When the user selects the desired first target file and sends the selection instruction, the terminal can send the first target file to the user. The specific sending method can be downloading or copying, etc., which is not limited in this application.
[0060] Combine the following Figure 3The architecture of the improved database version recovery method of this application is introduced, such as Figure 3 As shown, in the original scheme, the target database only uses full backup (i.e. Full Backup in the figure) regularly. When version recovery is required, it is necessary to first restore to the full backup time point that has been backed up, and then replay the corresponding log files (i.e. log Backup in the figure) in sequence. In the scheme provided by this application, the full backup (i.e. Full Backup in the figure) method is still retained normally, and then an additional method for generating target files offline at a scheduled time (i.e. Compack Backup in the figure) is provided. The offline scheduled generation method can better save system resources and has little impact on the running database cluster. When version recovery is required, the database can be restored to any time point where a full backup has been performed, and then the target files and related log files from that time point to the current moment can be obtained, so that fast version recovery can be achieved. Compared with the original architecture, the new architecture provided by this application can better save costs and improve efficiency.
[0061] Figure 4 A structural block diagram of a database recovery method device provided in an embodiment of the present application, such as Figure 4 As shown, the health evaluation device 400 of the Internet technology IT system may include: an instruction receiving module 401, a target file acquisition module 402, a log file acquisition module 403 and a version recovery module 404, wherein: The instruction receiving module 401 is used to receive a version recovery instruction for a target database, wherein the version recovery instruction includes a target time to be recovered; The target file acquisition module 402 is used to acquire at least one second target file from a plurality of first target files stored in a preset database based on a target time; wherein each first target file is generated based on at least two first log files for a target database, the first target file includes a time zone, and the time zone is determined based on the generation time of each first log file generating the first target file; and the end time of the time zone of each second target file is before the target time; The log file acquisition module 403 is used to acquire at least one second log file from a preset database based on the target time and each end time if the target time and the end time of the time zone of each stored first target file are different; The version recovery module 404 is used to input at least one second target file into the target database and replay each second log file to restore the target database to the version corresponding to the target time.
[0062] The solution provided by the present application, when version recovery is required, obtains one or more stored target files and part of the log files, inputs the obtained target files into the target database, so that the target database can be quickly restored to the database version at the time corresponding to the multiple target files, and then replays a small section of the log file to achieve database version recovery. There is no need to replay a large number of log files one by one, which can effectively improve the efficiency of database version recovery.
[0063] In an optional embodiment of the present application, the log file acquisition module is specifically used to: Determine a third target file from each second target file; the end time of the third target file is before the target time and is closest to the target time; At least one second log file whose generation time is between the end time of the time zone of the third target file and the target time is obtained.
[0064] In an optional embodiment of the present application, the device further includes a target file generation module, which is specifically used to: Scan the target database to obtain at least two first log files for the target database; The first log files are integrated to generate a first target file, and the first target file is stored in a preset database.
[0065] In an optional embodiment of the present application, the target file generation module is specifically used to: Obtaining the key-value pairs contained in each first log file, and sorting each key-value pair based on the key and generation time of each key-value pair; For any key-value pair, if there are other key-value pairs that are the same as the key-value pair, then delete the other key-value pairs; A first target file is generated based on the sorting order of the remaining key-value pairs.
[0066] In an optional embodiment of the present application, the device further includes a target file verification module, which is specifically used to: Verifying the first target file, and if the verification result is passed, storing the first target file in a preset database; If the verification result is not passed, the step of generating the first target file is executed again.
[0067] In an optional embodiment of the present application, the target file verification module is specifically used to: If the first target file meets any of the following conditions, a verification result indicating that the verification failed is returned, otherwise a verification result indicating that the verification passed is returned; Any of the following conditions may apply: The first total number of key-value pairs existing in the first target file is not equal to the difference between the second total number of key-value pairs contained in each first log file and the third total number of key-value pairs of each key-value pair that has been deleted; A first total length of each key-value pair existing in the first target file is not equal to a difference between a second total length of each key-value pair included in each first log file and a third total length of each key-value pair that has been deleted; The first operation result obtained after performing cyclic redundancy operation on each key-value pair existing in the first target file is different from the second operation result obtained after performing cyclic redundancy operation on each key-value pair contained in each first log file and the third operation result obtained by XORing the deleted key-value pairs.
[0068] In an optional embodiment of the present application, the device further includes a target file modification module, which is specifically used to: receiving a modification instruction for a first target file; The data unit or the corresponding time area stored in the first target file is modified based on the modification instruction to obtain a modified first target file.
[0069] In an optional embodiment of the present application, the device further includes an identification information generating module, which is specifically used to: Based on the first target file, generating identification information corresponding to the first target file; the identification information includes the first log files integrated when generating the first target file, the file areas involved when generating the first target file, and the statistical information when generating the first target file; the identification information is used to find the first target file; The identification information is stored in a preset database.
[0070] In an optional embodiment of the present application, the device further includes a target file display module, which is specifically used to: In response to a target file acquisition instruction input by a user, a target file acquisition interface is displayed to the user, wherein the target file acquisition interface includes each first target file and identification information corresponding to each first target file; In response to a selection instruction input by a user for any first target file in the target file acquisition interface, any first target file is sent to the user.
[0071] Reference below Figure 5 , which shows an electronic device suitable for implementing the embodiments of the present application (for example, Figure 1The electronic device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), wearable devices, etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0072] The electronic device includes: a memory and a processor, the memory is used to store a program for executing the method described in each of the above method embodiments; the processor is configured to execute the program stored in the memory. The processor here can be referred to as the processing device 501 described below, and the memory can include at least one of the read-only memory (ROM) 502, the random access memory (RAM) 503, and the storage device 508 described below, as shown below: like Figure 5 As shown, the electronic device 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 to a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0073] Typically, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0074] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 509, or installed from the storage device 508, or installed from the ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present application are executed.
[0075] It should be noted that the computer-readable storage medium mentioned above in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0076] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0077] The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0078] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: Receive a version recovery instruction for a target database, wherein the version recovery instruction includes a target time to be recovered; obtain at least one second target file from a plurality of first target files stored in a preset database based on the target time; wherein each first target file is generated based on at least two first log files for the target database, the first target file includes a time zone, and the time zone is determined based on the generation time of each first log file that generates the first target file; the end time of the time zone of each second target file is before the target time; if the target time is different from the end time of the time zone of each stored first target file, then obtain at least one second log file from the preset database based on the target time and each end time; input at least one second target file into the target database, and play back each second log file to restore the target database to the version corresponding to the target time.
[0079] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0080] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0081] The modules or units involved in the embodiments of the present application may be implemented by software or hardware. The name of a module or unit does not limit the unit itself in some cases. For example, the first constraint acquisition module may also be described as a "module for acquiring the first constraint".
[0082] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0083] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0084] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0085] The above descriptions are only some embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A database recovery method, It is characterized in that include: Receiving a version recovery instruction for a target database, wherein the version recovery instruction includes a target time to be recovered; At least one second target file is obtained from a plurality of first target files stored in a preset database based on the target time; wherein each first target file is generated based on at least two first log files for the target database, the first target file includes a time zone, and the time zone is determined based on the generation time of each first log file that generates the first target file; and the end time of the time zone of each second target file is before the target time; If the target time is different from the end time of the time zone of each stored first target file, obtaining at least one second log file from the preset database based on the target time and each end time; The at least one second target file is input into the target database, and each second log file is replayed to restore the target database to a version corresponding to the target time.
2. The method according to claim 1, It is characterized in that The acquiring at least one second log file from the preset database based on the target time and each termination time includes: Determine a third target file from each second target file; the end time of the third target file is before the target time and is closest to the target time; At least one second log file whose generation time is between the end time of the time zone of the third target file and the target time is obtained.
3. The method according to claim 1, It is characterized in that The first target file is generated by: Scan the target database to obtain at least two first log files for the target database; The first log files are integrated to generate the first target file, and the first target file is stored in the preset database.
4. The method according to claim 3, It is characterized in that The step of integrating the first log files to generate the first target file includes: Obtaining the key-value pairs contained in each first log file, and sorting each key-value pair based on the key and generation time of each key-value pair; For any key-value pair, if there is another key-value pair that is the same as the key-value pair, delete the other key-value pair; The first target file is generated based on the sorting order of the remaining key-value pairs.
5. The method according to claim 4, It is characterized in that After generating the first target file, the method further includes: Verifying the first target file, and if the verification result is passed, storing the first target file in the preset database; If the verification result is failed, the step of generating the first target file is executed again.
6. The method according to claim 5, It is characterized in that The verifying the first target file includes: If the first target file meets any of the following conditions, a verification result indicating that the verification fails is returned; otherwise, a verification result indicating that the verification passes is returned; Any of the conditions include: The first total number of key-value pairs in the first target file is not equal to the difference between the second total number of key-value pairs in each of the first log files and the third total number of key-value pairs of each of the deleted key-value pairs; A first total length of each key-value pair existing in the first target file is not equal to a difference between a second total length of each key-value pair included in each first log file and a third total length of each deleted key-value pair; A first operation result obtained after performing a cyclic redundancy operation on each key-value pair existing in the first target file is different from a third operation result obtained by performing a cyclic redundancy operation on each key-value pair contained in each first log file and performing an XOR operation on each deleted key-value pair.
7. The method according to claim 1, It is characterized in that The method further comprises: receiving a modification instruction for the first target file; The data unit or the corresponding time area stored in the first target file is modified based on the modification instruction to obtain a modified first target file.
8. The method according to claim 3, It is characterized in that After generating the first target file, the method further comprises: Based on the first target file, generating identification information corresponding to the first target file; the identification information includes the first log files integrated when generating the first target file, the file areas involved when generating the first target file, and the statistical information when generating the first target file; the identification information is used to find the first target file; The identification information is stored in the preset database.
9. The method according to claim 8, It is characterized in that The method further comprises: In response to a target file acquisition instruction input by a user, a target file acquisition interface is displayed to the user, wherein the target file acquisition interface includes each first target file and identification information corresponding to each first target file; In response to a selection instruction input by the user for any first target file in the target file acquisition interface, the any first target file is sent to the user.
10. A database recovery device, It is characterized in that include: An instruction receiving module, used to receive a version recovery instruction for a target database, wherein the version recovery instruction includes a target time to be recovered; a target file acquisition module, configured to acquire at least one second target file from a plurality of first target files stored in a preset database based on the target time; wherein each first target file is generated based on at least two first log files for the target database, the first target file includes a time zone, the time zone is determined based on the generation time of each first log file generating the first target file, and the end time of the time zone of each second target file is before the target time; A log file acquisition module, configured to acquire at least one second log file from the preset database based on the target time and each end time if the target time and the end time of the time zone of each stored first target file are different; The version recovery module is used to input the at least one second target file into the target database and replay each second log file to restore the target database to the version corresponding to the target time.
11. An electronic device comprising a memory, a processor and a computer program stored in the memory, It is characterized in that The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 9.
12. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.
