Data recovery method, device, computer readable storage medium and processor
By parsing and generating recovery instructions in the database, automatic recovery of data tables is realized, solving the data recovery problem that requires manual programming in the existing technology, and improving efficiency and security.
Patent Information
- Application Number
- CN202110559466.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-21
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-05-21
AI Technical Summary
In the existing technology, data recovery for database services requires manual programming, which requires developers to master normal business logic and compensation processes at the same time. Automation cannot be achieved, which increases development difficulty and the probability of misoperation.
By parsing instructions when the target database executes predetermined instructions and generating recovery instructions, automatic recovery of data tables is achieved without manual programming, which reduces programmer requirements and development difficulty.
It realizes the automatic recovery of data tables, improves data recovery efficiency, reduces the development of compensation logic, reduces the probability of misoperation, and provides automatic recording of instruction operation logs to facilitate troubleshooting.
Smart Images

Figure CN113297220B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular, to a data recovery method, device, computer-readable storage medium, and processor. Background Art
[0002] As corporate business continues to grow, traditional technical architecture can no longer meet business needs. Most application systems use a distributed architecture, with data distributed across multiple databases. A complete user interaction requires operations across multiple databases.
[0003] In order to ensure the consistency of distributed transactions, a business compensation and recovery mechanism needs to be provided. Generally, developers are required to write different business logics for different business scenarios to implement compensation operations. This requires developers to not only master the normal business logic, but also be very familiar with the compensation process. It requires reprogramming and cannot be automated.
[0004] Therefore, there is an urgent need for a method that can automatically generate recovery data without requiring programmers to reprogram, so as to simplify the solution to data consistency in a distributed architecture.
[0005] The above information disclosed in the background technology section is only used to enhance the understanding of the background technology of the technology described in this article. Therefore, the background technology may contain certain information that does not form the prior art known in this country for those skilled in the art. Summary of the invention
[0006] The main purpose of the present application is to provide a data recovery method, device, computer-readable storage medium and processor to solve the problem that data recovery of database services in the prior art requires manual programming.
[0007] According to one aspect of an embodiment of the present invention, a data recovery method is provided, comprising: when a target database executes a predetermined instruction, parsing the predetermined instruction to obtain a name of a target data table and a target string, the target string including one-to-one corresponding target fields and target values, the target fields including at least corresponding fields in the predetermined instruction; upon receiving a recovery request to restore the target database to a state before the predetermined instruction, generating a recovery instruction corresponding to the predetermined instruction according to the predetermined instruction, the name of the target data table and the target string; and executing the recovery instruction to restore the data in the target database.
[0008] Optionally, the predetermined instruction is parsed to obtain the name of the target data table and the target character string, including: parsing the predetermined instruction to obtain the name of the target data table; acquiring the table structure of the target data table according to the name of the target data table; determining at least the field corresponding to the numerical value in the predetermined instruction as the target field according to the table structure and the predetermined instruction; determining the target numerical value corresponding to the target field according to the type of the predetermined instruction; and generating the target character string according to the target numerical value and the target field.
[0009] Optionally, determining the target value according to the type of the predetermined instruction includes: when the predetermined instruction is an insert instruction or a delete instruction, determining the target value to be a corresponding value in the predetermined instruction.
[0010] Optionally, in the case where the predetermined instruction is an update instruction, based on the table structure and the predetermined instruction, at least the field corresponding to the numerical value in the predetermined instruction is determined as the target field, including: based on the table structure, determining the corresponding primary key field and all non-primary key fields; determining the primary key field and all the non-primary key fields as the target field.
[0011] Optionally, in the case where the predetermined instruction is an update instruction, the target value corresponding to the target field is determined according to the type of the predetermined instruction, including: determining the target value corresponding to the non-primary key field as a record value in the target data table; determining a first target value corresponding to the primary key field, the first target value being a record value in the target data table, and generating the target string according to the target value and the target field, including: generating a first target string according to the primary key field and the first target value; generating a second target string according to the non-primary key field and the corresponding target value.
[0012] Optionally, in the case where the field modified in the update instruction includes the primary key field, determining the target value corresponding to the target field according to the type of the predetermined instruction, further includes: determining a second target value corresponding to the primary key field, wherein the second target value is a corresponding value in the update instruction, generating the target string according to the target value and the target field, and further includes: generating a third target string according to the target field and the second target value.
[0013] Optionally, the method further comprises: storing the name of the predetermined instruction, the name of the target data table and the target character string in a first auxiliary data table.
[0014] Optionally, the method further includes: generating an instruction number corresponding to the predetermined instruction when executing the predetermined instruction on the target database; and storing the instruction number in a second auxiliary data table.
[0015] Optionally, when a recovery request is received to restore the target database to the state before the predetermined instruction, a recovery instruction corresponding to the predetermined instruction is generated according to the predetermined instruction, the name of the target data table and the target character string, including: according to the recovery request, obtaining the corresponding instruction number from the second auxiliary data table; according to the instruction number, extracting the corresponding predetermined instruction, the name of the target data table and the target character string from the first auxiliary data table; generating the recovery instruction according to the predetermined instruction, the name of the target data table and the target character string.
[0016] Optionally, both the predetermined instruction and the recovery instruction are SQL instructions.
[0017] According to another aspect of an embodiment of the present invention, a data recovery device is also provided, including: a parsing unit, used to parse the predetermined instruction when the target database executes the predetermined instruction, and obtain the name of the target data table and the target string, the target string including one-to-one corresponding target fields and target values, and the target fields at least including the corresponding fields in the predetermined instruction; a first generating unit, used to generate a recovery instruction corresponding to the predetermined instruction according to the predetermined instruction, the name of the target data table and the target string when receiving a recovery request to restore the target database to a state before the predetermined instruction; and an execution unit, used to execute the recovery instruction to restore the data in the target database.
[0018] According to yet another aspect of the embodiments of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein the program executes any one of the methods described.
[0019] According to yet another aspect of an embodiment of the present invention, a processor is provided, wherein the processor is used to run a program, wherein any one of the methods is executed when the program is run.
[0020] In the embodiment of the present invention, in the above recovery method, when the target database executes the predetermined instruction, the predetermined instruction is parsed to obtain the name of the target data table and the target string corresponding to the predetermined instruction; then, when a recovery request is received, a recovery instruction is generated according to the predetermined instruction, the name of the target data table and the target string; finally, the recovery instruction is executed to restore the data in the target data table to the state before the predetermined instruction is executed. This method can realize the automatic recovery of data in the target data table without manual programming, reduces the requirements for programmers, and improves the efficiency of data recovery. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The drawings constituting part of the present application are used to provide a further understanding of the present application. The exemplary embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0022] Figure 1 A schematic diagram showing a flow chart of an embodiment of a method for recovering data according to the present application; and
[0023] Figure 2 A schematic diagram of a process flow of an embodiment of a device for recovering data according to the present application is shown. DETAILED DESCRIPTION
[0024] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0025] 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.
[0026] 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 sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. 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.
[0027] As mentioned in the background technology, data recovery of database services in the prior art requires manual programming. In order to solve the above problem, a typical implementation of the present application provides a data recovery method, device, computer-readable storage medium and processor.
[0028] According to an embodiment of the present application, a data recovery method is provided.
[0029] Figure 1 FIG. 1 is a flow chart of a method for recovering data according to an embodiment of the present application. Figure 1 As shown, the method comprises the following steps:
[0030] Step S101, when the target database executes the predetermined instruction, the predetermined instruction is parsed to obtain the name of the target data table and the target string, the target string includes a one-to-one corresponding target field and a target value, and the target field includes at least the corresponding field in the predetermined instruction;
[0031] Step S102, when a recovery request for restoring the target database to a state before the predetermined instruction is received, generating a recovery instruction corresponding to the predetermined instruction according to the predetermined instruction, the name of the target data table and the target character string;
[0032] Step S103: execute the recovery instruction to restore the data in the target database.
[0033] In the above recovery method, when the target database executes the predetermined instruction, the predetermined instruction is parsed to obtain the name of the target data table and the target string corresponding to the predetermined instruction; then, when a recovery request is received, a recovery instruction is generated according to the predetermined instruction, the name of the target data table and the target string; finally, the recovery instruction is executed to restore the data in the target data table to the state before the predetermined instruction is executed. This method can realize the automatic recovery of data in the target data table without manual programming, reduces the requirements for programmers, and improves the efficiency of data recovery.
[0034] In addition, the above method reduces unnecessary compensation logic development by developers, automatically generates database recovery instructions, reduces the probability of misoperation, reduces development difficulty, and improves development efficiency; for key database instruction operations, it provides the function of automatically recording instruction operation logs to facilitate problem troubleshooting. At the same time, this operation is equivalent to data logic backup to ensure data security; this solution is relatively independent and more general, suitable for more scenarios, such as daily system upgrades, for standard data deployment operations, there is no need to provide separate rollback SQL and other instruction statements.
[0035] In one embodiment of the present application, the predetermined instruction is parsed to obtain the name of the data table and the target string, including: parsing the predetermined instruction to obtain the name of the target data table; obtaining the table structure of the target data table according to the name of the target data table; determining at least the field corresponding to the numerical value in the predetermined instruction as the target field according to the table structure and the predetermined instruction; determining the target numerical value corresponding to the target field according to the type of the predetermined instruction; generating the target string according to the target numerical value and the target field. This method further ensures the accuracy of the obtained target string and the target data table, thereby further ensuring the accuracy of the generated recovery instruction, and further ensuring that the data of the target data table can be accurately restored to the state before the predetermined instruction is executed.
[0036] In a specific application, in an embodiment of the present application, the target value is determined according to the type of the predetermined instruction, including: when the predetermined instruction is an insert instruction (insert instruction) or a delete instruction (delete instruction), the target value is determined to be the corresponding value in the predetermined instruction. For an insert instruction, it is usually to insert a complete instruction, and the insert instruction includes a specific inserted value, and the restore instruction should delete the inserted data, that is, the corresponding deleted inserted value, so the target value is the corresponding value in the corresponding insert instruction. For a delete instruction, it is usually to delete a complete data, and the delete instruction includes a specific deleted value, and the restore instruction should reinsert the deleted data, that is, the corresponding inserted deleted value, so the target value is the corresponding value in the corresponding delete instruction.
[0037] In the actual application process, the predetermined instruction can not only be an insert instruction or a delete instruction, but also an update instruction. For the update instruction, it generally updates a value, so its implementation process is relatively complicated. In order to more accurately and efficiently restore the data corresponding to the update instruction, in an embodiment of the present application, when the predetermined instruction is an update instruction, according to the table structure and the predetermined instruction, at least the field corresponding to the value in the predetermined instruction is determined as the target field, including: according to the table structure, determining the corresponding primary key field and all non-primary key fields; determining the primary key field and all the non-primary key fields as the target field.
[0038] Of course, in the present application, for the case where the predetermined instruction is an update instruction, the process of determining the target value is not limited to using both the primary key field and the non-primary key field of the table structure of the target data table as the target fields, but the field corresponding to the corresponding update value in the update instruction can also be used as the target field. However, this method is more complicated than the method in the previous section in that the process of generating a recovery instruction and restoring data according to the recovery instruction is more complicated.
[0039] In another embodiment of the present application, when the predetermined instruction is an update instruction, the target value corresponding to the target field is determined according to the type of the predetermined instruction, including: determining the target value corresponding to the non-primary key field as the record value in the target data table; determining the first target value corresponding to the primary key field, the first target value being the record value in the target data table. Generating the target string according to the target value and the target field includes: generating a first target string according to the primary key field and the first target value; generating a second target string according to the non-primary key field and the corresponding target value. For the recovery process of the update instruction, it actually restores the data to the state before executing the update instruction. Therefore, the record values corresponding to each field in the target data table before the execution of the update instruction are used as the target values. In this way, these target values are used later, and the target data table can be restored to the state before the execution of the update instruction more efficiently, that is, the data in the target data table is restored to the previous record value.
[0040] In the case where the field modified in the update instruction includes the primary key field, the target value corresponding to the target field is determined according to the type of the predetermined instruction, and further includes: determining a second target value corresponding to the primary key field, wherein the second target value is the corresponding value in the update instruction, generating the target string according to the target value and the target field, and further includes: generating a third target string according to the target field and the second target value. In this way, in the case where the field modified in the update instruction includes the primary key field, the correspondence between the updated data and the original data can be determined by the value corresponding to the original primary key field and the corresponding value in the update instruction, thereby avoiding the problem that the record value in the original table and the value in the update instruction are difficult to correspond due to the update of the primary key field, and the data recovery is more difficult.
[0041] In order to recover data more efficiently and accurately, in one embodiment of the present application, the method further includes: storing the name of the predetermined instruction, the name of the target data table and the target string in a first auxiliary data table. The auxiliary data table can be queried later to obtain the corresponding information.
[0042] In another embodiment of the present application, the method further includes: when executing the predetermined instruction on the target database, generating an instruction number corresponding to the predetermined instruction; and storing the instruction number in a second auxiliary data table. In this method, the instructions are numbered and the corresponding instruction numbers are generated. When restoring data later, the corresponding predetermined instruction can be more efficiently found according to the instruction number, thereby further improving the efficiency of data recovery.
[0043] In order to restore data more efficiently and accurately, in an embodiment of the present application, when a recovery request to restore the target database to the state before the predetermined instruction is received, a recovery instruction corresponding to the predetermined instruction is generated according to the predetermined instruction, the name of the target data table, and the target string, including: according to the recovery request, obtaining the corresponding instruction number from the second auxiliary data table; according to the instruction number, extracting the corresponding predetermined instruction, the name of the target data table, and the target string from the first auxiliary data table; generating the recovery instruction according to the predetermined instruction, the name of the target data table, and the target string.
[0044] In another embodiment of the present application, the predetermined instruction and the recovery instruction are both SQL instructions, that is, the predetermined instruction and the recovery instruction are both SQL statements. Of course, in the actual application process, the recovery instruction and the predetermined instruction can also be other feasible statements in the prior art.
[0045] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0046] The embodiment of the present application also provides a data recovery device. It should be noted that the data recovery device of the embodiment of the present application can be used to execute the data recovery method provided by the embodiment of the present application. The data recovery device provided by the embodiment of the present application is introduced below.
[0047] Figure 2 Schematic diagram of a data recovery device according to an embodiment of the present application. Figure 2 As shown, the device comprises:
[0048] The parsing unit 10 is used to parse the predetermined instruction when the target database executes the predetermined instruction to obtain the name of the target data table and the target string, wherein the target string includes a one-to-one corresponding target field and a target value, and the target field includes at least a corresponding field in the predetermined instruction;
[0049] A first generating unit 20 is configured to generate a recovery instruction corresponding to the predetermined instruction according to the predetermined instruction, the name of the target data table and the target character string when receiving a recovery request to restore the target database to a state before the predetermined instruction;
[0050] The execution unit 30 is used to execute the recovery instruction to restore the data in the target database.
[0051] In the above-mentioned recovery device, when the target database executes the predetermined instruction, the parsing unit parses the predetermined instruction to obtain the name of the target data table and the target string corresponding to the predetermined instruction; when the first generating unit receives the recovery request, it generates the recovery instruction according to the predetermined instruction, the name of the target data table and the target string; the executing unit executes the recovery instruction to restore the data in the target data table to the state before the predetermined instruction is executed. The device can realize the automatic recovery of the data in the target data table without manual programming, which reduces the requirements for programmers and improves the efficiency of data recovery.
[0052] In one embodiment of the present application, the parsing unit includes: a parsing module, which is used to parse the predetermined instruction to obtain the name of the target data table; a first acquisition module, which is used to obtain the table structure of the target data table according to the name of the target data table; a first determination module, which is used to determine at least the field corresponding to the numerical value in the predetermined instruction as the target field according to the table structure and the predetermined instruction; a second determination module, which is used to determine the target numerical value corresponding to the target field according to the type of the predetermined instruction; and a generation module, which is used to generate the target string according to the target numerical value and the target field. The device further ensures the accuracy of the obtained target string and the target data table, thereby further ensuring the accuracy of the generated recovery instruction, and further ensuring that the data of the target data table can be accurately restored to the state before the predetermined instruction is executed.
[0053] In a specific application, in one embodiment of the present application, the second determination module is used to: when the predetermined instruction is an insert instruction (insert instruction) or a delete instruction (delete instruction), determine that the target value is the corresponding value in the predetermined instruction. For an insert instruction, it is usually to insert a complete instruction, and the insert instruction includes a specific inserted value, and the restore instruction should be to delete the inserted data, that is, to delete the inserted value, so the target value is the corresponding value in the corresponding insert instruction. For a delete instruction, it is usually to delete a complete data, and the delete instruction includes a specific deleted value, and the restore instruction should be to reinsert the deleted data, that is, to insert the deleted value, so the target value is the corresponding value in the corresponding delete instruction.
[0054] In the actual application process, the predetermined instruction can not only be an insert instruction or a delete instruction, but also an update instruction. For the update instruction, it generally updates a value, so its implementation process is relatively complicated. In order to more accurately and efficiently restore the data corresponding to the update instruction, in one embodiment of the present application, the first determination module is used to: when the predetermined instruction is an update instruction, determine the corresponding primary key field and all non-primary key fields according to the table structure; determine the primary key field and all the non-primary key fields as the target field.
[0055] Of course, in the present application, for the case where the predetermined instruction is an update instruction, the process of determining the target value is not limited to using both the primary key field and the non-primary key field of the table structure of the target data table as the target fields, but the field corresponding to the corresponding update value in the update instruction can also be used as the target field. However, this method is more complicated than the method in the previous section in that the process of generating a recovery instruction and restoring data according to the recovery instruction is more complicated.
[0056] In another embodiment of the present application, the second determination module is also used to: determine that the target value corresponding to the non-primary key field is the record value in the target data table; determine the first target value corresponding to the primary key field, the first target value is the record value in the target data table. The generation module is used to: generate a first target string according to the primary key field and the first target value; generate a second target string according to the non-primary key field and the corresponding target value. For the recovery process of the update instruction, it actually restores the data to the state before the update instruction is executed. Therefore, the record values corresponding to each field in the target data table before the execution of the update instruction are used as target values. In this way, these target values are used later, and the target data table can be restored to the state before the execution of the update instruction more efficiently, that is, the data in the target data table is restored to the previous record value.
[0057] In another embodiment of the present application, the second determination module is also used to: when the field modified in the update instruction includes the primary key field, determine the second target value corresponding to the primary key field, wherein the second target value is the corresponding value in the update instruction, generate the target string according to the target value and the target field, and also include: generating a third target string according to the target field and the second target value.
[0058] In order to recover data more efficiently and accurately, in one embodiment of the present application, the device further includes: a first storage unit, which is used to store the name of the predetermined instruction, the name of the target data table, and the target string in a first auxiliary data table. The corresponding information can be subsequently obtained by querying the auxiliary data table.
[0059] In another embodiment of the present application, the device further includes: a second generating unit, for generating an instruction number corresponding to the predetermined instruction when executing the predetermined instruction on the target database; and a second storage unit, for storing the instruction number in a second auxiliary data table. In the device, the instructions are numbered and the corresponding instruction numbers are generated, so that the corresponding predetermined instructions can be more efficiently found according to the instruction numbers when restoring data later, thereby further improving the efficiency of data recovery.
[0060] In order to restore data more efficiently and accurately, in an embodiment of the present application, the first generation unit includes: a second acquisition module, used to obtain the corresponding instruction number from the second auxiliary data table according to the recovery request; an extraction module, used to extract the corresponding predetermined instruction, the name of the target data table and the target character string from the first auxiliary data table according to the instruction number; a generation module, used to generate the recovery instruction according to the predetermined instruction, the name of the target data table and the target character string.
[0061] In another embodiment of the present application, the predetermined instruction and the recovery instruction are both SQL instructions, that is, the predetermined instruction and the recovery instruction are both SQL statements. Of course, in actual application, the recovery instruction and the predetermined instruction can also be other feasible statements in the prior art.
[0062] Example
[0063] In this embodiment, different processes are performed for different database SQL instructions.
[0064] When executing the insert command: parse the SQL command to obtain the table name (the table name of the target data table, the term has the same meaning and will not be explained further), obtain the table structure of the table through the table name, match the fields in the target data table with the values in the SQL command one by one, generate a record value string in the key and value format of "field = value", automatically generate a version number (command number, the same below, will not be explained further) and store it in the second auxiliary data table, and store the "insert", table name, and record value string in the "operation", "table name", and "record value" fields of the first auxiliary data table in the database respectively. When recovering, query the operation record through the version number, and automatically generate the recovery SQL: delete from table name where record value;
[0065] When executing the delete command: parse the SQL command to obtain the table name, obtain the table structure and corresponding values through the table name and the where condition in the delete command, match the fields with the values in the SQL command one by one, generate a record value string in the key and value format of "field = value", automatically generate a version number, and store "delete", table name, and record value string in the database's "operation", "table name", and "record value" fields respectively. When restoring, query the operation record through the version number, and automatically generate the recovery SQL: insert into table name values (record value);
[0066] When executing the update command: parse the SQL command to obtain the table name, obtain the primary key field of the table through the table name, and determine whether the field modified in the update contains the primary key field:
[0067] 1. If the primary key field is not included, obtain the value of the primary key field and the target data table before the update and all the record values modified by the update command through the table name and the where condition in the update command. Generate a string of the primary key field and its value and all the record values that will be modified in the form of "field = value" key and value, automatically generate a version number, and store "update", table name, primary key value string (first string) and record value string (second string) in the database's "operation", "table name", "original primary key value" and "record value" fields respectively. When restoring, query the operation record through the version number and automatically generate the recovery SQL: update table name set record value where original primary key value;
[0068] 2. If the primary key field is included, obtain it through the table name, the where condition in the update command, obtain the primary key field and the original value (the value before the update in the target data table), the primary key field and the new value modified in the update command, and all the record values modified by the update command, and generate a string in the key and value format of "field = value", automatically generate a version number, and store "update", table name, original primary key value string (first string), new primary key value string (third string) and record value string (second string) in the database "operation", "table name", "original primary key value", "new primary key value", "record value" 5 fields. When restoring, query the operation record through the version number, and automatically generate the recovery SQL: update table name set record value where new primary key value.
[0069] For delete and update instructions, after the instructions are parsed, the database will be queried based on the parsed where conditions to obtain the number of records that will be affected. If the number of records is 0, it means that there is no data that needs to be operated. The SQL instruction will not affect the database, so no recovery operation is involved, and all subsequent operations will not be executed.
[0070] The data recovery device includes a processor and a memory. The above-mentioned parsing unit, the first generating unit and the executing unit are all stored in the memory as program units. The processor executes the above-mentioned program units stored in the memory to realize corresponding functions.
[0071] The processor contains a kernel, which calls the corresponding program unit from the memory. One or more kernels can be set, and the problem of manual programming required for data recovery of database services can be solved by adjusting kernel parameters.
[0072] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0073] An embodiment of the present invention provides a storage medium on which a program is stored. When the program is executed by a processor, the data recovery method is implemented.
[0074] An embodiment of the present invention provides a processor, which is used to run a program, wherein the data recovery method is executed when the program is running.
[0075] An embodiment of the present invention provides a device, the device comprising a processor, a memory, and a program stored in the memory and executable on the processor, and when the processor executes the program, at least the following steps are implemented:
[0076] Step S101, when the target database executes the predetermined instruction, the predetermined instruction is parsed to obtain the name of the target data table and the target string, the target string includes a one-to-one corresponding target field and a target value, and the target field includes at least the corresponding field in the predetermined instruction;
[0077] Step S102, when a recovery request for restoring the target database to a state before the predetermined instruction is received, generating a recovery instruction corresponding to the predetermined instruction according to the predetermined instruction, the name of the target data table and the target character string;
[0078] Step S103: execute the recovery instruction to restore the data in the target database.
[0079] The devices in this article can be servers, PCs, PADs, mobile phones, etc.
[0080] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program for initializing at least the following method steps:
[0081] Step S101, when the target database executes the predetermined instruction, the predetermined instruction is parsed to obtain the name of the target data table and the target string, the target string includes a one-to-one corresponding target field and a target value, and the target field includes at least the corresponding field in the predetermined instruction;
[0082] Step S102, when a recovery request for restoring the target database to a state before the predetermined instruction is received, generating a recovery instruction corresponding to the predetermined instruction according to the predetermined instruction, the name of the target data table and the target character string;
[0083] Step S103, executing the recovery instruction to restore the data in the target database. In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For the part not described in detail in one embodiment, please refer to the relevant description of other embodiments.
[0084] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units 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, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0085] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0086] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0087] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, 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, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0088] From the above description, it can be seen that the above embodiments of the present application achieve the following technical effects:
[0089] 1) In the recovery method of the present application, when the target database executes the predetermined instruction, the predetermined instruction is parsed to obtain the name of the target data table and the target string corresponding to the predetermined instruction; then, when a recovery request is received, a recovery instruction is generated according to the predetermined instruction, the name of the target data table and the target string; finally, the recovery instruction is executed to restore the data in the target data table to the state before the predetermined instruction is executed. This method can realize the automatic recovery of the data in the target data table without manual programming, reduces the requirements for programmers, and improves the efficiency of data recovery.
[0090] 2) In the recovery device of the present application, when the target database executes the predetermined instruction, the parsing unit parses the predetermined instruction to obtain the name of the target data table and the target string corresponding to the predetermined instruction; when the first generating unit receives the recovery request, it generates the recovery instruction according to the predetermined instruction, the name of the target data table and the target string; the executing unit executes the recovery instruction to restore the data in the target data table to the state before the predetermined instruction is executed. The device can realize the automatic recovery of the data in the target data table without manual programming, which reduces the requirements for programmers and improves the efficiency of data recovery.
[0091] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A data recovery method, It is characterized in that include: When the target database executes the predetermined instruction, the predetermined instruction is parsed to obtain the name of the target data table and the target string, the target string includes a one-to-one corresponding target field and a target value, and the target field includes at least the corresponding field in the predetermined instruction; In case of receiving a recovery request to restore the target database to a state before the predetermined instruction, generating a recovery instruction corresponding to the predetermined instruction according to the predetermined instruction, the name of the target data table and the target character string; Executing the recovery instruction to restore the data in the target database; The predetermined instruction is parsed to obtain the name of the target data table and the target string, including: Parsing the predetermined instruction to obtain the name of the target data table; According to the name of the target data table, obtaining the table structure of the target data table; According to the table structure and the predetermined instruction, at least a field corresponding to a value in the predetermined instruction is determined as the target field; Determining the target value corresponding to the target field according to the type of the predetermined instruction; The target character string is generated according to the target value and the target field.
2. The method according to claim 1, It is characterized in that Determining the target value according to the type of the predetermined instruction includes: In the case that the predetermined instruction is an insert instruction or a delete instruction, the target value is determined to be a corresponding value in the predetermined instruction.
3. The method according to claim 1, It is characterized in that In the case where the predetermined instruction is an update instruction, determining at least the field corresponding to the value in the predetermined instruction as the target field according to the table structure and the predetermined instruction includes: According to the table structure, determine the corresponding primary key field and all non-primary key fields; The primary key field and all the non-primary key fields are determined as the target fields.
4. The method according to claim 3, It is characterized in that In the case where the predetermined instruction is an update instruction, determining the target value corresponding to the target field according to the type of the predetermined instruction includes: Determine that the target value corresponding to the non-primary key field is a record value in the target data table; Determine a first target value corresponding to the primary key field, the first target value being a record value in the target data table, Generating the target character string according to the target value and the target field includes: Generate a first target character string according to the primary key field and the first target value; A second target character string is generated according to the non-primary key field and the corresponding target value.
5. The method according to claim 4, It is characterized in that In the case where the fields modified in the update instruction include the primary key field, Determining the target value corresponding to the target field according to the type of the predetermined instruction further includes: Determine a second target value corresponding to the primary key field, wherein the second target value is a corresponding value in the update instruction, Generating the target character string according to the target value and the target field also includes: A third target character string is generated according to the target field and the second target value.
6. The method according to any one of claims 1 to 5, It is characterized in that The method further comprises: The name of the predetermined instruction, the name of the target data table, and the target character string are stored in a first auxiliary data table.
7. The method according to claim 6, It is characterized in that The method further comprises: When executing the predetermined instruction on the target database, generating an instruction number corresponding to the predetermined instruction; The instruction number is stored in a second auxiliary data table.
8. The method according to claim 7, It is characterized in that In case of receiving a recovery request to restore the target database to a state before the predetermined instruction, generating a recovery instruction corresponding to the predetermined instruction according to the predetermined instruction, the name of the target data table and the target character string, including: According to the recovery request, obtaining the corresponding instruction number from the second auxiliary data table; According to the instruction number, extracting the corresponding predetermined instruction, the name of the target data table and the target character string from the first auxiliary data table; The restoration instruction is generated according to the predetermined instruction, the name of the target data table and the target character string.
9. The method according to any one of claims 1 to 5, It is characterized in that The predetermined instruction and the recovery instruction are both SQL instructions.
10. A data recovery device, It is characterized in that include: A parsing unit, used for parsing the predetermined instruction when the target database executes the predetermined instruction, to obtain the name of the target data table and the target string, wherein the target string includes a one-to-one corresponding target field and a target value, and the target field includes at least a corresponding field in the predetermined instruction; A first generating unit is configured to generate a recovery instruction corresponding to the predetermined instruction according to the predetermined instruction, the name of the target data table and the target character string when receiving a recovery request to restore the target database to a state before the predetermined instruction; An execution unit, configured to execute the recovery instruction so as to restore the data in the target database; The parsing unit includes: a parsing module, a first acquisition module, a first determination module, a second determination module, and a generation module, wherein the parsing module is used to parse the predetermined instruction to obtain the name of the target data table; The first acquisition module is used to acquire the table structure of the target data table according to the name of the target data table; the first determination module is used to determine, based on the table structure and the predetermined instruction, at least the field corresponding to the numerical value in the predetermined instruction as the target field; the second determination module is used to determine the target numerical value corresponding to the target field according to the type of the predetermined instruction; the generation module is used to generate the target string according to the target numerical value and the target field.
11. A computer-readable storage medium, It is characterized in that The computer-readable storage medium includes a stored program, wherein the program executes the method of any one of claims 1 to 9.
12. A processor, It is characterized in that The processor is used to run a program, wherein the program executes the method according to any one of claims 1 to 9 when running.
