Data recovery method, apparatus and device, and computer program product
By obtaining database error operation information and transaction identifiers, the error operation data is restored, which solves the problem of long recovery time after database data corruption, and achieves fast and efficient data recovery.
Patent Information
- Application Number
- CN202410954137.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-11-08
AI Technical Summary
In the prior art, the recovery time is long after the database data is damaged, and data cannot be recovered quickly.
By obtaining the database error operation information, determining the transaction identifier, selecting matching transaction identifiers from historical operations, restoring the error operation data, and only recovering the data affected by the error operation, improving recovery efficiency.
It significantly shortens data recovery time, improves data recovery efficiency, and improves business continuity guarantee capabilities.
Smart Images

Figure CN118916213A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of database management, and in particular to a data recovery method, device, equipment and computer program product. Background Art
[0002] When a database is damaged due to an erroneous operation, how to quickly restore the data is an important issue facing current database management.
[0003] Currently, data is usually restored based on backup storage, which includes: before data damage occurs, a production environment identical to the database is set up in advance, and the same production environment includes an operating system and software versions that are consistent with the database; a backup disk is configured in the set up production environment to back up database data; when data recovery is required, all data in the complete backup file stored in the backup disk is restored to the database.
[0004] The above data recovery method requires a long recovery time because all data must be recovered. For example, when the database stores 10TB of data, it takes about 10 hours to recover the data at a 10 Gigabit network speed. Summary of the invention
[0005] The embodiments of the present application provide a data recovery method, device, equipment and computer program product to solve the problem of long recovery time after database data is damaged in the prior art.
[0006] The present application embodiment adopts the following technical solutions:
[0007] A data recovery method, comprising:
[0008] Obtaining operation information of a first erroneous operation on a database;
[0009] According to the operation information, from among the pre-generated transaction identifiers, a transaction identifier matching the operation information is determined as a target identifier; a single transaction identifier is generated based on the operation information of a single transaction that performs a series of operations on the database;
[0010] According to the target identifier, selecting, from the recorded historical operations on the database, a historical operation with the target identifier as the transaction identifier of the transaction to which it belongs as a second erroneous operation;
[0011] Based on the operation type of the second erroneous operation, data in the database operated by the second erroneous operation is restored.
[0012] A data recovery method, comprising:
[0013] Acquire incremental data operations of a database, and store the incremental data operations to form historical operations;
[0014] Obtaining operation information of a first erroneous operation on a database;
[0015] According to the operation information, from among the pre-generated transaction identifiers, a transaction identifier matching the operation information is determined as a target identifier; a single transaction identifier is generated based on the operation information of a single transaction that performs a series of operations on the database;
[0016] According to the target identifier, selecting, from the recorded historical operations on the database, a historical operation with the target identifier as the transaction identifier of the transaction to which it belongs as a second erroneous operation;
[0017] Based on the operation type of the second erroneous operation, data in the database operated by the second erroneous operation is restored.
[0018] A data recovery device, comprising:
[0019] An operation information acquisition unit, used to acquire operation information of a first erroneous operation on a database;
[0020] a target identifier determination unit, configured to determine, according to the operation information, from among the pre-generated transaction identifiers, a transaction identifier that matches the operation information as a target identifier; a single transaction identifier is generated based on the operation information of performing a series of operations on the database contained in a single transaction;
[0021] an erroneous operation selecting unit, which selects, according to the target identifier, a historical operation with the target identifier as a transaction identifier of a corresponding transaction from the recorded historical operations on the database as a second erroneous operation;
[0022] The data recovery unit recovers the data in the database operated by the second erroneous operation based on the operation type of the second erroneous operation.
[0023] A data recovery device, comprising:
[0024] An incremental data operation acquisition unit, used to acquire incremental data operations of a database, and store the incremental data operations to form historical operations;
[0025] An operation information acquisition unit, used to acquire operation information of a first erroneous operation on a database;
[0026] a target identifier determination unit, configured to determine, according to the operation information, from among the pre-generated transaction identifiers, a transaction identifier that matches the operation information as a target identifier; a single transaction identifier is generated based on the operation information of performing a series of operations on the database contained in a single transaction;
[0027] an erroneous operation selecting unit, which selects, according to the target identifier, a historical operation with the target identifier as a transaction identifier of a corresponding transaction from the recorded historical operations on the database as a second erroneous operation;
[0028] The data recovery unit recovers the data in the database operated by the second erroneous operation based on the operation type of the second erroneous operation.
[0029] A computing device, comprising: a memory and a processor, wherein:
[0030] The memory is used to store computer programs;
[0031] The processor is coupled to the memory and is used to execute the computer program stored in the memory to perform the above method.
[0032] A computer-readable storage medium storing a computer program, wherein the computer program can implement the above method when executed by a computer.
[0033] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:
[0034] Based on the operation information of the first erroneous operation of the database, a transaction identifier corresponding to the erroneous operation is determined. Since the transaction identifier is generated based on the operation information of a series of operations performed on the database contained in the transaction, each operation information corresponding to the series of operations contains the same transaction identifier. Based on the transaction identifier, all operations corresponding to the current transaction identifier, that is, the second erroneous operation, can be found from the historical operations on the database. Corresponding recovery is performed based on the data operated on by the second erroneous operation. Since only the data corresponding to the erroneous operation is specifically recovered, the data recovery efficiency is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0036] Figure 1 A specific implementation flow chart of a data recovery method provided in Example 1 of the present application;
[0037] Figure 2is an example diagram of operation information of historical operations filtered out based on the operation information of the first erroneous operation;
[0038] Figure 3 is an example diagram of operation information of a second erroneous operation screened out based on the target identifier;
[0039] Figure 4 A schematic diagram of a specific process of a data recovery method provided in Embodiment 2 of the present application;
[0040] Figure 5 A schematic diagram of the specific structure of a data recovery device provided in Embodiment 3 of the present application;
[0041] Figure 6 A schematic diagram of the specific structure of a data recovery device provided in Embodiment 4 of the present application;
[0042] Figure 7 A schematic diagram of the specific structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. 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 making creative work are within the scope of protection of the present application.
[0044] Those skilled in the art may appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0045] 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 need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0046] In order to solve the problem in the prior art that it takes a long time to recover database data after the data is damaged, a first embodiment of the present application provides a method for recovering data.
[0047] The executor of the method may be any computing device that can implement the method, such as a server, a mobile phone, a personal computer, a smart wearable device, a smart robot, and the like.
[0048] In addition, the execution order of different steps is not limited in the embodiment of the present application. When using the method provided in the embodiment of the present application, the execution order of different steps can be adjusted according to actual needs.
[0049] For ease of description, the method provided in the embodiment of the present application is described in detail below by taking a data recovery device as the execution subject of the method as an example.
[0050] like Figure 1 As shown, it is a specific implementation flow chart of a data recovery method provided in an embodiment of the present application, including the following steps 11 to 14:
[0051] Step 11: Obtain operation information of a first erroneous operation on the database.
[0052] Operation refers to adding, deleting, modifying and querying data in the database. Misoperation is usually determined based on the current state of the data in the database (e.g., whether it exists in the database) and / or the value of the data.
[0053] For example, if it is found that the value of the data in a table in the database (such as the table name table_user) is wrong, or the table cannot be found in the entire database, it is considered that an error has occurred. In addition, when it is found that the value of the data in a table in the database is wrong, it can be inferred that an incorrect modification operation has been performed on the data; when it is found that the table cannot be found in the entire database, it can be inferred that an incorrect deletion operation has been performed on the table.
[0054] Based on the determined erroneous operation, operation information of the erroneous operation is further determined, such as the table name operated by the erroneous operation, the operation type, and the occurrence time of the erroneous operation, etc. The operation type includes an add (or write) operation, a modify operation, and a delete operation.
[0055] It should be noted that the above-mentioned erroneous operation determined usually cannot include all erroneous operations. For the convenience of distinction, the erroneous operation determined in this step is referred to as the first erroneous operation. The above-mentioned first erroneous operation determined usually does not include all erroneous operations. The reason is that: after the data operator performs operations such as adding / deleting / changing data, it is necessary to click a transaction button, such as buttons such as "Save", "Withdraw", etc. The operation of adding / deleting / changing data by the operator can be uploaded to the database system to take effect, so the erroneous operation is formed after clicking the transaction button. Moreover, the operator's one click on the transaction button usually makes multiple operations take effect. Therefore, the above-mentioned first erroneous operation determined usually cannot include all erroneous operations.
[0056] It should also be noted that the operation information of the first erroneous operation does not necessarily include all the operation information of the erroneous operation. Usually, the operation information of an operation includes at least the data before and after the operation in addition to the operation time, the name of the table operated, and the operation type; and the erroneous operation is determined based on the current state and / or value of the data in the database, that is, only the data after the operation is executed can be obtained, so the operation information of the first erroneous operation usually does not include all the operation information of the erroneous operation.
[0057] Step 12: According to the operation information, determine, from among the pre-generated transaction identifiers, a transaction identifier that matches the operation information as a target identifier.
[0058] The single transaction identifier is generated based on the operation information of a series of operations performed on the database contained in a single transaction.
[0059] Transaction ID, also known as the database transaction identifier TID (Transaction Identifier). In the computer field, a transaction is a logical unit consisting of a series of operations (or, a transaction is an operation sequence), that is, each database transaction contains at least one operation performed on the database data; the transaction ID is used as a unique identifier of the transaction to distinguish different transactions. The transaction ID is generated when the transaction occurs, such as clicking the "Save" button, and the unique transaction ID of the "Save" transaction is generated immediately.
[0060] In one implementation, according to the operation information, from among various pre-generated transaction identifiers, determining a transaction identifier that matches the operation information as a target identifier specifically includes the following steps 121 to 122:
[0061] Step 121 : based on the operation information of the first erroneous operation, filter the operation information of each historical operation that matches the operation information of the first erroneous operation from the operation information of the historical operations recorded in the database.
[0062] The operation information of historical operations is generated when the database generates incremental data, that is, when data changes occur. The operation information of historical operations records the operation time, operation type, name of the table operated, the value of the operated data before and after the operation, the location of the operated data in the table, and the transaction ID of the transaction to which the operation belongs. Usually, one operation corresponds to one operation record.
[0063] In a feasible implementation, the operation information of historical operations is stored in the cache of incremental data operations. Only the incremental data operations in historical operations are stored, such as the add operation, modify operation, and delete operation on data. Since the query operation does not cause a change in the data value in the database, it can be not recorded in the historical operation information. In this way, when screening historical operations that match the first incorrect operation from the operation information of historical operations, the screening time can be reduced and the screening efficiency can be improved.
[0064] In another feasible implementation, the operation information of historical operations is stored in a distributed message queue system in the form of incremental data messages.
[0065] The distributed message queue system can be a Kafka cluster. The operation information of historical operations is stored in the Kafka cluster in the form of incremental data messages. The specific implementation process includes:
[0066] When there is a data change in the database, a corresponding incremental data message is generated, and the message of the data change is pushed to Kafka, so that the incremental data message is stored in Kafka.
[0067] Data changes include three scenarios: addition, modification, and deletion. Three corresponding messages are generated respectively, as shown in the following example:
[0068] Message 1: {"meta": {"table": "table_user", "TID": "2031": "I"}, "databefore": {}, "datanew": {"id": 1, "name": "Zhang San", "age": "18"}, "pkey": {"id"}};
[0069] Message 2: {"meta": {"table": "table_user", "TID": "2032": "D"}, "databefore": {}, "datanew": {"id": 1, "name": "Zhang San", "age": "18"}, "datanew": {}, "pkey": {"id"}};
[0070] Message 3: {"meta": {"table": "table_user", "TID": "2033": "U"}, "databefore": {"id": 1, "name": "Zhang San", "age": "18"}, "datanew": {"id": 1, "name": "Li Si", "age": "18"}, "pkey": {"id"}}.
[0071] In the above messages, message 1 indicates adding a new piece of data: "Zhang San, 18 years old", with primary key id = 1; message 2 indicates deleting the data with primary key 1; message 3 indicates modifying the data: changing the name from Zhang San to Li Si.
[0072] In addition, in the above message, "TID" represents the transaction identifier; "type" represents the operation type, specifically: "I" represents a new operation, "U" represents a modification operation, and "D" represents a deletion operation; "dataBefore" represents the data before the modification; "dataNew" represents the data after the modification; and "pKey" represents the primary key field.
[0073] According to the operation information determined in step 11, each historical operation information related to the first erroneous operation is filtered from the historical operation records. The table name, operation type, and operation occurrence time in the operation information can be used as filtering conditions to filter the relevant historical operation information from the historical operation records.
[0074] like Figure 2 As shown, taking the storage of operation information of historical operations in the form of incremental data messages as an example, based on the operation information, the operation information of the historical operations corresponding to the part outlined by the rectangular box in the figure is filtered out.
[0075] Step 122: determine the transaction identifier contained in the operation information of each historical operation as the target identifier.
[0076] A transaction identifier is obtained from the operation information of each historical operation screened out in step 121, and the transaction identifier is determined as a target identifier that matches the first erroneous operation.
[0077] based on Figure 2 In the operation information of the filtered historical operations in the example, the transaction number "TID": "2035" can be obtained.
[0078] Step 13: According to the target identifier, select a historical operation corresponding to the target identifier from the historical operation records of the database as a second erroneous operation.
[0079] Since the transaction identifier of the transaction to which the operation belongs is stored in the operation record of the historical operation, based on the target identifier, all operations matching the target identifier are screened out from the historical operation record as the second erroneous operation.
[0080] like Figure 3 As shown, based on the target identifier (stored in the form of incremental data message), the operation information of the second erroneous operation is screened out. It should be noted that the above Figure 2 and Figure 3 The examples given are just examples. In actual situations, Figure 3The number of pieces of operation information corresponding to the second erroneous operation is usually greater than Figure 2 The number of corresponding operation information filtered out should be large.
[0081] Step 14: based on the operation type of the second erroneous operation, restore the data in the database operated by the second erroneous operation.
[0082] Based on the operation type of the second erroneous operation and the database data before and after the operation stored in the operation information of the second erroneous operation, a corresponding recovery script is generated to correspondingly recover the data in the database operated by the second erroneous operation.
[0083] If the operation type of the second erroneous operation is "add", a corresponding "delete" script is generated; if the operation type of the second erroneous operation is "delete", a corresponding "add" script is generated; if the second erroneous operation is "modify", a corresponding "modify" script is generated to restore the data before the modification.
[0084] For example:
[0085] The operation type of the second erroneous operation is "add", and the corresponding erroneous operation message is:
[0086] {"meta":{"table":"table_user","TID":"2031":"I"},
[0087] "databefore":{},"datanew":{"id":1,"name":"Zhang San","age":"18"},"pkey":{"id"}};
[0088] To restore the data, a statement for deleting the data is generated according to the primary key value (id). The corresponding "delete" script statement may be: Delete from table_user where id=1.
[0089] The operation type of the second erroneous operation is "delete", and the corresponding erroneous operation message is:
[0090] {"meta": {"table": "table_user", "TID": "2032": "D"}, "databefore": {}, "datanew": {"id": 1, "name": "Zhang San", "age": "18"}, "datanew": {}, "pkey": {"id"}};
[0091] To restore the data, according to the content of "databefore" before deletion, the deleted data is added back to the database. The corresponding "insert" script statement can be: insert into table_user(id,name,age)values(1,"张三",18).
[0092] The operation type of the second misoperation is "modification", and the corresponding misoperation message is:
[0093] {"meta":{"table":"table_user","TID":"2033":"U"},"databefore":{"id":1,"name":"张三","age":"18"},"datanew":{"id":1,"name":"李四","age":"18"},"pkey":{"id"}};
[0094] To restore the data, according to the primary key id value and the content of "databefore" in the message, modify the modified "name = 李四" to "name = 张三". The corresponding "update" script statement can be: update table_user set name = "张三" where id = 1.
[0095] Based on the operation information of the first misoperation of the database in this embodiment, the transaction identifier corresponding to the misoperation is determined. Since the transaction identifier is generated based on the operation information of a series of operations performed on the database by the transaction, each operation information corresponding to the series of operations contains the same transaction identifier; based on this transaction identifier, all operations corresponding to the current transaction identifier can be found from the historical operations on the database, that is, the second misoperation. The corresponding restoration is performed based on the data operated by the second misoperation. Since only the data corresponding to the misoperation is specifically restored, the data restoration efficiency is improved.
[0096] To solve the problem of long restoration time after the database data is damaged in the prior art, Embodiment 2 of this application provides a data restoration method.
[0097] The execution subject of this method can be any computing device that can implement this method, such as a server, a mobile phone, a personal computer, a smart wearable device, a smart robot, and so on.
[0098] In addition, this application embodiment does not limit the execution order of different steps. When using the method provided by this application embodiment, the execution order of different steps can be adjusted according to actual needs.
[0099] For ease of description, the method provided in the embodiment of the present application is described in detail below by taking a data recovery device as the execution subject of the method as an example.
[0100] like Figure 4 As shown, it is a specific implementation flow chart of a data recovery method provided in an embodiment of the present application, including the following steps 41 to 45:
[0101] Step 41, obtaining incremental data operations of the database, and storing the incremental data operations to form historical operations.
[0102] The incremental data operations of the database are obtained by asynchronously reading the database logical log. The incremental data operations are stored to form historical operations, which can be pushed to Kafka to completely retain the database change track. After the data is destroyed, the deleted or modified data can be retrieved from the Kafka cache.
[0103] When storing historical operations, this step also stores the operation information of the historical operations, namely, the operation time, the name of the table operated, the operation type, the value of the operated data before and after the operation, the location of the operated data in the table, and the transaction identifier of the transaction to which the operation belongs.
[0104] Step 42: Obtain operation information of the first erroneous operation on the database.
[0105] Misoperation and its operation information are usually discovered or analyzed manually and then input into the data recovery device.
[0106] For example, if it is found that the value of the data in a table in the database (such as the table name table_user) is wrong, or the table cannot be found in the entire database, it is considered that an error has occurred. In addition, when it is found that the value of the data in a table in the database is wrong, it can be inferred that an incorrect modification operation has been performed on the data; when it is found that the table cannot be found in the entire database, it can be inferred that an incorrect deletion operation has been performed on the table.
[0107] Based on the determined erroneous operation, operation information of the erroneous operation is further determined, such as the table name operated by the erroneous operation, the operation type, and the occurrence time of the erroneous operation, etc. The operation type includes an add (or write) operation, a modify operation, and a delete operation.
[0108] Step 43, according to the operation information, determine the transaction identifier that matches the operation information from the pre-generated transaction identifiers as the target identifier; a single transaction identifier is generated based on the operation information of a single transaction that performs a series of operations on the database.
[0109] The specific implementation of this step may be: based on the operation information of the first erroneous operation, filtering the operation information of each historical operation that matches the operation information of the first erroneous operation from the operation information of the historical operations recorded on the database; and determining the transaction identifier contained in the operation information of each historical operation as the target identifier.
[0110] Operation information of historical operations can be stored in the cache of incremental data operations.
[0111] The operation information of historical operations can also be stored in the distributed message queue system in the form of incremental data messages.
[0112] Step 44: According to the target identifier, select, from the recorded historical operations on the database, a historical operation with the target identifier as the transaction identifier of the transaction to which it belongs as the second erroneous operation.
[0113] Among them, historical operations are incremental data operations performed on the database.
[0114] Step 45: based on the operation type of the second erroneous operation, restore the data in the database operated by the second erroneous operation.
[0115] Based on the operation type of the second erroneous operation and the database data before and after the operation stored in the operation information of the second erroneous operation, the data in the database operated by the second erroneous operation is restored.
[0116] This embodiment determines the transaction identifier corresponding to the erroneous operation based on the operation information of the first erroneous operation of the database. Since the transaction identifier is generated based on the operation information of a series of operations performed on the database contained in the transaction, each operation information corresponding to the series of operations contains the same transaction identifier; based on the transaction identifier, all operations corresponding to the current transaction identifier can be found from the historical operations on the database, that is, the second erroneous operation, and corresponding recovery is performed based on the data operated by the second erroneous operation. Since only the data corresponding to the erroneous operation is targeted for data recovery, the data recovery efficiency is improved. In addition, according to testing, when the method of this embodiment is used to recover data, the time required is tens of minutes. Compared with the several hours required by the prior art, the method of this application can significantly improve the data recovery efficiency and improve the business continuity guarantee capability.
[0117] In order to solve the problem of long recovery time after database data is destroyed in the prior art, based on the same inventive concept as the above-mentioned embodiment 1 of the present application, embodiment 3 of the present application provides a data recovery device.
[0118] The specific structural diagram of the device is shown in Figure 5 As shown, it includes the following functional units 51-54:
[0119] The operation information acquisition unit 51 is used to acquire operation information of a first erroneous operation on the database.
[0120] The target identifier determination unit 52 is used to determine, according to the operation information, a transaction identifier that matches the operation information from pre-generated transaction identifiers as the target identifier; a single transaction identifier is generated based on the operation information of a single transaction that performs a series of operations on the database.
[0121] The erroneous operation selecting unit 53 selects, according to the target identifier, a historical operation with the target identifier as the transaction identifier of the transaction to which it belongs from the recorded historical operations on the database as a second erroneous operation.
[0122] The data recovery unit 54 recovers the data in the database operated by the second erroneous operation based on the operation type of the second erroneous operation.
[0123] Among them, the target identifier determination unit 52 is specifically used to: according to the operation information of the first erroneous operation, filter the operation information of each historical operation that matches the operation information of the first erroneous operation from the operation information of the historical operations recorded on the database; the operation information of the historical operation includes the transaction identifier of the transaction to which the operation belongs; and determine the transaction identifier contained in the operation information of each historical operation as the target identifier.
[0124] The data recovery unit 54 is specifically used to recover the data in the database operated by the second erroneous operation based on the operation type of the second erroneous operation and the database data before and after the operation stored in the operation information of the second erroneous operation.
[0125] The data recovery device provided in this embodiment determines the transaction identifier corresponding to the erroneous operation based on the operation information of the first erroneous operation of the database. Since the transaction identifier is generated based on the operation information of a series of operations performed on the database contained in the transaction, each operation information corresponding to the series of operations contains the same transaction identifier. Based on the transaction identifier, all operations corresponding to the current transaction identifier, that is, the second erroneous operation, can be found from the historical operations on the database. Corresponding recovery is performed based on the data operated by the second erroneous operation. Since only the data corresponding to the erroneous operation is specifically recovered, the data recovery efficiency is improved.
[0126] In order to solve the problem of long recovery time after database data is destroyed in the prior art, based on the same inventive concept as the above-mentioned embodiment 2 of the present application, embodiment 4 of the present application provides a data recovery device.
[0127] The specific structural diagram of the device is shown in Figure 6 As shown, it includes the following functional units 61-65:
[0128] The incremental data operation acquisition unit 61 is used to acquire the incremental data operations of the database and store the incremental data operations to form historical operations.
[0129] The operation information acquisition unit 62 is used to acquire operation information of a first erroneous operation on the database.
[0130] The target identifier determination unit 63 is used to determine, according to the operation information, a transaction identifier that matches the operation information from the pre-generated transaction identifiers as the target identifier; a single transaction identifier is generated based on the operation information contained in a single transaction that performs a series of operations on the database.
[0131] The target identifier determination unit 63 is specifically used to filter, based on the operation information of the first erroneous operation, the operation information of each historical operation that matches the operation information of the first erroneous operation from the operation information of the historical operations recorded on the database; the operation information of the historical operations includes the transaction identifier of the transaction to which the operation belongs; and the transaction identifier contained in the operation information of each historical operation is determined as the target identifier.
[0132] The erroneous operation selecting unit 64 selects, according to the target identifier, a historical operation with the target identifier as the transaction identifier of the transaction to which it belongs from the recorded historical operations on the database as a second erroneous operation.
[0133] The data recovery unit 65 recovers the data in the database operated by the second erroneous operation based on the operation type of the second erroneous operation.
[0134] The data recovery unit 65 is specifically used to recover the data in the database operated by the second erroneous operation based on the operation type of the second erroneous operation and the database data before and after the operation stored in the operation information of the second erroneous operation.
[0135] The data recovery device provided in this embodiment determines the transaction identifier corresponding to the erroneous operation based on the operation information of the first erroneous operation of the database. Since the transaction identifier is generated based on the operation information of a series of operations performed on the database contained in the transaction, each operation information corresponding to the series of operations contains the same transaction identifier. Based on the transaction identifier, all operations corresponding to the current transaction identifier, that is, the second erroneous operation, can be found from the historical operations on the database. Corresponding recovery is performed based on the data operated by the second erroneous operation. Since only the data corresponding to the erroneous operation is specifically recovered, the data recovery efficiency is improved.
[0136] Based on the same inventive concept as the aforementioned embodiments of the present application, the embodiments of the present application also provide a computing device.
[0137] like Figure 7 As shown, the computing device includes: a memory 71 and a processor 72. The memory 71 can be configured to store various other data to support operations on the electronic device. Examples of these data include instructions for any application or method for operating on the electronic device. The memory 71 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk or an optical disk.
[0138] The processor 72 is coupled to the memory 71 and is used to execute the computer program stored in the memory 71 to execute a data recovery method described in the above embodiment.
[0139] When the processor 72 executes the computer program, the transaction identifier corresponding to the erroneous operation is determined based on the operation information of the first erroneous operation of the database. Since the transaction identifier is generated based on the operation information of a series of operations performed on the database contained in the transaction, each operation information corresponding to the series of operations contains the same transaction identifier. Based on the transaction identifier, all operations corresponding to the current transaction identifier, that is, the second erroneous operation, can be found from the historical operations on the database, and corresponding recovery is performed based on the data operated on by the second erroneous operation. Since only the data corresponding to the erroneous operation is recovered in a targeted manner, the data recovery efficiency is improved.
[0140] When the processor 72 executes the computer program in the memory 71, in addition to the above functions, it can also realize other functions, and the details can be found in the description of the previous embodiments.
[0141] Further, such as Figure 7 As shown, the computing device also includes: a display 74, a communication component 73, a power component 75, an audio component 76 and other components. Figure 7 Only some components are shown schematically, and it does not mean that the computing device only includes Figure 7 Components shown.
[0142] Accordingly, an embodiment of the present application further provides a computer-readable storage medium storing a computer program, and when the computer program is executed by a computer, the methods provided in the above embodiments can be implemented.
[0143] An embodiment of the present application also provides a computer program product, including a computer program, which implements the methods provided in the above embodiments when executed by a processor.
[0144] The computer program product includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a processor, the methods provided in the above embodiments are implemented.
[0145] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0146] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0147] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A data recovery method, characterized in that: include: Obtaining operation information of a first erroneous operation on a database; According to the operation information, determining a transaction identifier that matches the operation information from pre-generated transaction identifiers as a target identifier; A single transaction identifier, generated based on operation information of a series of operations performed on the database contained in a single transaction; According to the target identifier, selecting, from the recorded historical operations on the database, a historical operation with the target identifier as the transaction identifier of the transaction to which it belongs as a second erroneous operation; Based on the operation type of the second erroneous operation, data in the database operated by the second erroneous operation is restored.
2. The method according to claim 1, characterized in that According to the operation information, determining a transaction identifier that matches the operation information from pre-generated transaction identifiers as a target identifier includes: According to the operation information of the first erroneous operation, the operation information of each historical operation matching the operation information of the first erroneous operation is selected from the operation information of the historical operations recorded on the database; the operation information of the historical operation includes the transaction identifier of the transaction to which the operation belongs; The transaction identifier included in the operation information of each historical operation is determined as the target identifier.
3. The method according to claim 2, characterized in that The operation information of the historical operation is stored in the cache of the incremental data operation.
4. The method according to claim 2, characterized in that The operation information of the historical operation is stored in the distributed message queue system in the form of incremental data messages.
5. The method according to claim 2, characterized in that The recovering the data in the database operated by the second erroneous operation based on the operation type of the second erroneous operation includes: Based on the operation type of the second erroneous operation and the database data before and after the operation stored in the operation information of the second erroneous operation, the data in the database operated by the second erroneous operation is restored.
6. The method according to claim 1, characterized in that The historical operation is an incremental data operation performed on the database.
7. A data recovery method, characterized in that: include: Acquire incremental data operations of a database, and store the incremental data operations to form historical operations; Obtaining operation information of a first erroneous operation on a database; According to the operation information, determining a transaction identifier that matches the operation information from pre-generated transaction identifiers as a target identifier; A single transaction identifier, generated based on operation information of a series of operations performed on the database contained in a single transaction; According to the target identifier, selecting, from the recorded historical operations on the database, a historical operation with the target identifier as the transaction identifier of the transaction to which it belongs as a second erroneous operation; Based on the operation type of the second erroneous operation, data in the database operated by the second erroneous operation is restored.
8. A data recovery device, characterized in that: include: An operation information acquisition unit, used to acquire operation information of a first erroneous operation on a database; a target identifier determining unit, configured to determine, according to the operation information, from among the pre-generated transaction identifiers, a transaction identifier that matches the operation information as a target identifier; A single transaction identifier, generated based on operation information of a series of operations performed on the database contained in a single transaction; an erroneous operation selecting unit, which selects, according to the target identifier, a historical operation with the target identifier as a transaction identifier of a corresponding transaction from the recorded historical operations on the database as a second erroneous operation; The data recovery unit recovers the data in the database operated by the second erroneous operation based on the operation type of the second erroneous operation.
9. A data recovery device, characterized in that: include: An incremental data operation acquisition unit, used to acquire incremental data operations of a database, and store the incremental data operations to form historical operations; An operation information acquisition unit, used to acquire operation information of a first erroneous operation on a database; a target identifier determining unit, configured to determine, according to the operation information, from among the pre-generated transaction identifiers, a transaction identifier that matches the operation information as a target identifier; A single transaction identifier, generated based on operation information of a series of operations performed on the database contained in a single transaction; an erroneous operation selecting unit, which selects, according to the target identifier, a historical operation with the target identifier as a transaction identifier of a corresponding transaction from the recorded historical operations on the database as a second erroneous operation; The data recovery unit recovers the data in the database operated by the second erroneous operation based on the operation type of the second erroneous operation.
10. A computing device, characterized in that: include: Memory and processor, wherein: The memory is used to store computer programs; The processor is coupled to the memory and is used to execute the computer program stored in the memory to execute the method according to any one of claims 1 to 7.
11. A computer-readable storage medium storing a computer program, wherein the computer program can implement the method according to any one of claims 1 to 7 when executed by a computer.
12. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 7 when executed by a processor.
Citation Information
Patent Citations
Data recovery method and device, computer equipment and storage medium
CN110781036A
Backup method and device for MongoDB database, recovery method and device for MongoDB database, electronic equipment and storage medium
CN111488243A
Recovery method, recovery system and recovery program for distributed database
JP2006350411A
