Data recovery method and device, electronic device and storage medium

By parsing the redo log files of the MySQL database and generating recovery instructions, the problem of the MySQL database being unable to recover after abnormal operations is solved, the error data recovery of the database is realized, and the recovery efficiency and success rate are improved.

CN113760608BActive Publication Date: 2024-09-17BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111053302.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-08
Publication Date
2024-09-17
Estimated Expiration
2041-09-08

AI Technical Summary

Technical Problem

After abnormal operations are performed in the MySQL database, data recovery cannot be performed due to lack of backup or unavailable backup files, resulting in erroneous data that cannot be recovered.

Method used

By obtaining the redo log file of the target database, parsing the rollback log, generating recovery instructions, and instructing the device to perform recovery operations to restore the database to the historical data state before the erroneous data change.

Benefits of technology

It realizes the error data recovery of the database when there is a lack of backup or the backup file is unavailable, provides a new database recovery implementation method, and improves the efficiency and success rate of database maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113760608B
    Figure CN113760608B
Patent Text Reader

Abstract

The present application provides a data recovery method and device, an electronic device and a storage medium. The method includes: obtaining a target redo log file of a target database; parsing a target rollback log from the target redo log file; parsing the target rollback log according to the constituent fields of the target rollback log to obtain a rollback log record; generating a recovery instruction for recovering the target database according to the rollback log record; instructing the device where the target database is located to execute the recovery instruction to recover the target database from the state after executing the erroneous data change to the historical data state. The present application solves the problem in the related art that the target database cannot be recovered when there is no backup after the target database performs an abnormal operation, or the backup file of the target database is unavailable after the abnormal operation is performed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a data recovery method and device, an electronic device, and a storage medium. Background Art

[0002] During the use of MySQL database, the data therein will be frequently modified. Therefore, it is inevitable that erroneous data will exist in the modified MySQL database.

[0003] In the related art, when there is erroneous data in a MySQL database and the erroneous data needs to be recovered, if there is no data backup and binlog file (a file used to record data updates or potential updates in the MySQL database) in the MySQL database, the data cannot be recovered.

[0004] Therefore, in the related art, there is a problem that when the target database has no backup after performing an abnormal operation, or the backup file of the target database is unavailable after performing an abnormal operation, it is impossible to recover the erroneous data in the database. Summary of the invention

[0005] The present application provides a data recovery method and device, an electronic device and a storage medium to at least solve the problem in the related art that when the target database has no backup after performing an abnormal operation, or the backup file of the target database is unavailable after performing an abnormal operation, it is impossible to recover the erroneous data in the database.

[0006] According to one aspect of an embodiment of the present application, a data recovery method is provided, including:

[0007] Obtaining a target redo log file of a target database, wherein the target redo log file is a log file generated when an erroneous data change is performed in the target database;

[0008] Parse the target rollback log from the target redo log file;

[0009] Parsing the target rollback log according to the constituent fields of the target rollback log to obtain a rollback log record, wherein the rollback log record is information indicating the historical data state of the target database before executing the erroneous data change;

[0010] Generating a recovery instruction for recovering the target database according to the rollback log record;

[0011] Instruct the device where the target database is located to execute the recovery instruction to restore the target database from a state after executing the erroneous data change to the historical data state.

[0012] Optionally, as in the aforementioned method, parsing the target rollback log from the target redo log file includes:

[0013] Determine at least one target rollback log block in the target redo log file, wherein each target rollback log block includes one target rollback log;

[0014] The target rollback log is parsed in the target rollback log block using a first parsing method to obtain the target rollback log, wherein the target rollback log block includes logs of multiple log types, the multiple log types include a target log type to which the target rollback log belongs, and the first parsing method matches the log type to which the target rollback log belongs.

[0015] Optionally, as in the aforementioned method, the using the first parsing method to parse the log segment where the target rollback log in the target rollback log block is located includes: using multiple parsing methods to parse the current log segment in the target rollback log block respectively in the following manner until the target rollback log is parsed, and the starting position of the current log segment is the first position after the log segment successfully identified last time, or the starting position of the target rollback log block:

[0016] In the case where the first parsing method among the multiple parsing methods is used to identify the type start identifier of the target log type at the starting position of the current log segment, the first parsing method is continued to be used to identify the type end identifier of the target log type in the target rollback log, and the position where the type end identifier of the target log type is located is used as the ending position of the current log segment, and the content parsed from the starting position of the current log segment to the ending position of the current log segment is used as the target rollback log;

[0017] In case the type start identifier of the second log type is identified at the starting position of the current log segment using the second parsing method among the multiple parsing methods, the second parsing method is continued to be used to identify the type end identifier of the second log type in the target rollback log, and the first position after the type end identifier of the second log type is used as the starting position of the next log segment, wherein the second parsing method is any parsing method among the multiple parsing methods except the first parsing method.

[0018] Optionally, as in the aforementioned method, parsing the target rollback log according to the constituent fields of the target rollback log to obtain the rollback log record includes:

[0019] Determine the order relationship between the constituent fields of the target rollback log;

[0020] Parsing the target rollback log according to the order relationship to obtain a field value of each of the component fields;

[0021] The rollback log record is obtained according to the field value of each of the component fields.

[0022] Optionally, as in the aforementioned method, generating a recovery instruction for recovering the target database according to the rollback log record includes:

[0023] Determine the historical primary key value of the historical data, the historical field name and the historical field value of the historical component field of the historical data through the rollback log record, wherein the historical data is the data of the target database before the error data change is executed, and the historical component field is the field in the historical data whose field value is modified after the error data change is executed;

[0024] The historical primary key value is written into the write position of the primary key value of the data to be modified in the recovery statement template, the historical field name is written into the write position of the field name of the field to be modified in the recovery statement template, and the historical field value is written into the write position of the field value of the field to be modified in the recovery statement template to obtain the recovery instruction.

[0025] Optionally, as in the aforementioned method, instructing the device where the target database is located to execute the recovery instruction to restore the target database from the state after executing the erroneous data change to the historical data state includes:

[0026] instructing the device to locate target data in the target database according to the historical primary key value in the recovery instruction, wherein the target data is data after the historical data is changed by the erroneous data;

[0027] instructing the device to locate, in the target data, a target field changed by the erroneous data according to the historical field name in the recovery instruction;

[0028] The device is instructed to modify the current value in the target field by using the historical field value to restore the target database to the historical data state.

[0029] Optionally, as in the aforementioned method, before obtaining the target redo log file of the target database, the method further includes:

[0030] Obtain target data changes executed by the target database at historical time;

[0031] When it is determined that the target data change does not meet the preset change requirement, the target data change is determined as the erroneous data change.

[0032] Optionally, as in the above method, when it is determined that the target data change does not meet the preset change requirement, after determining the target data change as an erroneous data change, the method further includes:

[0033] Determining a target business party corresponding to the target database, wherein the target business party is a business party that can operate the target database;

[0034] The operation performed by the target business party on the target database is interrupted.

[0035] According to another aspect of the embodiment of the present application, there is also provided a data recovery device, including:

[0036] An acquisition module, used for acquiring a target redo log file of a target database, wherein the target redo log file is a log file generated when an erroneous data change is performed in the target database;

[0037] A first parsing module, configured to parse the target redo log file to obtain a target rollback log;

[0038] A second parsing module is used to parse the target rollback log according to the constituent fields of the target rollback log to obtain a rollback log record, wherein the rollback log record is information indicating the historical data state of the target database before executing the erroneous data change;

[0039] A recovery instruction module, used to generate a recovery instruction for recovering the target database according to the rollback log record;

[0040] The database recovery module is used to instruct the device where the target database is located to execute the recovery instruction to restore the target database from the state after executing the erroneous data change to the historical data state.

[0041] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein the memory is used to store a computer program; and the processor is used to execute the method steps in any of the above embodiments by running the computer program stored in the memory.

[0042] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the method steps in any of the above embodiments when executed.

[0043] In an embodiment of the present application, a method of parsing a target redo log file of a target database is adopted, and a corresponding rollback log record is obtained by parsing the target redo log file of the target database. Since the rollback log record is information used to indicate the historical data state of the target database before executing the erroneous data change, the purpose of restoring the target database to the historical data state corresponding to the target rollback log in the target redo log file according to the rollback log record can be achieved, thereby achieving the technical effect of providing a new implementation method for recovering a database, thereby solving the problem in the related art that the target database cannot be recovered when there is no backup after executing an abnormal operation, or the backup file of the target database is unavailable after executing an abnormal operation. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0045] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0046] Figure 1 is a schematic diagram of a hardware environment of an optional data recovery method according to an embodiment of the present application;

[0047] Figure 2 is a flowchart of an optional data recovery method according to an embodiment of the present application;

[0048] Figure 3 is a structural block diagram of an optional data recovery device according to an embodiment of the present application;

[0049] Figure 4It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0050] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0051] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0052] According to one aspect of an embodiment of the present application, a data recovery method is provided. Optionally, in this embodiment, the above data recovery method can be applied to a hardware environment consisting of a terminal and a server. The server is connected to the terminal via a network, and can be used to provide services (such as game services, application services, etc.) for the terminal or a client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server.

[0053] The above network may include but is not limited to at least one of the following: wired network, wireless network. The above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal may not be limited to a PC, a mobile phone, a tablet computer, etc.

[0054] The data recovery method of the embodiment of the present application can be executed by a server, a terminal, or a server and a terminal together. The terminal can also execute the data recovery method of the embodiment of the present application by a client installed thereon.

[0055] Taking the data recovery method in this embodiment executed by the server as an example, Figure 1 is a flow chart of an optional data recovery method according to an embodiment of the present application, such as Figure 1 As shown, the process of the method may include the following steps:

[0056] Step S101, obtaining a target redo log file of a target database, wherein the target redo log file is a log file generated when an erroneous data change is performed in the target database.

[0057] The data recovery method in this embodiment can be applied to scenarios where data recovery is required for a specified database, for example, scenarios where the target database has no backup after performing an abnormal operation, or scenarios where the backup file of the target database is unavailable after performing an abnormal operation, etc. It can also be a scenario where data is recovered for a database in other scenarios. In the embodiment of the present application, the data recovery method is described by taking the case where the target database has no backup or backup after performing an abnormal operation as an example. For other types of target databases that perform erroneous data changes, the data recovery method is also applicable if there is no contradiction.

[0058] Taking the scenario where the target database cannot be started or has no backup files after abnormal operation as an example, data recovery is performed on the target database to restore the target database to the historical data state before the erroneous data change is performed.

[0059] The target database may be a database where data is changed, and the target database generates a target redo log file after the data is changed.

[0060] Furthermore, the target redo log file may be a log file generated when an erroneous data change is performed in the target database.

[0061] The erroneous data changes may include, but are not limited to, changes such as writing erroneous data into the target database or deleting erroneous data.

[0062] For example, after the business party corresponding to the target database performs an erroneous operation on the target database (such as writing erroneous data), an erroneous data change is executed in the target database. Therefore, a target redo log file corresponding to the erroneous data change executed in the target database is generated, such as a Redo Log File file.

[0063] Step S102, parsing the target redo log file to obtain the target rollback log.

[0064] After obtaining the target redo log file, the target rollback log can be parsed from the redo log file.

[0065] Before the target database executes the erroneous data change, the target database may have executed multiple data changes, and if the target rollback log corresponding to at least one of the data changes is not deleted, at least one target rollback log can be parsed from the target redo log file. Therefore, the parsed target rollback logs may include one or more.

[0066] Step S103, parsing the target rollback log according to the constituent fields of the target rollback log to obtain a rollback log record, wherein the rollback log record is information indicating the historical data state before the target database executes the erroneous data change.

[0067] After all target rollback logs of the target redo log are obtained, each target rollback log may be parsed to obtain the rollback log record in each target rollback log.

[0068] When the target rollback log is obtained, the structure of the target rollback log can be determined through the constituent fields of the target rollback log, and the parameter type referred to by each constituent field can be determined. Therefore, according to the constituent fields of the target rollback log, the target rollback log is parsed to obtain the rollback log record.

[0069] The rollback log record may be information indicating the historical data state before the target database executes the erroneous data change, and the historical data state may include but is not limited to: the change position corresponding to the erroneous data change, and the parameter value before the change. For example, when the erroneous data change changes the value corresponding to the primary key X and the update column Y from a null value (i.e., NULL) to "xxx", the rollback log record may include the value corresponding to the primary key X and the update column Y as a null value (i.e., NULL).

[0070] Step S104: generating a recovery instruction for recovering the target database according to the rollback log record.

[0071] After the rollback log record is obtained, a recovery instruction for recovering the target database may be generated according to the rollback log record.

[0072] The recovery instruction may be an instruction for recovering the target database from the state after executing the erroneous data change to the historical data state. Therefore, the recovery instruction may include the location information and value (which may be a null value) that need to be recovered.

[0073] In the case where there are multiple target rollback logs, since each target rollback log includes a rollback log record, different rollback log records are used to indicate different historical data states of the target database; for example, when there are three rollback log records (A, B, C), A corresponds to the historical data state of the target database 3 minutes before the erroneous data change is executed, B corresponds to the historical data state of the target database 2 minutes before the erroneous data change is executed, and C corresponds to the historical data state of the target database 1 minute before the erroneous data change is executed. Therefore, corresponding recovery instructions a, b, and c can be generated according to A, B, and C, respectively.

[0074] For example, based on the previous example, when the rollback log record may include that the values ​​corresponding to the primary key X and the update column Y are null values ​​(i.e., NULL), the recovery instruction Q generated based on the rollback log record may be an instruction to instruct to modify the values ​​of the primary key X and the update column Y to null values.

[0075] Step S105, instructing the device where the target database is located to execute a recovery instruction to restore the target database from the state after executing the erroneous data change to the historical data state.

[0076] After the recovery instruction is generated, the device where the target database is located can be instructed to execute the recovery instruction to restore the target database from the state after the erroneous data change to the historical data state.

[0077] The device where the target database is located may be a computing device corresponding to the target database, or may be a computing device used to modify data in the target database.

[0078] When the recovery instruction includes one, the device where the target database is located can be instructed to execute the single recovery instruction to recover the target database from the state after executing the erroneous data change to the historical data state corresponding to the recovery instruction.

[0079] In the case where the recovery instructions include multiple ones, the device where the target database is located is instructed to execute the target recovery instruction to restore the target database from the state after the erroneous data change is executed to the target historical data state, wherein the target recovery instruction is a recovery instruction for restoring the target database, and the target historical data state is the historical data state of the target database indicated by the rollback log record corresponding to the target recovery instruction. That is, the device where the target database is located can be instructed to first determine the target recovery instruction for recovery from the multiple recovery instructions to restore the target database from the state after the erroneous data change is executed to the historical data state corresponding to the target recovery instruction.

[0080] For example, when only the aforementioned recovery instruction Q exists and the business party corresponding to the target database determines to restore the target database through the recovery instruction Q, the recovery instruction Q can be triggered to execute through a preset operation (for example, clicking "Confirm to restore to this state") to instruct the device where the target database is located to execute the recovery instruction Q, and restore the target database from the state after executing the erroneous data change to the historical data state in which the values ​​corresponding to the primary key X and the update column Y are empty (i.e., NULL).

[0081] Through the method in this embodiment, when the target database has no backup after executing an abnormal operation, or the backup file of the target database is unavailable after executing an abnormal operation, the target database can be restored to the historical data state corresponding to the target rollback log in the target redo log file through the target redo log file of the target database, thereby achieving the purpose of restoring the erroneous data state in the target database to the correct data state, and providing a new implementation method for database recovery.

[0082] As an optional implementation, as in the aforementioned method, the step S102 of parsing the target rollback log from the target redo log file includes the following steps:

[0083] Step S201: determine at least one target rollback log block in a target redo log file, wherein each target rollback log block includes a target rollback log.

[0084] Since each time data is updated on the target database, a latest target rollback log block (i.e., Redo Block) corresponding to the data update will be generated in the target redo log file, and at least the latest target rollback log block will be retained in the target redo log file; therefore, after obtaining the target redo log file of the target database, the target redo log file can be parsed (for example, according to the log block name, etc.) to obtain at least one target rollback log block, and each target rollback log block includes a target rollback log (i.e., MLOG_UNDO_INSERT).

[0085] Step S202, using the first parsing method to parse the log segment where the target rollback log is located in the target rollback log block to obtain the target rollback log, wherein the target rollback log block includes logs of multiple log types, the multiple log types include the target log type to which the target rollback log belongs, and the first parsing method matches the log type to which the target rollback log belongs.

[0086] A target rollback log block may include several log segments of different types. Optionally, when a log segment named MLOG_UNDO_INSERT is parsed, it can be determined that the target rollback log is parsed.

[0087] The target rollback log is a record contained in the target rollback log block. The target rollback log block includes logs of multiple log types. The multiple log types include the target log type to which the target rollback log belongs. Therefore, it is necessary to determine the first parsing method that matches the log type to which the target rollback log belongs among all parsing methods corresponding to the target rollback log block.

[0088] After determining the first parsing method corresponding to the target rollback log, the first parsing method can be used to parse the log segment where the target rollback log is located in the target rollback log block to obtain the target rollback log.

[0089] For example, it is uncertain how much space each redo record (i.e., log) in a redo block (i.e., the target rollback log block) occupies. Therefore, each redo record in the redo block can be parsed out using all parsing methods corresponding to the target rollback log block until the log segment where the target rollback log is located is parsed using the first parsing method to obtain the target rollback log. Alternatively, the first parsing method can be used to start parsing from the first position of the target rollback log block. When parsing fails, the position that cannot be parsed is skipped and parsing starts from the next position until the log segment where the target rollback log is located is parsed using the first parsing method to obtain the target rollback log.

[0090] When there are multiple target rollback log blocks, the target rollback log can be obtained by parsing each target rollback log block using the method in this embodiment.

[0091] Through the method in this embodiment, the purpose of parsing the target redo log file to obtain the target rollback log can be achieved, so as to facilitate the recovery of the target database according to the target rollback log at a later time.

[0092] like Figure 2 As shown, as an optional implementation, as in the aforementioned method, the step S201 uses the first parsing method to parse the log segment where the target rollback log is located in the target rollback log block, and obtaining the target rollback log includes the following steps: using multiple parsing methods to parse the current log segment in the target rollback log block respectively in the following manner until the target rollback log is parsed, and the starting position of the current log segment is the first position after the log segment successfully identified last time, or the starting position of the target rollback log block:

[0093] Step S301, when using the first parsing method among multiple parsing methods to identify the type start identifier of the target log type at the starting position of the current log segment, continue to use the first parsing method to identify the type end identifier of the target log type in the target rollback log, and use the position of the type end identifier of the target log type as the end position of the current log segment, and use the content parsed from the starting position of the current log segment to the end position of the current log segment as the target rollback log.

[0094] After the target rollback log is determined, the target rollback log can be parsed using the first parsing method to obtain the target rollback log. Since the space occupied by each log in the target rollback log block cannot be determined, the log segment of each log in the target rollback log block cannot be determined. Therefore, the target rollback log block can be parsed in a loop using various parsing methods until the target rollback log is parsed in the target rollback log block using the first parsing method.

[0095] When the corresponding N logs have been parsed out using N of the parsing methods, the current log segment is the log segments in the target rollback log block except for the log segments of the N logs, that is, the starting position of the current log segment is the first position after the log segment that was successfully identified last time; when the log is not parsed out in the target rollback log block using any of the parsing methods, the current log segment is the target rollback log block, that is, the starting position of the current log segment is the starting position of the target rollback log block.

[0096] When the current log segment is parsed by the first parsing method, if the type start identifier of the target log type is identified at the starting position of the current log segment by the first parsing method, the first parsing method can continue to be used to identify in the target rollback log until the type end identifier of the target log type is identified.

[0097] The type start identifier of the target log type may be one or more identifiers located at the start position of all logs corresponding to the log type of the target rollback log.

[0098] The type end identifier of the target log type may be one or more identifiers located at the end position of all logs corresponding to the log type of the target rollback log.

[0099] After identifying the type start identifier and the type end identifier, all bytes between the type start identifier and the type end identifier (including the type start identifier and the type end identifier) ​​can be used as the log segment of the target rollback log. Therefore, the position of the type end identifier of the target log type can be used as the end position of the current log segment, and the content parsed from the start position to the end position of the current log segment can be used as the target rollback log.

[0100] Step S302, when using the second parsing method among multiple parsing methods to identify the type start identifier of the second log type at the starting position of the current log segment, continue to use the second parsing method to identify the type end identifier of the second log type in the target rollback log, and use the first position after the type end identifier of the second log type as the starting position of the next log segment, wherein the second parsing method is any parsing method among the multiple parsing methods except the first parsing method.

[0101] The method of parsing the current log segment by the second parsing method to obtain the log of the second log type corresponding to the second parsing method is the same as the method in step S301, which will not be described in detail here.

[0102] When the type end identifier of the second log type is identified in the target rollback log using the second parsing method, the log of the second log type corresponding to the second parsing method can be determined in the current log segment, and then the first position after the type end identifier of the second log type can be used as the starting position of the next log segment, so as to continue parsing from the starting position of the next log segment through various parsing methods.

[0103] This cycle is repeated until the target rollback log is parsed using the first parsing method.

[0104] According to the method in this embodiment, the target rollback log block can be cyclically parsed in various parsing modes to obtain the target rollback log in the target rollback log block, which has the advantage of high parsing efficiency.

[0105] As an optional implementation, as in the aforementioned method, the step S103 parses the target rollback log according to the constituent fields of the target rollback log to obtain the rollback log record, including the following steps:

[0106] Step S401, determining the order relationship between the various constituent fields of the target rollback log.

[0107] Step S402: Parse the target rollback log in order to obtain the field value of each constituent field.

[0108] Step S403, obtaining a rollback log record according to the field value of each component field.

[0109] After obtaining the target rollback log, the order relationship between the constituent fields in the target rollback log can be determined, and then the target rollback log can be parsed according to the parsing method of each constituent field to obtain the field value of each constituent field. Each constituent field can have a corresponding field name.

[0110] For any rollback log, it includes multiple constituent fields, among which the location of the data where the erroneous data change is performed can be determined first through the information corresponding to the fields UNIQ FILED ORPRIMARY FILED, and then the data before the erroneous data change is performed at the location can be queried through the information corresponding to the field UPDATEFILED to obtain the data before the erroneous data change is performed.

[0111] Through the method in this embodiment, the rollback log record can be quickly parsed according to the target rollback log, so as to achieve the purpose of obtaining the data before the target database is changed by erroneous data.

[0112] As an optional implementation, as in the above method, the step S104 of generating a recovery instruction for recovering the target database according to the rollback log record includes the following steps:

[0113] Step S501, determine the historical primary key value of the historical data, the historical field name and the historical field value of the historical component field of the historical data through the rollback log record, wherein the historical data is the data in the target database before the erroneous data change is performed, and the historical component field is the field in the historical data whose field value is modified after the erroneous data change.

[0114] After the rollback log record is obtained, the historical primary key value of the historical data, the historical field name of the historical constituent field of the historical data, and the historical field value can be determined according to the rollback log record.

[0115] The historical primary key value may be a serial number for indicating the historical primary key of the data on which the error data change is performed, and the historical primary key value is consistent with the primary key value of the data after the error data change.

[0116] The historical field name may be a field name used to indicate a field in the data corresponding to the historical primary key that has undergone an erroneous data change, and may be represented by a parameter type corresponding to the field (eg, addr (address)), and the like.

[0117] The historical field value may be the value of the field corresponding to the historical field name before the erroneous data is changed.

[0118] Step S502, write the historical primary key value into the write position of the primary key value for writing the data to be modified in the recovery statement template, write the historical field name into the write position of the field name for writing the field to be modified in the recovery statement template, and write the historical field value into the write position of the field value for writing the field to be modified in the recovery statement template, to obtain a recovery instruction.

[0119] After obtaining the historical primary key value, the historical primary key value can be written into the write position of the primary key value for writing the data to be modified in the recovery statement template; after obtaining the historical field name, the historical field name can be written into the write position of the field name for writing the field to be modified in the recovery statement template; after obtaining the historical field value, the historical field value can be written into the write position of the field value for writing the field to be modified in the recovery statement template to obtain the recovery instruction.

[0120] The recovery statement template may be a pre-set template for writing recovery information (ie, historical primary key value, historical field name, historical field value, etc.) to generate a corresponding recovery instruction.

[0121] For example, update `type_test`.`test5` set `historical field name` = historical field value where `id` = 'historical primary key value';

[0122] When the historical primary key value is 18, the historical field name is addr, and the historical field value is NULL, the generated recovery instruction is: update `type_test`.`test5`set`addr`=NULL where`id`='18';

[0123] When the historical primary key value is 19, the historical field name is addr, and the historical field value is yyy, the generated recovery instruction is: update `type_test`.`test5`set `addr`=yyy where `id`='19'.

[0124] Through the method in this embodiment, a recovery instruction for recovering the target database can be automatically constructed, so that the target database can be automatically recovered to the historical data state before the erroneous data was changed according to the recovery instruction.

[0125] As an optional implementation, as in the above method, the step S105 instructs the device where the target database is located to execute a recovery instruction to restore the target database from the state after executing the erroneous data change to the historical data state, including the following steps:

[0126] Step S601, instructing the device to locate target data in a target database according to the historical primary key value in the recovery instruction, wherein the target data is the historical data after being changed by the erroneous data.

[0127] Step S602, the instructing device locates the target field changed by the erroneous data in the target data according to the historical field name in the recovery instruction.

[0128] Step S603, instructing the device to modify the current value in the target field by using the historical field value to restore the target database to the historical data state.

[0129] After the recovery instructions are generated, data in the target database can be modified according to the recovery instructions.

[0130] After receiving the recovery instruction, the device where the target database is located can locate the target data in the target database according to the historical primary key value in the parsed recovery instruction, because the primary key value of the historical data is consistent with the target data after the error data is changed.

[0131] After locating the target data, since the field names of the historical data and the target data after being changed by the erroneous data are consistent, the target field changed by the erroneous data can be located in the target data according to the historical field name in the parsed reply instruction.

[0132] After locating the target field in the target data, the current value in the target field can be modified according to the historical field value, thereby achieving the purpose of restoring the target database to the historical data state.

[0133] Through the method in this embodiment, the target database can be automatically restored to the historical data state through the recovery instruction, thereby effectively improving the efficiency of database recovery and reducing the workload of database maintenance personnel.

[0134] As an optional implementation, as in the above method, before the step S101 of obtaining the target redo log file of the target database, the method further includes the following steps:

[0135] Step S701, obtaining target data changes executed in the target database at historical time.

[0136] After the target database executes the target data change at a historical time, the target data change can be obtained by monitoring the target database.

[0137] The historical time may be a point in time before the current time.

[0138] The target data change may be to modify, add, delete, etc. the data.

[0139] Step S702: When it is determined that the target data change does not meet the preset change requirement, the target data change is determined as an erroneous data change.

[0140] After obtaining the target data change, it can be determined whether the target data change is an erroneous data change by determining whether the target data change meets the preset change requirements.

[0141] The preset change requirements may be requirements for limiting legal data changes, for example, limiting legal data types and legal change methods (for example, only additions can be made, and deletions are illegal).

[0142] For example, when the preset change requirement is that the value of the address field cannot be "xxx", if the target data change modifies the value of the address field with the primary key 18 to "xxx", the target data change is determined to be an erroneous data change.

[0143] Through the method in this embodiment, it is possible to automatically determine whether an erroneous data change occurs in the target database, so as to improve the response efficiency of recovering the target database.

[0144] As an optional implementation, as in the above method, in the case where it is determined in step S702 that the target data change does not meet the preset change requirement, after the target data change is determined as an erroneous data change, the method further includes the following steps:

[0145] Step S801: determine a target business party corresponding to a target database, wherein the target business party is a business party that can operate the target database.

[0146] Step S802: interrupting the target business party's operation on the target database.

[0147] After determining that the target data change is an erroneous data change, the business party corresponding to the target database can be determined through the target database docking interface.

[0148] The target business party is a business party that can operate the target database.

[0149] When it is determined that the target database has undergone erroneous data changes, the target business party's operations on the target database can be interrupted by switching the interface through which the target business party operates the target database. After the target database is restored to the historical data state, the target business party is allowed to operate on the target database again.

[0150] Through the method in this embodiment, by interrupting the target business party's operations on the target database when it is determined that an erroneous data change has occurred in the target database, it is possible to avoid the problem that the target rollback log in the target database is cleared due to the target business party's operations after the erroneous data change, resulting in the rollback log in the redo log file only containing information corresponding to the data state after the erroneous data change, and thus the target database cannot be restored to a normal historical data state. This can effectively improve the success rate of recovering the target database.

[0151] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0152] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory) / RAM (Random Access Memory), a disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0153] According to another aspect of an embodiment of the present application, a data recovery device for implementing the above data recovery method is also provided. Figure 3 is a structural block diagram of an optional data recovery device according to an embodiment of the present application, such as Figure 3 As shown, the device may include:

[0154] An acquisition module 1 is used to acquire a target redo log file of a target database, wherein the target redo log file is a log file generated when an erroneous data change is performed in the target database;

[0155] The first parsing module 2 is used to parse the target redo log file to obtain the target rollback log;

[0156] The second parsing module 3 is used to parse the target rollback log according to the constituent fields of the target rollback log to obtain a rollback log record, wherein the rollback log record is information indicating the historical data state before the target database executes the erroneous data change;

[0157] A recovery instruction module 4, used to generate a recovery instruction for recovering the target database according to the rollback log record;

[0158] The database recovery module 5 is used to instruct the device where the target database is located to execute a recovery instruction to restore the target database from the state after executing the erroneous data change to the historical data state.

[0159] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. In addition, the specific process of each module in the device of the embodiment of the present invention to implement its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0160] As an optional implementation, in the aforementioned device, the first parsing module 2 includes:

[0161] A determination unit, configured to determine at least one target rollback log block in a target redo log file, wherein each target rollback log block includes a target rollback log;

[0162] A parsing unit is used to parse the log segment where the target rollback log is located in the target rollback log block using a first parsing method to obtain a target rollback log, wherein the target rollback log block includes logs of multiple log types, the multiple log types include a target log type to which the target rollback log belongs, and the first parsing method matches the log type to which the target rollback log belongs.

[0163] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. In addition, the specific process of each module in the device of the embodiment of the present invention to implement its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0164] As an optional implementation, as in the aforementioned device, the parsing unit is used to: parse the current log segment in the target rollback log block using multiple parsing methods respectively in the following manner until the target rollback log is parsed, and the starting position of the current log segment is the first position after the log segment successfully identified last time, or the starting position of the target rollback log block:

[0165] In the case where the type start identifier of the target log type is identified at the start position of the current log segment using the first parsing method among the multiple parsing methods, the type end identifier of the target log type is continuously identified in the target rollback log using the first parsing method, and the position where the type end identifier of the target log type is located is used as the end position of the current log segment, and the content parsed from the start position of the current log segment to the end position of the current log segment is used as the target rollback log;

[0166] When a second parsing method among multiple parsing methods is used to identify a type start identifier of a second log type at the starting position of a current log segment, the second parsing method is continued to be used to identify a type end identifier of the second log type in a target rollback log, and the first position after the type end identifier of the second log type is used as the starting position of a next log segment, wherein the second parsing method is any parsing method among the multiple parsing methods except the first parsing method.

[0167] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. In addition, the specific process of each module in the device of the embodiment of the present invention to implement its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0168] As an optional implementation, in the aforementioned device, the second parsing module 3 is used to:

[0169] Determine the order relationship between the various constituent fields of the target rollback log;

[0170] Parse the target rollback log in order to obtain the field value of each component field;

[0171] According to the field value of each component field, a rollback log record is obtained.

[0172] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. In addition, the specific process of each module in the device of the embodiment of the present invention to implement its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0173] As an optional implementation, in the aforementioned device, the recovery instruction module 4 is used to:

[0174] Determine the historical primary key value of the historical data, the historical field name and the historical field value of the historical component field of the historical data through the rollback log record, wherein the historical data is the data of the target database before the error data change is executed, and the historical component field is the field in the historical data whose field value is modified after the error data change;

[0175] Write the historical primary key value into the write position of the primary key value for writing the data to be modified in the recovery statement template, write the historical field name into the write position of the field name for writing the field to be modified in the recovery statement template, and write the historical field value into the write position of the field value for writing the field to be modified in the recovery statement template to obtain a recovery instruction.

[0176] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. In addition, the specific process of each module in the device of the embodiment of the present invention to implement its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0177] As an optional implementation, as in the aforementioned device, the database recovery module 5 is used to:

[0178] The instructing device locates the target data in the target database according to the historical primary key value in the recovery instruction, wherein the target data is the data after the historical data is changed by the erroneous data;

[0179] The instructing device locates the target field changed by the erroneous data in the target data according to the historical field name in the recovery instruction;

[0180] The instructing device modifies the current value in the target field by using the historical field value to restore the target database to the historical data state.

[0181] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. In addition, the specific process of each module in the device of the embodiment of the present invention to implement its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0182] As an optional implementation, the aforementioned device further includes a determination module, which is used to:

[0183] Obtain target data changes executed in the target database at historical time;

[0184] When it is determined that the target data change does not meet the preset change requirements, the target data change is determined as an erroneous data change.

[0185] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. In addition, the specific process of each module in the device of the embodiment of the present invention to implement its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0186] As an optional implementation, the aforementioned device further includes an interrupt module, which is used to:

[0187] Determine a target business party corresponding to the target database, wherein the target business party is a business party that can operate the target database;

[0188] Interrupt the target business party's operations on the target database.

[0189] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. In addition, the specific process of each module in the device of the embodiment of the present invention to implement its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0190] According to another embodiment of the present application, there is also provided an electronic device, including: Figure 4 As shown, the electronic device may include: a processor 1501 , a communication interface 1502 , a memory 1503 and a communication bus 1504 , wherein the processor 1501 , the communication interface 1502 , and the memory 1503 communicate with each other via the communication bus 1504 .

[0191] Memory 1503, used for storing computer programs;

[0192] The processor 1501 is used to implement the steps of the above method embodiment when executing the program stored in the memory 1503.

[0193] The bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0194] The communication interface is used for communication between the above electronic device and other devices.

[0195] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0196] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0197] An embodiment of the present application further provides a computer-readable storage medium, the storage medium including a stored program, wherein the method steps of the above method embodiment are executed when the program is run.

[0198] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a ROM, a RAM, a mobile hard disk, a magnetic disk, or an optical disk.

[0199] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0200] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.

[0201] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0202] In the several embodiments provided in the present application, it should be understood that the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation, for example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, modules or indirect coupling or communication connection of modules, which can be electrical or other forms.

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

[0204] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.

[0205] The above is only a preferred implementation of the present application. 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 application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A data recovery method, characterized in that: include: Obtaining a target redo log file of a target database, wherein the target redo log file is a log file generated when an erroneous data change is performed in the target database; Parse the target rollback log from the target redo log file; According to the constituent fields of the target rollback log, the target rollback log is parsed to obtain a rollback log record, including: determining at least one target rollback log block in the target redo log file, each of the target rollback log blocks including one of the target rollback logs, the target rollback log block including logs of multiple log types, the multiple log types including the target log type to which the target rollback log belongs; using multiple parsing methods to parse the current log segment in the target rollback log block in the following manner, respectively, until the target rollback log is parsed, the starting position of the current log segment is the first position after the log segment successfully identified last time, or is the starting position of the target rollback log block: when a type start identifier of the target log type is identified at the starting position of the current log segment using a first parsing method among the multiple parsing methods, continuing to use the first parsing method to identify the target log type in the target rollback log The first parsing method matches the log type to which the target rollback log belongs. When the type start identifier of the second log type is identified at the start position of the current log segment using the second parsing method among the multiple parsing methods, the type end identifier of the second log type is continuously identified in the target rollback log using the second parsing method, and the first position after the type end identifier of the second log type is used as the start position of the next log segment. The second parsing method is any parsing method among the multiple parsing methods except the first parsing method, wherein the rollback log record is information for indicating the historical data state of the target database before executing the erroneous data change. Generating a recovery instruction for recovering the target database according to the rollback log record; Instruct the device where the target database is located to execute the recovery instruction to restore the target database from a state after executing the erroneous data change to the historical data state.

2. The method according to claim 1, characterized in that The target rollback log is parsed according to the constituent fields of the target rollback log to obtain the rollback log record, including: Determine the order relationship between the constituent fields of the target rollback log; Parsing the target rollback log according to the order relationship to obtain a field value of each of the component fields; The rollback log record is obtained according to the field value of each of the component fields.

3. The method according to claim 2, characterized in that The generating of a recovery instruction for recovering the target database according to the rollback log record comprises: Determine the historical primary key value of the historical data, the historical field name and the historical field value of the historical component field of the historical data through the rollback log record, wherein the historical data is the data in the target database before the error data change is performed and the error data change is performed, and the historical component field is the field in the historical data whose field value is modified after the error data change is performed; The historical primary key value is written into the write position of the primary key value of the data to be modified in the recovery statement template, the historical field name is written into the write position of the field name of the field to be modified in the recovery statement template, and the historical field value is written into the write position of the field value of the field to be modified in the recovery statement template to obtain the recovery instruction.

4. The method according to claim 3, characterized in that The instructing the device where the target database is located to execute the recovery instruction to restore the target database from the state after executing the erroneous data change to the historical data state includes: instructing the device to locate target data in the target database according to the historical primary key value in the recovery instruction, wherein the target data is data after the historical data is changed by the erroneous data; instructing the device to locate, in the target data, a target field changed by the erroneous data according to the historical field name in the recovery instruction; The device is instructed to modify the current value in the target field by using the historical field value to restore the target database to the historical data state.

5. The method according to any one of claims 1 to 4, characterized in that Before obtaining the target redo log file of the target database, the method further includes: Obtain target data changes executed by the target database at historical time; When it is determined that the target data change does not meet the preset change requirement, the target data change is determined as the erroneous data change.

6. The method according to claim 5, characterized in that When it is determined that the target data change does not meet the preset change requirement, after determining the target data change as an erroneous data change, the method further includes: Determining a target business party corresponding to the target database, wherein the target business party is a business party that can operate the target database; The operation performed by the target business party on the target database is interrupted.

7. A data recovery device, characterized in that: include: An acquisition module, used for acquiring a target redo log file of a target database, wherein the target redo log file is a log file generated when an erroneous data change is performed in the target database; A first parsing module, configured to parse the target redo log file to obtain a target rollback log; A second parsing module is used to parse the target rollback log according to the component fields of the target rollback log to obtain a rollback log record, including: determining at least one target rollback log block in the target redo log file, each of the target rollback log blocks including one of the target rollback logs, the target rollback log block including logs of multiple log types, the multiple log types including the target log type to which the target rollback log belongs; using multiple parsing methods to parse the current log segment in the target rollback log block in the following manner until the target rollback log is parsed, the starting position of the current log segment is the first position after the log segment successfully identified last time, or is the starting position of the target rollback log block: when a first parsing method among the multiple parsing methods is used to identify the type start identifier of the target log type at the starting position of the current log segment, continue to use the first parsing method to identify the target log type in the target rollback log. a type end identifier of a target log type, and the position of the type end identifier of the target log type is used as the end position of the current log segment, and the content parsed from the start position of the current log segment to the end position of the current log segment is used as the target rollback log, the first parsing method matches the log type to which the target rollback log belongs, and in the case of using a second parsing method among the multiple parsing methods to identify the type start identifier of a second log type at the start position of the current log segment, continue to use the second parsing method to identify the type end identifier of the second log type in the target rollback log, and use the first position after the type end identifier of the second log type as the start position of the next log segment, the second parsing method is any parsing method among the multiple parsing methods except the first parsing method, wherein the rollback log record is information for indicating the historical data state of the target database before executing the erroneous data change; A recovery instruction module, used to generate a recovery instruction for recovering the target database according to the rollback log record; The database recovery module is used to instruct the device where the target database is located to execute the recovery instruction to restore the target database from the state after executing the erroneous data change to the historical data state.

8. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, the communication interface and the memory communicate with each other via the communication bus, wherein: The memory is used to store computer programs; The processor is configured to execute the method steps of any one of claims 1 to 6 by running the computer program stored in the memory.

9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method steps described in any one of claims 1 to 6 when run.