Database rollback method and device, medium and program product
By recording the data status corresponding to database operation commands and generating reverse operation commands, the accuracy and reliability issues of the database rollback mechanism are solved, enabling efficient data recovery and unified management in a multi-database environment.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-30
- Publication Date
- 2026-03-17
AI Technical Summary
Existing database rollback mechanisms suffer from issues of low accuracy, reliability, and efficiency, especially in the event of erroneous operations during maintenance, making it difficult to quickly locate and accurately recover from such errors.
By recording the data status corresponding to the operation instructions and performing a rollback operation according to the specific instructions specified to trigger the rollback, a reverse operation instruction is generated and executed to achieve precise location of the target database and data rollback.
It improves the accuracy, reliability, and efficiency of database rollback, reduces operational risks, enhances operational efficiency, and supports unified management and traceability in multi-database environments.
Smart Images

Figure CN121681237A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data management technology, and more specifically, to a database rollback method, device, medium, and program product. Background Technology
[0002] In daily database operations and maintenance, operations and maintenance personnel may perform operations such as data modification, deletion, or table structure adjustment.
[0003] Operational errors during maintenance often result in data loss or business interruption. Traditional solutions rely on the database's built-in backup and recovery mechanisms or involve manually writing and executing rollback scripts to restore data. However, recovery mechanisms based on regular backups are coarse-grained and cannot accurately pinpoint and recover from erroneous operations. Secondly, manually writing rollback scripts requires advanced skills, is prone to errors, and is inefficient.
[0004] In summary, existing database rollback mechanisms suffer from issues of low accuracy, reliability, and efficiency. Summary of the Invention
[0005] The purpose of this application is to provide a database rollback method, device, medium, and program product to improve the accuracy, reliability, and efficiency of database rollback.
[0006] In a first aspect, embodiments of this application provide a database rollback method, including: In response to a user-triggered rollback request, determine the target operation instruction specified in the rollback request; Obtain data status backup information corresponding to the target operation instruction; wherein, the data status backup information is recorded and backed up before the target operation instruction takes effect; Based on the data status backup information, perform data rollback processing on the target database.
[0007] In this embodiment, by backing up the data state at the instruction level and accurately locating and rolling back the target instruction when a rollback is triggered, the accuracy, reliability, and efficiency of database rollback are effectively improved.
[0008] In some embodiments, the data rollback process for the target database based on the data status backup information includes: Generate a reverse operation instruction corresponding to the data status backup information, and execute the reverse operation instruction to perform data rollback processing on the target database.
[0009] In this embodiment of the application, the reliability of data rollback is further improved by generating reverse operation instructions for rollback.
[0010] In some embodiments, generating a reverse operation instruction corresponding to the data state backup information and executing the reverse operation instruction to perform data rollback processing on the target database includes: Acquire at least one historical operation instruction generated from the start of the target operation instruction to the current time; wherein, the at least one historical operation instruction includes the target operation instruction; Obtain the data status backup information corresponding to each of the historical operation instructions; Based on the backup information of each data status, corresponding reverse operation instructions are generated respectively; Each of the reverse operation instructions is executed sequentially to perform data rollback on the target database.
[0011] In this embodiment, multiple reverse operation instructions are generated based on the data status backup information corresponding to multiple historical operation instructions, and these reverse operation instructions are executed sequentially to perform rollback, thereby further improving the reliability of data rollback.
[0012] In some embodiments, the data rollback process for the target database based on the data status backup information includes: Acquire at least one historical operation instruction generated from the start of the target operation instruction to the current time; wherein, the at least one historical operation instruction includes the target operation instruction; Generate reverse operation instructions corresponding to each of the aforementioned historical operation instructions; Each of the reverse operation instructions is executed sequentially to perform data rollback on the target database.
[0013] In this embodiment, by generating multiple reverse operation instructions based on multiple historical operation instructions and executing these reverse operation instructions sequentially to perform rollback, the reliability of data rollback is further improved.
[0014] In some embodiments, acquiring at least one historical operation instruction generated from the start of the target operation instruction to the current time includes: If it is determined that the rollback type of the rollback request is a data-only rollback, the target data object targeted by the target operation instruction is obtained; wherein, the rollback type includes data-only rollback and full database rollback; Obtain at least one historical operation instruction generated from the start of the target operation instruction up to the current time and applied to the target data object.
[0015] In this embodiment of the application, by providing the function of individual data rollback, the operation on the target data object can be rolled back individually, thereby further improving the flexibility of data rollback.
[0016] In some embodiments, the sequential execution of each of the reverse operation instructions to perform data rollback processing on the target database includes: The reverse execution order is determined based on the execution order of the at least one historical operation instruction; The reverse operation instructions are executed sequentially according to the reverse execution order to perform data rollback processing on the target database.
[0017] In this embodiment, the reliability of data rollback is further improved by determining the reverse execution order based on the execution order of historical operation instructions and performing data rollback according to the reverse execution order.
[0018] In some embodiments, the step of executing each of the reverse operation instructions sequentially according to the reverse execution order to perform data rollback processing on the target database includes: After each execution of the reverse operation instruction, obtain the current data status information; A consistency check is performed based on the data status information and the data status backup information of the corresponding historical operation instructions; wherein, the reverse operation instructions and the historical operation instructions have a one-to-one correspondence. If the consistency check passes, the remaining reverse operation instructions are executed sequentially to perform data rollback on the target database.
[0019] In this embodiment of the application, the reliability of data rollback is further improved by performing a consistency check with the corresponding data status backup information after each execution of the reverse operation instruction.
[0020] In some embodiments, generating a reverse operation instruction corresponding to the data state backup information and executing the reverse operation instruction to perform data rollback processing on the target database includes: According to the instruction format of the target operation instruction, a reverse operation instruction corresponding to the data status backup information is generated and executed to perform data rollback processing on the target database.
[0021] In this embodiment, the scalability of data rollback is further improved by generating corresponding reverse operation instructions based on the instruction format of the target operation instruction.
[0022] In some embodiments, generating reverse operation instructions corresponding to each of the historical operation instructions includes: Determine the database type corresponding to each of the historical operation instructions; Determine the instruction format corresponding to each of the aforementioned database types; According to the corresponding instruction format, reverse operation instructions corresponding to each of the historical operation instructions are generated respectively.
[0023] In this embodiment, the corresponding instruction format is determined according to the database type of different historical operation instructions, and corresponding reverse operation instructions are generated based on various instruction formats, thereby further improving the flexibility of data rollback.
[0024] Secondly, embodiments of this application provide a database rollback apparatus, comprising: The instruction determination module is used to determine the target operation instruction specified by the rollback request in response to a rollback request triggered by the user. The data acquisition module is used to acquire data status backup information corresponding to the target operation instruction; wherein, the data status backup information is recorded and backed up before the target operation instruction takes effect; The data rollback module is used to perform data rollback processing on the target database based on the data status backup information.
[0025] Thirdly, embodiments of this application provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, can implement the method described in any embodiment of the first aspect.
[0026] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, can implement the method described in any embodiment of the first aspect.
[0027] Fifthly, embodiments of this application provide a computer program product, the computer program product including a computer program, wherein when the computer program is executed by a processor, it can implement the method described in any embodiment of the first aspect. Attached Figure Description
[0028] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0029] Figure 1 A schematic flowchart illustrating a database rollback method provided in an embodiment of this application; Figure 2 This is a schematic diagram of the structure of a database rollback device provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0030] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0031] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0032] It should be noted that existing technologies primarily rely on the database's built-in backup and recovery mechanisms, or on manually writing and executing rollback scripts to restore data. However, these solutions have at least the following problems: First, rollback typically depends on periodic backups, resulting in coarse-grained recovery and an inability to quickly locate and undo a specific erroneous operation; second, manually writing rollback scripts requires high levels of expertise, making them prone to errors and inefficient; third, different types of databases (such as MySQL, Oracle, PostgreSQL, etc.) differ significantly in syntax and mechanisms, making it difficult to achieve unified rollback control in multi-database environments.
[0033] As more and more enterprises adopt bastion hosts for centralized management and auditing of operations and maintenance, how to perform fine-grained rollback control of database operations and maintenance at the bastion host level has become a key issue in ensuring data security and operational compliance.
[0034] To address at least one of the aforementioned technical problems, this application provides a database rollback method that records the data state corresponding to the operation instruction and performs a rollback operation based on the specific instruction that triggers the rollback, effectively improving the accuracy, reliability, and efficiency of data rollback.
[0035] like Figure 1 As shown in the figure, this application embodiment provides a database rollback method, which may include the following steps: S1. In response to a user-triggered rollback request, determine the target operation instruction specified in the rollback request.
[0036] For example, in an operations and maintenance system, every operation command actually executed by a user during the operations and maintenance process can be recorded (historical operation commands). These operation records can also be displayed through a rollback management interface.
[0037] For example, the key information related to the operation instructions recorded by the system may include one or more of the following: table name, primary key / unique identifier, operation type, specific operation instruction content, data result set before the operation takes effect, timestamp of the effective date, session identifier, etc.
[0038] When maintenance personnel discover a mistake or want to "undo an operation" for other reasons, they can select the desired rollback location in the rollback management interface, such as clicking on a specific operation instruction (target operation instruction), to trigger a rollback request.
[0039] The system can respond to rollback requests triggered by users and determine the specific operation instructions that the user wants to roll back this time (i.e., determine the target operation instructions specified in the rollback request).
[0040] S2. Obtain the data status backup information corresponding to the target operation command; wherein, the data status backup information is recorded and backed up before the target operation command takes effect.
[0041] It should be noted that the operation and maintenance system can record the data status backup information corresponding to each operation instruction. The data status backup information refers to the data status of each operation instruction before it takes effect on the target data object. For example, suppose that the data 'a' in table A has a data status of A0 (such as the value 500) before a certain operation instruction X is executed, then the data status backup information corresponding to operation instruction X is A0.
[0042] For example, data status backup information can be recorded and stored as the "data result set before the operation took effect" in the key information. For example, users can view the data status backup information corresponding to each operation instruction in the operation record displayed on the rollback management interface.
[0043] S3. Perform data rollback processing on the target database based on data status backup information.
[0044] After determining the data status backup information corresponding to the target operation instruction, data rollback can be performed on the target database based on the data status backup information. For example, the target data object corresponding to the target operation instruction can be directly restored to the data corresponding to the data status backup information. For instance, assuming the data status backup information for the target data object corresponding to the target operation instruction is 500, and the current value of the target data object is 600 (which could be any value), then the data rollback process would be to restore the value of the target data object to 500.
[0045] Based on this, by backing up the data state at the instruction level and accurately locating and rolling back the target instruction when a rollback is triggered, the accuracy, reliability, and efficiency of database rollback are effectively improved.
[0046] In some embodiments, data rollback processing of the target database based on data status backup information includes: Generate and execute reverse operation instructions corresponding to the data status backup information to perform data rollback on the target database.
[0047] It should be noted that after determining the data status backup information corresponding to the target operation instruction, a corresponding reverse operation instruction can be generated based on the data status backup information, and the data rollback can be achieved by executing the reverse operation instruction.
[0048] For example, the current data state of the corresponding target data object (determined based on key information related to the target operation instruction) can be obtained, and a reverse operation instruction can be generated based on the difference between the current data state and the data state backup information.
[0049] For example, assuming the current data status of the target data object is 600, and the corresponding data status backup information is 500, a reverse operation instruction of "reducing by 100" can be generated. For instance, if it is an SQL operation instruction, the above example can generate a reverse operation instruction of "UPDATE table_name SET target_column = target_column - 100 WHERE id = 1".
[0050] Based on this, the reliability of data rollback is further improved by generating specific reverse operation instructions based on the data status backup information for rollback.
[0051] In some embodiments, generating and executing reverse operation instructions corresponding to data state backup information to perform data rollback processing on the target database includes: Retrieve at least one historical operation instruction generated from the start of the target operation instruction to the current time; wherein, the at least one historical operation instruction includes the target operation instruction; Obtain the data status backup information corresponding to each historical operation command; Based on the backup information of each data status, corresponding reverse operation instructions are generated; Each reverse operation instruction is executed sequentially to perform data rollback on the target database.
[0052] For example, when the operation and maintenance personnel select the target operation instruction they want to roll back, they can obtain all historical operation instructions (including the target operation instruction) generated by the system from the start of the target operation instruction to the current moment. At the same time, for each historical operation instruction, they can obtain its corresponding data status backup information.
[0053] Then, a corresponding reverse operation instruction can be generated based on the backup information of each data state. For example, suppose there are three historical operation instructions X1, X2, and X3 acting on the same target data object, and their corresponding data state backup information is A1, A2, and A3, respectively. Then, by comparing the "current data state" with A3, the reverse operation instruction corresponding to X3 can be generated (that is, the reverse operation instruction corresponding to A3). By comparing A3 with A2, the reverse operation instruction corresponding to X2 can be generated (that is, the reverse operation instruction corresponding to A2), and so on, until multiple corresponding reverse operation instructions can be obtained.
[0054] For example, the order and basis for generating reverse operation instructions are not limited to the above method. Any order and combination can also be used. For example, the reverse operation instruction corresponding to A2 can be generated by comparing the "current data state" with A2, the reverse operation instruction corresponding to A3 can be generated by comparing A3 with A2, and finally the reverse operation instruction corresponding to A1 can be generated by comparing A3 with A1.
[0055] Finally, the generated reverse operation instructions are executed sequentially to complete the data rollback of the target database. It can be understood that the execution order of the reverse operation instructions can follow the order in which they were generated.
[0056] Based on this, multiple reverse operation instructions are generated according to the data status backup information corresponding to multiple historical operation instructions, and these reverse operation instructions are executed in sequence to perform rollback, thereby further improving the reliability of data rollback.
[0057] In some embodiments, data rollback processing of the target database based on data status backup information includes: Retrieve at least one historical operation instruction generated from the start of the target operation instruction to the current time; wherein, the at least one historical operation instruction includes the target operation instruction; Generate reverse operation instructions corresponding to each historical operation instruction; Each reverse operation instruction is executed sequentially to perform data rollback on the target database.
[0058] It should be noted that when maintenance personnel select the target operation instruction they want to roll back, they can obtain all historical operation instructions (including the target operation instruction) generated by the system from the start of the target operation instruction to the current moment.
[0059] Then, the corresponding reverse operation instruction can be generated directly based on each historical operation instruction.
[0060] For example, suppose a historical operation command is "increment the target data object by 100", then its corresponding reverse operation command is "decrement the target data object by 100". Taking SQL statements as an example, suppose a historical operation command is "UPDATE table_name SET target_column = target_column + 100 WHERE id = 1", then its corresponding reverse operation command is "UPDATE table_name SET target_column = target_column -100 WHERE id = 1".
[0061] Finally, the generated reverse operation instructions are executed sequentially to roll back the data in the target database. It is understood that the execution order of the reverse operation instructions can be arbitrary; alternatively, the execution order can also follow the generation order of the reverse operation instructions to further improve the reliability of the data rollback.
[0062] Based on this, by generating multiple reverse operation instructions according to multiple historical operation instructions and executing these reverse operation instructions in sequence to perform rollback, it is beneficial to further improve the efficiency and reliability of data rollback.
[0063] In some embodiments, acquiring at least one historical operation instruction generated from the start of the target operation instruction to the current time includes: If the rollback type of the rollback request is determined to be a data-only rollback, obtain the target data object targeted by the target operation instruction; wherein, the rollback type includes data-only rollback and full database rollback; Retrieves at least one historical operation instruction generated from the start of the target operation instruction up to the current moment that has acted on the target data object.
[0064] It should be noted that in the rollback management interface, in addition to selecting the target operation command to be rolled back according to needs, operations and maintenance personnel can also select the rollback type. The rollback type can be divided into data-only rollback and full database rollback. For example, data-only rollback refers to rolling back all operations and maintenance operations on only a specific data object during the period, while full database rollback refers to rolling back all operations and maintenance operations on the entire database during the period.
[0065] If the rollback type of the rollback request is determined to be a data-only rollback, the target data object can be determined based on the key information related to the target operation instruction. Based on this, two range conditions can be determined for filtering historical operation instructions: 1. All instructions generated from the start of the target operation instruction to the current moment (time range condition); 2. Operation instructions that act on the target data object (data object range condition).
[0066] Then, all historical operation instructions that meet the filtering criteria can be obtained (that is, all historical operation instructions generated from the start of the target operation instruction to the current moment and applied to the target data object).
[0067] Based on this, by providing the function of individual data rollback, precise rollback of operations on target data objects can be achieved, further improving the accuracy and flexibility of data rollback.
[0068] In some embodiments, each reverse operation instruction is executed sequentially to perform data rollback processing on the target database, including: The reverse execution order is determined based on the execution order of at least one historical operation instruction; The reverse operation instructions are executed sequentially in reverse execution order to perform data rollback on the target database.
[0069] It should be noted that the effective timestamps of each historical operation instruction can be determined based on the key information recorded by the system, thus determining the execution order of each historical operation instruction.
[0070] Based on this, the reverse order of the execution order of each historical operation instruction can be used as the reverse execution order of multiple reverse operation instructions. For example, suppose the currently filtered historical operation instructions are X1, X2, and X3, and their corresponding reverse operation instructions are Y1, Y2, and Y3 respectively; if the execution order of the historical operation instructions is determined to be X1→X2→X3, then the execution order of the reverse operation instructions (reverse execution order) can be determined to be Y3→Y2→Y1.
[0071] Based on this, the reverse execution order is determined according to the execution order of historical operation instructions, and data rollback is performed according to the reverse execution order, thereby further improving the reliability of data rollback.
[0072] In some embodiments, each reverse operation instruction is executed sequentially in reverse execution order to perform data rollback processing on the target database, including: Obtain the current data status information after each execution of the reverse operation instruction; Consistency verification is performed based on the data status information and the corresponding historical operation instructions' data status backup information; among them, the reverse operation instructions and the historical operation instructions have a one-to-one correspondence. If the consistency check passes, the remaining reverse operation instructions are executed sequentially to perform data rollback on the target database.
[0073] It should be noted that after each execution of a reverse operation instruction, the current data state information of the target data object can be retrieved once, and a consistency check can be performed against the data state backup information. Only if the consistency check passes will the remaining reverse operation instructions be executed sequentially. It can be understood that each reverse operation instruction corresponds one-to-one with a historical operation instruction.
[0074] For example, suppose the target data object currently has three historical operation instructions: X1, X2, and X3, with corresponding data state backup information of A0, A1, and A2, and corresponding reverse operation instructions of Y1, Y2, and Y3. During data rollback, Y3→Y2→Y1 will be executed sequentially. After executing Y3, the current data state information of the target data object can be obtained as A2'. At this point, A2' can be compared with the corresponding data state backup information A2 for consistency verification. If they match, the remaining reverse operation instructions (Y2→Y1) will continue to be executed; otherwise, the verification fails, the data rollback is canceled, and an exception alarm is triggered.
[0075] Based on this, the reliability of data rollback is further improved by performing a consistency check with the corresponding data status backup information after each execution of the reverse operation instruction.
[0076] In some embodiments, generating and executing reverse operation instructions corresponding to data state backup information to perform data rollback processing on the target database includes: According to the instruction format of the target operation instruction, generate a reverse operation instruction corresponding to the data status backup information, and execute the reverse operation instruction to perform data rollback on the target database.
[0077] It should be noted that the operation and maintenance system may include various types of databases, and the operation and maintenance instructions may include various instruction formats. Therefore, when rolling back data, the corresponding reverse operation instructions can be generated according to the instruction format of the target operation instructions to ensure that the instruction format of the reverse operation instructions is compatible with the corresponding target database.
[0078] In this way, the operation and maintenance system can arbitrarily expand the database type according to the needs. It only needs to record the instruction format of the operation and maintenance command, without modifying the rollback processing mechanism, so that the purpose of database rollback can be achieved during the operation and maintenance process.
[0079] Based on this, the scalability of data rollback is further improved by generating corresponding reverse operation instructions according to the instruction format of the target operation instruction.
[0080] In some embodiments, reverse operation instructions corresponding to each historical operation instruction are generated, including: Determine the database type corresponding to each historical operation instruction; Determine the instruction format corresponding to each database type; According to the corresponding instruction format, generate reverse operation instructions corresponding to each historical operation instruction.
[0081] It should be noted that when there are multiple historical operation commands that need to be rolled back, the databases on which these historical operation commands are applied may be different (e.g., MySQL, Oracle, PostgreSQL, etc.). Therefore, the type of database on which each historical operation command is applied can be determined based on the key information related to the historical operation commands. Then, reverse operation commands with corresponding command formats can be generated according to different database types, thereby enabling unified rollback control in a multi-database environment.
[0082] Based on this, by determining the corresponding instruction format according to the database type of different historical operation instructions, and generating corresponding reverse operation instructions based on various instruction formats, the flexibility of data rollback is further improved.
[0083] In some embodiments, the method of this application can also be applied to multi-protocol database data rollback scenarios based on bastion host protocol proxy. Its core principle is: to capture each operational operation in real time at the bastion host proxy layer, bind the operation to the session, and save the data state before each operation (data state backup information); when a rollback requirement is triggered, the proxy directly generates a reverse operation instruction and sends it to the database, achieving precise automated rollback. By directly controlling the rollback process through the protocol proxy layer, unified rollback in multi-database and multi-protocol environments is supported, and it can be linked with the operation and maintenance audit system to achieve traceable and automated execution of rollback operations.
[0084] The specific process is as follows: (1) Session access: Operations personnel access the target database through the bastion host; the protocol proxy layer establishes a session and generates a unique identifier for the session.
[0085] (2) Operation capture and recording: The protocol proxy layer can obtain operation and maintenance instructions (such as SQL operations) in real time. For query operations (SELECT), only pass-through is required; for operations involving data changes (such as INSERT, UPDATE, DELETE, etc.), the logic of capturing the data state before the operation (which can be represented by "before-image" in this example) is triggered.
[0086] After the before-image logic is triggered, the proxy layer intercepts the sending of the original operation command and automatically constructs a corresponding SELECT query to obtain the current state of the row (target data object) that is about to be modified.
[0087] Then, the serialized data result set obtained from the query (data status backup information) is stored in the cache of the proxy layer. The data storage structure includes, but is not limited to, one or more of the following: table name, primary key / unique identifier, operation type, data result set before operation, timestamp, and session identifier.
[0088] (3) Trigger rollback: After discovering an erroneous operation, maintenance personnel can view the executed instructions in the instruction audit interface (rollback management interface).
[0089] Operations personnel can manually select an operation command and click "rollback"; this will trigger the data rollback operation.
[0090] (4) Generate rollback operation set: Once the database rollback program receives a rollback request, it will begin calculating the rollback operation set. The rollback scope can be all operations from the latest operation to the target operation instruction (the instruction selected by the operations and maintenance personnel).
[0091] Specifically, the database rollback procedure can trace back step by step from the most recently executed instruction, based on the instruction record; For each historical operation command, its corresponding data status backup information can be read.
[0092] Then, based on the data status backup information, the corresponding reverse operation instructions are automatically generated.
[0093] For example: The database executed the command UPDATE users SET balance = balance - 100 WHERE id=1; The data status backup information shows that the original value of this data object was 500.
[0094] The database rollback procedure can then generate the rollback statement: UPDATE users SET balance = 500 WHEREid=1; All reverse operation instructions are arranged in reverse order of execution (i.e., the latest operation is rolled back first, and the earliest operation is rolled back last) and encapsulated in a database transaction.
[0095] (5) Perform a rollback operation: After the rollback instruction set is generated, the agent reads the reverse operation instructions sequentially from the encapsulated database transactions.
[0096] The agent program sends the read reverse operation instructions one by one to the target database server and executes them to achieve data rollback.
[0097] (6) Rollback audit and confirmation: Rollback operations can be recorded and stored in the audit log, and associated with the original session; Based on this, audit logs can be used to support the playback and review of rollback operations, ensuring security and traceability.
[0098] Based on the above process, the following specific examples are provided for detailed explanation: Suppose that an enterprise's operations and maintenance personnel access the target MySQL database through a bastion host and perform a balance adjustment operation on the users table.
[0099] 1. The operations and maintenance personnel establish a session with the MySQL database through the bastion host. The protocol proxy layer assigns a unique identifier to the session and enters the session monitoring state.
[0100] 2. The operations and maintenance personnel execute the following command: UPDATE users SET balance = balance - 100 WHEREid = 1; 3. The protocol proxy layer detects that this operation is a data update operation and triggers the before-image (data recording) logic: 4. Before executing the original command, automatically generate the following query statement: SELECT * FROM users WHERE id = 1; 5. The query results and their metadata (table name, primary key, operation type, timestamp, session ID, etc.) are serialized and cached (as backup information for data state). Subsequently, the original UPDATE command is passed through to the database for execution.
[0101] 6. If the operations and maintenance personnel find that the operation is a mistake in the operation and maintenance audit interface of the bastion host, they can select the UPDATE command in the audit interface (or rollback management interface) and click "rollback".
[0102] 7. The database rollback program generates the corresponding reverse instruction based on the data status backup information of the operation: UPDATEusers SET balance = 500 WHERE id = 1; If there are multiple consecutive erroneous operations in the session, the database rollback program can trace back from the latest operation one by one, generate the corresponding reverse operation instruction for each operation, and encapsulate them into a rollback transaction in the reverse order of the original operations.
[0103] 8. Under transaction control, the protocol proxy layer sequentially sends the above rollback operation set to the database.
[0104] 9. The protocol proxy layer writes this rollback operation to the audit log and associates it with the original session record of the erroneous operation. Administrators can replay the rollback process in subsequent audits to achieve complete traceability of operational operations.
[0105] Compared with the prior art, the embodiments of this application have the following beneficial effects: 1. Precise automatic rollback reduces operational risks; By capturing the data state before an operation at the proxy layer and generating a reverse operation, precise rollback of single or session-level erroneous operations can be achieved, ensuring data security and consistency.
[0106] 2. Improve operational efficiency and reduce labor costs; The system automatically generates a rollback operation set and encapsulates it as a transaction. Operation and maintenance personnel can complete the rollback by clicking the command on the audit interface without having to manually write scripts, thus shortening recovery time and improving processing efficiency.
[0107] 3. Unified management and traceability across multiple databases and protocols; The bastion host protocol proxy layer unifies the capture and rollback logic, supports multiple databases and protocols, and associates rollback operations with session auditing to achieve unified management and secure traceability of operation and maintenance operations.
[0108] Please refer to Figure 2 , Figure 2 A block diagram illustrating the composition of a database rollback apparatus provided in some embodiments of this application is shown. It should be understood that this database rollback apparatus is similar to the one described above. Figure 1 Corresponding to the method embodiments, it can execute the various steps involved in the above method embodiments. The specific functions of the database rollback device can be found in the description above. To avoid repetition, detailed descriptions are appropriately omitted here.
[0109] Figure 2 The database rollback device includes at least one software functional module that can be stored in memory or embedded in the database rollback device in the form of software or firmware. The database rollback device includes: The instruction determination module 210 is used to determine the target operation instruction specified in the rollback request in response to the rollback request triggered by the user. The data acquisition module 220 is used to acquire data status backup information corresponding to the target operation instruction; wherein, the data status backup information is recorded and backed up before the target operation instruction takes effect; The data rollback module 230 is used to perform data rollback processing on the target database based on data status backup information.
[0110] It is understood that the above-described device embodiments correspond to the method embodiments of the present invention. The database rollback device provided by the embodiments of the present invention can implement the database rollback method provided by any one of the method embodiments of the present invention.
[0111] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the device described above can be referred to the corresponding process in the aforementioned method, and will not be elaborated further here.
[0112] like Figure 3 As shown, some embodiments of this application provide an electronic device 300, which includes a memory 310, a processor 320, and a computer program stored in the memory 310 and executable on the processor 320. When the processor 320 reads the program from the memory 310 via a bus 330 and executes the program, it can implement any of the methods included in the above-described database rollback method.
[0113] Processor 320 can process digital signals and may include various computing architectures. For example, it may be a complex instruction set computer architecture, a reduced instruction set computer architecture, or an architecture that implements multiple instruction set combinations. In some examples, processor 320 may be a microprocessor.
[0114] The memory 310 can be used to store instructions executed by the processor 320 or data related to the execution of instructions. These instructions and / or data may include code used to implement some or all of the functions of one or more modules described in the embodiments of this application. The processor 320 of this disclosure embodiment can be used to execute the instructions in the memory 310 to implement the methods shown above. The memory 310 includes dynamic random access memory, static random access memory, flash memory, optical memory, or other memories well known to those skilled in the art.
[0115] Some embodiments of this application also provide a computer-readable storage medium storing a computer program that, when executed by a processor, describes the method described in the method embodiments.
[0116] Some embodiments of this application also provide a computer program product that, when run on a computer, causes the computer to perform the methods described in the method embodiments.
[0117] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For apparatus embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0118] It should be understood, in the several embodiments provided in this application, that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0119] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0120] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0121] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application. It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0122] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0123] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A database rollback method, characterized by, The method comprises: in response to a rollback request triggered by a user, determining a target operation instruction specified by the rollback request; obtaining data state backup information corresponding to the target operation instruction; wherein the data state backup information is recorded and backed up before the target operation instruction takes effect; performing data rollback processing on a target database based on the data state backup information.
2. The database rollback method of claim 1, wherein, The data rollback processing on the target database based on the data state backup information comprises: generating reverse operation instructions corresponding to the data state backup information, and executing the reverse operation instructions to perform data rollback processing on the target database.
3. The database rollback method of claim 2, wherein, The generation of the reverse operation instructions corresponding to the data state backup information and the execution of the reverse operation instructions to perform data rollback processing on the target database comprise: obtaining at least one historical operation instruction generated from the target operation instruction to the current time; wherein the at least one historical operation instruction includes the target operation instruction; obtaining data state backup information corresponding to each of the historical operation instructions respectively; generating corresponding reverse operation instructions based on each of the data state backup information respectively; sequentially executing each of the reverse operation instructions to perform data rollback processing on the target database.
4. The database rollback method of claim 1, wherein, The data rollback processing on the target database based on the data state backup information comprises: obtaining at least one historical operation instruction generated from the target operation instruction to the current time; wherein the at least one historical operation instruction includes the target operation instruction; generating reverse operation instructions corresponding to each of the historical operation instructions respectively; sequentially executing each of the reverse operation instructions to perform data rollback processing on the target database.
5. The database rollback method of claim 3 or 4, wherein, The obtaining of the at least one historical operation instruction generated from the target operation instruction to the current time comprises: in a case where it is determined that a rollback type of the rollback request is data-only rollback, obtaining a target data object to which the target operation instruction is directed; wherein the rollback type includes data-only rollback and database full-amount rollback; obtaining at least one historical operation instruction generated from the target operation instruction to the current time and acting on the target data object.
6. The database rollback method of claim 3 or 4, wherein, The sequential execution of each of the reverse operation instructions to perform data rollback processing on the target database comprises: determining a reverse execution order based on an execution order of the at least one historical operation instruction; sequentially executing each of the reverse operation instructions in the reverse execution order to perform data rollback processing on the target database.
7. The database rollback method of claim 6, wherein, The sequential execution of each of the reverse operation instructions in the reverse execution order to perform data rollback processing on the target database comprises: obtaining current data state information after each execution of the reverse operation instruction; performing consistency verification based on the data state information and data state backup information of a corresponding historical operation instruction; wherein the reverse operation instruction and the historical operation instruction are in a one-to-one correspondence; in a case where the consistency verification passes, sequentially executing remaining reverse operation instructions to perform data rollback processing on the target database.
8. The database rollback method of claim 2, wherein, The reverse operation instruction corresponding to the data state backup information is generated according to the instruction format of the target operation instruction, and the reverse operation instruction is executed to perform data rollback processing on the target database. The reverse operation instruction corresponding to the data state backup information is generated according to the instruction format of the target operation instruction, and the reverse operation instruction is executed to perform data rollback processing on the target database.
9. The database rollback method of claim 4, wherein, The reverse operation instruction corresponding to the data state backup information is generated according to the instruction format of the target operation instruction, and the reverse operation instruction is executed to perform data rollback processing on the target database. The database type corresponding to each historical operation instruction is determined. The instruction format corresponding to each database type is determined. The reverse operation instruction corresponding to each historical operation instruction is generated according to the corresponding instruction format.
10. An electronic device, comprising: The computer readable storage medium stores a computer program, and the processor executes the program to implement the database rollback method of any one of claims 1-9.
11. A computer readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the processor executes the program to implement the database rollback method of any one of claims 1-9.
12. A computer program product, characterised in that, The computer program product includes a computer program, and the processor executes the program to implement the database rollback method of any one of claims 1-9.