Database misoperation recovery method and device

By parsing and generating reverse operation statements, the database can be restored using partial backup data, solving the problem of data errors and failures caused by database misoperation and achieving fast and flexible database recovery.

CN119003238APending Publication Date: 2024-11-22BEIJING XIJUN DATA TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410987061.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-23
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

Due to differences in the skill level and familiarity of personnel operating databases within enterprises, unpredictable errors can easily occur, leading to data errors and business failures, and existing technologies are insufficient to effectively recover the database.

Method used

By parsing database operation statements, the system determines the timing of backups and generates reverse operation statements in case of erroneous operations. It then uses partial backup data to restore the database, supporting on-demand recovery and a flexible database recovery mechanism.

Benefits of technology

It enables fast and flexible database recovery, reduces the potential risks caused by accidental operations, and improves the security and reliability of database operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003238A_ABST
    Figure CN119003238A_ABST
Patent Text Reader

Abstract

The invention provides a database misoperation recovery method and device, relates to the technical field of computers, and is used for solving the database recovery problem in related technologies. The method comprises the following steps: analyzing a target operation statement of a database to obtain a statement type, an operation table and condition information of the target operation statement; under the condition that the statement type is the target type, determining a backup opportunity corresponding to the statement type; the backup opportunity refers to backup after execution of the target operation statement or backup before execution of the target operation statement; executing the target operation statement in the database to update the database; and at the backup opportunity, based on the operation table and the condition information, performing backup on the table structure and the data content in the data range involved by the target operation statement to obtain local backup data, when it is determined that the target operation statement is the misoperation statement, generating an inverse operation statement of the target operation statement; and executing an inverse operation statement on the database by taking the local backup data as a benchmark.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] In recent years, with the advent of the digital age, the size of data has increased dozens of times. Therefore, enterprises have invested more and more in the storage, management and operation of data. In actual database management, due to the differences in the number of manpower, management details, personnel quality and familiarity of each enterprise, some unpredictable errors in database operations are prone to occur, which in turn leads to data errors. In serious cases, it will cause large-scale business failures. Summary of the invention

[0003] The embodiments of the present application provide a method and device for recovering a database misoperation, which are used to solve the problem of how to recover a database after a misoperation in the related art.

[0004] In a first aspect, the present disclosure provides a method for recovering a database misoperation, comprising:

[0005] Parsing the target operation statement of the database to obtain the statement type, operation table and condition information of the target operation statement;

[0006] In the case where the statement type is a target type, determining a backup timing corresponding to the statement type; the backup timing is backing up after executing the target operation statement, or backing up before executing the target operation statement;

[0007] Executing the target operation statement in the database to update the database; and, at the backup timing, backing up the table structure and data content within the data range involved in the target operation statement based on the operation table and the condition information to obtain partial backup data;

[0008] In the case where it is determined that the target operation statement is an erroneous operation statement, generating an inverse operation statement of the target operation statement;

[0009] The reverse operation statement is executed on the database based on the local backup data.

[0010] In a second aspect, the present application provides a device for recovering a database misoperation, the device comprising:

[0011] A parsing module, used to parse the target operation statement of the database to obtain the statement type, operation table and condition information of the target operation statement;

[0012] A determination module, used for determining, when the statement type is a target type, a backup timing corresponding to the statement type; the backup timing is to back up after executing the target operation statement, or to back up before executing the target operation statement;

[0013] A backup module, configured to execute the target operation statement in the database to update the database; and, at the backup timing, back up the table structure and data content within the data range involved in the target operation statement based on the operation table and the condition information to obtain local backup data;

[0014] A generating module, configured to generate a reverse operation statement of the target operation statement when determining that the target operation statement is an erroneous operation statement;

[0015] A recovery module is used to execute the reverse operation statement on the database based on the local backup data.

[0016] In a third aspect, the present application further provides an electronic device, including:

[0017] processor;

[0018] a memory for storing instructions executable by the processor;

[0019] The processor is configured to execute the instructions to implement the method provided in the first aspect of the present application.

[0020] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium. When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method provided in the first aspect of the present application.

[0021] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the method provided in the first aspect of the present application.

[0022] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. Obviously, the drawings introduced below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0024] Figure 1 A schematic diagram of an application scenario of the method for recovering from database misoperation provided in an embodiment of the present application;

[0025] Figure 2 A flowchart of a method for recovering from database misoperation provided in an embodiment of the present application;

[0026] Figure 3 Another schematic diagram of a process flow of a method for recovering a database misoperation provided by an embodiment of the present application;

[0027] Figure 4 A schematic diagram of another process of a method for recovering a database misoperation provided in an embodiment of the present application;

[0028] Figure 5 Another flowchart of a method for recovering a database misoperation provided by an embodiment of the present application;

[0029] Figure 6 A schematic diagram of the overall process of a method for identifying operation and maintenance faults provided in an embodiment of the present application;

[0030] Figure 7 is a block diagram of a device for identifying operation and maintenance faults according to an exemplary embodiment;

[0031] Figure 8 It is a schematic structural diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0032] In order to enable ordinary persons in the art to better understand the technical solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.

[0033] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here can be implemented in an order other than those illustrated or described here. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.

[0034] Below, some terms in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.

[0035] (1) In the embodiments of the present application, the term "plurality" refers to two or more than two, and other quantifiers are similar.

[0036] (2) "and / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects are in an "or" relationship.

[0037] (3) Servers provide services for terminals. The services provided include providing resources to terminals and storing terminal data. Servers correspond to applications installed on terminals and work in conjunction with applications on terminals.

[0038] (4) Terminal device, which can refer to software APP (Application) or client. It has a visual display interface and can interact with users. It corresponds to the server and provides local services to customers. For software applications, except for some applications that only run locally, they are generally installed on ordinary client terminals and need to cooperate with the server to run. For applications, there needs to be corresponding servers and service programs in the network to provide corresponding services, such as database services, configuration parameter services, etc. In this way, specific communication connections need to be established between the client terminal and the server to ensure the normal operation of the application.

[0039] Due to complex reasons, such as differences in personnel literacy and familiarity, some unpredictable human errors are prone to occur in database operations, which in turn lead to potential database failures. Therefore, a flexible database recovery mechanism is needed to help perform database recovery efficiently and in real time.

[0040] In view of this, an embodiment of the present application provides a method for recovering database misoperations, in which a user can quickly perform rollback recovery after a misoperation occurs, thereby reducing the potential risks of enterprises due to such data misoperations. The following is a brief introduction to the application scenarios to which the technical solutions of the embodiments of the present application can be applied. It should be noted that the application scenarios introduced below are only used to illustrate the embodiments of the present application and are not intended to be limiting. In specific implementation, the technical solutions provided by the embodiments of the present application can be flexibly applied according to actual needs.

[0041] refer to Figure 1, which is a schematic diagram of an application scenario of the method for identifying operation and maintenance faults provided in an embodiment of the present application. The application scenario includes multiple terminal devices 101 (including terminal device 101-1, terminal device 101-2, ... terminal device 101-n), and also includes a server 102. Among them, the terminal device 101 and the server 102 are connected via a wireless or wired network, and the terminal device 101 includes but is not limited to electronic devices such as desktop computers, mobile phones, mobile computers, tablet computers, media players, smart wearable devices, smart TVs, etc. The server 102 can be a server cluster or a cloud computing center composed of a plurality of servers. The server 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0042] In the process of executing database operation statements, the server can record relevant information and perform flexible backup of the smallest unit. After an erroneous operation, the database can be restored in a timely manner based on the flexible backup data of the smallest unit.

[0043] To further illustrate the technical solution provided by the embodiment of the present application, this is described in detail below in conjunction with the accompanying drawings and specific implementation methods. Although the embodiment of the present application provides the method operation steps shown in the following embodiments or drawings, more or fewer operation steps may be included in the method based on routine or no creative labor. In the steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiment of the present application.

[0044] like Figure 2 FIG. 1 is a flow chart of a method for recovering a database misoperation provided by an embodiment of the present disclosure, and includes the following contents:

[0045] S201, parsing a target operation statement in a database to obtain a statement type, an operation table, and condition information of the target operation statement.

[0046] Among them, some conventional database operation statements such as UPDATE, INSERT, DELELTE (delete specified rows), and TRUNCATE (delete all rows in the table) can be used as target operation statements respectively, and the embodiments of the present disclosure do not limit this.

[0047] In the disclosed embodiment, the parsing function of standard SQL (Structured Query Language) statements can be used to parse out information such as statement type, operation table, and conditions in the executed SQL statement.

[0048] S202, when the statement type is a target type, determine a backup timing corresponding to the statement type; the backup timing is backing up after executing the target operation statement, or backing up before executing the target operation statement.

[0049] In the disclosed embodiments, the backup timing, that is, defines when to perform the backup operation. In the disclosed embodiments, the backup timing generally includes two types, namely, backing up before executing the target operation statement, or backing up after executing the target operation statement. In order to be able to perform backup flexibly and reduce the storage resources occupied by the backup data, in the disclosed embodiments, S203 is executed to execute the target operation statement in the database to update the database; and, at the backup timing, based on the operation table and the condition information, the table structure and data content within the data range involved in the target operation statement are backed up to obtain local backup data.

[0050] In order to facilitate flexible and rapid database recovery, in the embodiment of the present disclosure, the types of data operation statements, i.e., target types, can be divided into two categories, one of which is called first-category statements and the other is called second-category statements. The first-category statements are used to change existing data in the database, such as UPDATE, DELELTE, and TRUNCATE, etc.; the second-category statements are used to insert new data into the database, such as INSERT, etc.

[0051] Correspondingly, when the statement type is the first type of statement in the target type, the backup time corresponding to the statement type is to back up before executing the target operation statement. According to the conditions in the SQL statement, data query can be performed to find the original data for backup.

[0052] In the case where the statement type is a second type of statement in the target type, the backup timing corresponding to the statement type is to perform the backup after executing the target operation statement. According to the inserted data value, a data query is performed to find the inserted data, and then the backup is completed.

[0053] For example, for UPDATE, DELETE, and TRUNCATE statements, you need to back up the relevant data before executing the statement. For INSERT statements, you need to back up the relevant data after executing the statement.

[0054] Therefore, regardless of the first type of statement or the second type of statement, the embodiment of the present disclosure records the data content involved as completely as possible while reducing the amount of backup data. This is conducive to database recovery based on the backup data when recovery is needed.

[0055] It is understandable that the local backup data also includes target operation statements to facilitate the execution of database recovery operations during future recovery.

[0056] S204: When it is determined that the target operation statement is an erroneous operation statement, generate an inverse operation statement of the target operation statement.

[0057] As the name implies, the inverse operation statement and the target operation statement perform the inverse operation. For example, the insert operation corresponds to the delete operation. The operation of changing the value A to B corresponds to the operation of changing the value B to A. The specific inverse operation can be determined according to actual needs.

[0058] S205: Execute the reverse operation statement on the database based on the local backup data.

[0059] In summary, in the disclosed embodiment, in the process of executing the target operation statement, the backup timing can be effectively identified, and the backup data range can be accurately identified based on the condition information and the operation table. Therefore, flexible real-time backup can be achieved, and the backup of the minimum data volume can be achieved. In the case of an operation error, the database recovery operation can be performed in real time for the target operation statement based on the local backup data. In the whole process, database recovery is flexible and fast.

[0060] In order to accurately perform local backup, in the embodiment of the present disclosure, based on the operation table and the condition information, the table structure and data content within the data range involved in the target operation statement are backed up to obtain local backup data, which can be implemented as follows: Figure 3 As shown:

[0061] S301, obtaining the operation number and time information of the target operation statement.

[0062] S302, recording the operation number, the time information, the operation table, and the table structure of the operation table in association in a backup database, and backing up the data content within the data range into the operation table in the backup database according to the table structure of the operation table.

[0063] Back up the table structure in the database, including the table column name, column type, primary key information (if any), and index information.

[0064] You can first parse the object (i.e., the operation table) currently being operated by the target operation statement to determine whether the object exists in the backup database. If it does not exist, back up its table structure; if it exists, you can further determine whether its table structure has changed. If it has changed, add a new backup. If it has not changed, do not repeat the table structure backup. In the backup database, create the table name, field name, field length, primary key (if any) and other information of the object to facilitate the storage of backup data.

[0065] When backing up, if it is an insertion search, only the inserted data content can be backed up. If it is a deletion operation, only the deleted data can be recorded.

[0066] It is understandable that, in the embodiments of the present disclosure, for each operation, data within the data range involved is recorded, so that storage resources can be used as effectively as possible. Each operation has its corresponding operation number and operation time, which facilitates backing up data and improving database recovery efficiency.

[0067] In addition, in the embodiments of the present disclosure, database recovery can be performed on demand according to user needs. For example, the user may have executed multiple operation statements on the database. Each operation statement is backed up in the aforementioned manner. In the event of an erroneous operation, the data to be restored can be selected based on user needs, thereby completing on-demand recovery and improving the flexibility of database recovery.

[0068] In order to achieve on-demand recovery, in the embodiment of the present disclosure, it can be implemented as follows Figure 4 As shown:

[0069] S401: In response to a user's restore operation, determine a candidate object.

[0070] For example, the user can query the backup data records of a specified operation table, or query partial data records of operations within a specified time range, which can guide the user specifically on which data to restore.

[0071] S402, verifying the consistency between the table structure of the local backup data of the candidate object and the table structure of the candidate object in the database.

[0072] S403: When the table structure verification is consistent, the recovery status is displayed to the user based on the local backup data and the data in the database.

[0073] S404: In response to the user's selection operation, determine at least one piece of data to be restored in the candidate object.

[0074] In the above, steps S401 to S404 can be understood as comparing the current data in the database with the backup data during implementation, and displaying the expected changes of data recovery to the user for the user to check and determine which data to restore.

[0075] S405: Determine at least one operation statement in the operation record corresponding to the at least one piece of data to be restored as an erroneous operation statement.

[0076] Wherein, when the at least one operation statement includes the target operation statement, the target operation statement is determined to be an erroneous operation statement.

[0077] Therefore, in the disclosed embodiment, the user can restore the database as needed anytime and anywhere according to the recorded backup data.

[0078] For each erroneous operation statement, a corresponding reverse operation statement needs to be generated to recover the database.

[0079] Continuing to take the above target operation statement as an example, this can be implemented as follows Figure 5 As shown:

[0080] S501, for the data to be recovered corresponding to the target operation statement, if the data to be recovered has a primary key, according to the first primary key of the data to be recovered in the local backup data, search the database for the data to be changed that matches the first primary key to obtain a search result.

[0081] S502: Generate the inverse operation statement based on the search result.

[0082] Among them, based on different search results, adaptive inverse operation statements can be generated to facilitate accurate database recovery.

[0083] Case 1) When the corresponding first primary key is found in the database and the data to be modified is found in the database, the embodiment of the present disclosure can be implemented as follows: Figure 5 As shown, in S5021, based on the first primary key of the data to be restored in the local backup data, when the first primary key is found in the database and the data to be changed matching the data to be restored is found, a database operation statement for performing the inverse operation of the target operation statement is generated as the inverse operation statement.

[0084] For example, if the original operation statement executed on the database is an insert operation, a delete operation statement for the inserted data is generated to restore the database. If it is another database action, an UPDATE statement is generated to restore the data to be restored in the backup database to the database.

[0085] Case 2) If the first primary key to be restored is not found in the database and no corresponding statement to be changed is matched, the following can be implemented: Figure 5As shown, in S5022: based on the first primary key of the data to be restored in the local backup data, if the first primary key is not found in the database and the data to be changed that matches the data to be restored is not found, an insert statement is generated as the inverse operation statement; the insert statement is used to insert the data to be restored in the backup database into the database.

[0086] That is, if the current data is not found in the database based on the primary key information (i.e., the first primary key) in the local backup data, and the target operation statement is indeed a deletion operation, it can be considered that the data has been deleted, and an INSERT statement will be generated based on the backup data to perform data recovery.

[0087] In this embodiment, when the database loses required data, data recovery can be flexibly performed only for the required data.

[0088] Case 3), when the primary keys are inconsistent, it can be implemented as follows Figure 5 As shown, in S5023: when the data to be changed is found and the second primary key of the data to be changed in the database is inconsistent with the first primary key, the inverse operation statement including a delete statement and an insert statement is generated; wherein the delete statement is used to delete the data to be changed in the database; and the insert statement is used to insert the data to be restored in the backup database into the database.

[0089] For the same piece of data, you can confirm whether its primary key has changed based on the records of the backup data. If its primary key value has changed, the system will generate DELETE and INSERT statements to first delete the data with the changed primary key value, and then insert the data to be restored in the backup data.

[0090] In this embodiment, when the primary key is changed, the changed data can be identified, so as to accurately locate the data that needs to be changed and perform database recovery flexibly and accurately.

[0091] Case 4), when there is no primary key data, it can be implemented as follows Figure 5 As shown, including:

[0092] S5024: For the data to be recovered corresponding to the target operation statement, if the data to be recovered does not have a primary key, based on the uniqueness of the data to be recovered, query the database for multiple candidate data matching the data to be recovered.

[0093] S5025, based on the number of rows affected by the target operation statement, filter out candidate data of the number of rows from the multiple candidate data to generate the inverse operation statement; wherein the inverse operation statement is used to perform the inverse operation of the target operation statement on the filtered candidate data of the number of rows, and keep the candidate data of other rows in the multiple candidate data unchanged.

[0094] That is, when processing data without a primary key, multiple situations must be considered when performing recovery. Among them, the uniqueness of the data without a primary key itself is determined by the uniqueness of the whole row of the data set result (for example, the hash value of the data to be recovered can be obtained). If all the column fields of the row data are the same, the content of these rows is indistinguishable for the data without a primary key. When restoring the data, it is sufficient to restore the number of rows affected by the pre-recorded target operation statement.

[0095] For example, based on the data to be restored in the backup database, its hash value is solved, a query statement is generated in the corresponding table in the database, and multiple rows of data consistent with the data to be restored are queried to obtain multiple rows of candidate data.

[0096] Assume that m rows of candidate data are found, but only n rows of candidate data are modified when the target operation statement is executed, then only n rows out of the m rows need to be restored. Please refer to the following example:

[0097] For example, a table table1 has Column1 and Column2, but no primary key field. Assume that there are two rows in table1, as shown in Table 1:

[0098] Table 1

[0099] Column1 Column2 1 1 1 2

[0100] If you execute the modification statement update table1 set column2 = 1 where Column2 = 2

[0101] After running the change statement, the data in the table is converted to Table 2:

[0102] Table 2

[0103] Column1 Column2 1 1 1 1

[0104] If you want to restore the data at this time, if you execute the normal recovery statement update table1 set column2 = 2 where column2 = 1

[0105] Then two rows will be affected, and the original correct record will be modified. At this time, the reverse operation statement generated in the embodiment of the present disclosure is:

[0106] update table1 set column2=2where Column2=1and Column1=1limit 1.

[0107] Therefore, in the embodiment of the present disclosure, regardless of whether the restored statement is the original operation, for the case of no primary key, the data table can eventually restore the required data, thereby ensuring the normal operation of the business.

[0108] Case 5), forced recovery

[0109] This mainly focuses on the case of update data changes. If other columns are changed, the embodiment of the present disclosure supports the user to flexibly choose which columns to restore when performing recovery.

[0110] If a column is modified multiple times (that is, the current column is modified multiple times, which may be multiple modifications by the same user or multiple modifications by different users), in the embodiment of the present disclosure, the user can be supported to choose whether to perform a forced recovery operation. If the user chooses forced recovery, the data state of the column before the selected target operation statement is restored. If the user chooses not to force, the recovery action will not be performed on the column.

[0111] In addition, in order to be able to flexibly implement data recovery. In the embodiment of the present disclosure, the original parallel operation can be appropriately converted into a serial operation. For example, compared with simple data execution, a lot of query and data backup actions are added during data operations. Such actions will increase some additional consumption during the system execution process and change the execution order during the original SQL execution process. In response to this situation, the embodiment of the present disclosure provides a change lock mechanism for the SQL execution process. By analyzing the executed SQL, the table fields that need to be changed are analyzed, and then the change table is locked. When operating on the same object (ie, table), only serial execution is allowed, and operations on non-same objects can be executed in parallel. In the case where multiple tables are modified at the same time, a lock timeout mechanism of P seconds is used to prevent deadlock, where P is a positive integer.

[0112] The database operation statements will be executed in memory, and after adding shared locks, they will become serial execution. If multiple tables are nested, the locks may need to be nested with each other, which may easily cause deadlock, so a lock timeout mechanism is added based on P seconds.

[0113] In this way, for some special application scenarios, such as users updating product prices or attributes, which are not frequent operations, these infrequent operations can be converted to serial execution, which has little impact on operational efficiency, but can flexibly and accurately perform data backup and data recovery for each operation.

[0114] In general, the specific recovery process is as follows Figure 6 As shown:

[0115] S601, select the restore operation. Here, the user is supported to select the data to be restored.

[0116] S602, obtaining corresponding SQL information. That is, the server responds to the operation and can query the operation statement corresponding to the data to be restored, which can be understood as the target operation statement described above.

[0117] S603, check whether the modified table structure has changed. That is, compare whether the table structure of the operated table in the local backup data is consistent with the table structure of the corresponding table in the database. If not, execute S604, otherwise end the operation.

[0118] S604, obtaining current data and backup data according to the primary key information, that is, obtaining the data to be restored (ie, backup data) in the local backup data and the data to be changed (ie, current data) in the database according to the primary key information as described above.

[0119] S605, generating a corresponding insertion or deletion statement according to each data form, that is, generating a reverse operation statement of the corresponding reverse operation.

[0120] S606, executing the data change SQL, that is, executing the reverse operation statement.

[0121] S607, determine whether the execution is successful, if not, continue to execute S608, otherwise end the operation.

[0122] S608, the database operation is changed and rolled back. That is, when the reverse operation statement fails to be executed, the database is rolled back to a state where the reverse operation statement is not executed.

[0123] That is, in order to target the reverse operation statement, the solution of the embodiment of the present disclosure can also be executed as the target operation statement mentioned above.

[0124] Based on the same technical concept, the present disclosure provides a database misoperation recovery device 700, such as Figure 7 As shown, including:

[0125] The parsing module 701 is used to parse the target operation statement of the database to obtain the statement type, operation table and condition information of the target operation statement;

[0126] The determination module 702 is used to determine the backup timing corresponding to the statement type when the statement type is a target type; the backup timing is to back up after executing the target operation statement or to back up before executing the target operation statement;

[0127] The backup module 703 is used to execute the target operation statement in the database to update the database; and, at the backup time, based on the operation table and the condition information, back up the table structure and data content within the data range involved in the target operation statement to obtain local backup data;

[0128] A generating module 704, configured to generate an inverse operation statement of the target operation statement when it is determined that the target operation statement is an erroneous operation statement;

[0129] The recovery module 705 is used to execute the reverse operation statement on the database based on the local backup data.

[0130] In some embodiments, when the statement type is a first type of statement in the target type, the backup timing corresponding to the statement type is backup before executing the target operation statement; the first type of statement is used to change the existing data in the database;

[0131] In the case where the statement type is a second type of statement in the target type, the backup timing corresponding to the statement type is to back up after executing the target operation statement; the second type of statement is used to insert new data into the database.

[0132] In some embodiments, the backup module includes:

[0133] An acquisition unit, used to acquire the operation number and time information of the target operation statement;

[0134] The backup unit is used to record the operation number, the time information, the operation table, and the table structure of the operation table in a backup database, and to back up the data content within the data range to the operation table in the backup database according to the table structure of the operation table.

[0135] In some embodiments, it also includes:

[0136] A response module, configured to determine a candidate object in response to a user's recovery operation;

[0137] A verification module, used to verify the consistency between the table structure of the local backup data of the candidate object and the table structure of the candidate object in the database;

[0138] An output module, used for displaying the recovery status to the user based on the local backup data and the data in the database when the table structure is verified to be consistent;

[0139] An identification module, configured to determine at least one piece of data to be restored in the candidate object in response to a selection operation by a user;

[0140] The confirmation module is used to determine at least one operation statement in the operation record corresponding to the at least one piece of data to be recovered as an erroneous operation statement, wherein when the at least one operation statement includes the target operation statement, the target operation statement is determined to be the erroneous operation statement.

[0141] In some embodiments, the generating module comprises:

[0142] a second searching unit, configured to search, for the data to be restored corresponding to the target operation statement, and if the data to be restored has a primary key, search, in the database, for data to be modified that matches the first primary key of the data to be restored in the local backup data, to obtain a search result;

[0143] A generating unit is used to generate the inverse operation statement based on the search result.

[0144] In some embodiments, the generating unit is specifically configured to:

[0145] When the data to be modified is found and the second primary key of the data to be modified in the database is inconsistent with the first primary key, generating the reverse operation statement including a delete statement and an insert statement;

[0146] Wherein, the delete statement is used to delete the data to be changed in the database;

[0147] The insert statement is used to insert the data to be restored in the backup database into the database.

[0148] In some embodiments, the generating unit is specifically configured to: generate an insert statement as the inverse operation statement according to the first primary key of the data to be restored in the local backup data, if the first primary key is not found in the database and the data to be changed that matches the data to be restored is not found;

[0149] The insert statement is used to insert the data to be restored in the backup database into the database.

[0150] In some embodiments, the generating module is specifically used to:

[0151] For the data to be restored corresponding to the target operation statement, if the data to be restored does not have a primary key, based on the uniqueness of the data to be restored, querying the database for multiple candidate data matching the data to be restored;

[0152] Based on the number of rows affected by the target operation statement, selecting candidate data of the number of rows from the plurality of candidate data to generate the inverse operation statement;

[0153] The inverse operation statement is used to perform the inverse operation of the target operation statement on the selected candidate data of the number of rows, and keep the candidate data of other rows in the multiple candidate data unchanged.

[0154] After introducing various methods and devices according to exemplary embodiments of the present application, next, an electronic device according to another exemplary embodiment of the present application is introduced.

[0155] Those skilled in the art will appreciate that various aspects of the present application may be implemented as a system, method or program product. Therefore, various aspects of the present application may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to as "circuit", "module" or "system" herein.

[0156] In some possible implementations, the electronic device according to the present application may include at least one processor and at least one memory. The memory stores program code, and when the program code is executed by the processor, the processor executes the method for processing and / or querying network security information according to various exemplary implementations of the present application described above in this specification. For example, the processor may execute steps in the method for identifying an operation and maintenance failure.

[0157] Refer to the following Figure 8 hereinafter describes an electronic device 800 according to this embodiment of the present application. Figure 8 The electronic device 800 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0158] like Figure 8 As shown, the electronic device 800 is in the form of a general electronic device. The components of the electronic device 800 may include but are not limited to: the at least one processor 801, the at least one memory 802, and a bus 803 connecting different system components (including the memory 802 and the processor 801).

[0159] Bus 803 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a processor, or a local bus using any of a variety of bus architectures.

[0160] The memory 802 may include a readable medium in the form of a volatile memory, such as a random access memory (RAM) 8021 and / or a cache memory 8022 , and may further include a read-only memory (ROM) 8023 .

[0161] The memory 802 may also include a program / utility 8025 having a set (at least one) of program modules 8024, such program modules 8024 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0162] The electronic device 800 may also communicate with one or more external devices 804 (e.g., keyboards, pointing devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 800, and / or may communicate with any device (e.g., routers, modems, etc.) that enables the electronic device 800 to communicate with one or more other electronic devices. Such communication may be performed via an input / output (I / O) interface 805. Furthermore, the electronic device 800 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 806. As shown, the network adapter 806 communicates with other modules for the electronic device 800 via a bus 803. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 800, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.

[0163] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 802 including instructions, and the instructions can be executed by the processor 801 of the device 500 to complete the above-mentioned method for recovering from database misoperation. Optionally, the storage medium can be a non-transitory computer-readable storage medium, for example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0164] In an exemplary embodiment, a computer program product is also provided, including a computer program, and when the computer program is executed by the processor 801, the method for recovering from database misoperation as provided in the present application is implemented.

[0165] In an exemplary embodiment, various aspects of the recovery of a database misoperation provided by the present application can also be implemented in the form of a program product, which includes program code. When the program product is run on a computer device, the program code is used to enable the computer device to execute the steps of the method for recovering a database misoperation according to various exemplary embodiments of the present application described above in this specification.

[0166] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.

[0167] The program product of the method for identifying operation and maintenance faults of the embodiment of the present application can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on an electronic device. However, the program product of the present application is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0168] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein readable program code is carried. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the foregoing. A readable signal medium may also be any readable medium other than a readable storage medium, which may transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0169] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0170] The program code for performing the operations of the present application can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and also conventional procedural programming languages ​​such as "C" language or similar programming languages. The program code can be executed entirely on the user electronic device, partially on the user device, as an independent software package, partially on the user electronic device and partially on the remote electronic device, or entirely on the remote electronic device or server. In the case of a remote electronic device, the remote electronic device can be connected to the user electronic device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external electronic device (for example, using an Internet service provider to connect through the Internet).

[0171] It should be noted that, although several units or subunits of the device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units described above can be embodied in one unit. Conversely, the features and functions of one unit described above can be further divided into multiple units to be embodied.

[0172] In addition, although the operations of the method of the present application are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.

[0173] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0174] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable image scaling device to produce a machine, so that the instructions executed by the processor of the computer or other programmable image scaling device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0175] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable image scaling device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, the instruction device being implemented in the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0176] These computer program instructions may also be loaded onto a computer or other programmable device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0177] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.

[0178] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A method for recovering a database misoperation, comprising: Parsing the target operation statement of the database to obtain the statement type, operation table and condition information of the target operation statement; In the case where the statement type is a target type, determining a backup timing corresponding to the statement type; The backup timing is to back up after executing the target operation statement, or to back up before executing the target operation statement; Executing the target operation statement in the database to update the database; and, at the backup timing, backing up the table structure and data content within the data range involved in the target operation statement based on the operation table and the condition information to obtain partial backup data; In the case where it is determined that the target operation statement is an erroneous operation statement, generating an inverse operation statement of the target operation statement; The reverse operation statement is executed on the database based on the local backup data.

2. The method according to claim 1, wherein: In the case where the statement type is the first type of statement in the target type, the backup timing corresponding to the statement type is to back up before executing the target operation statement; The first type of statements are used to change existing data in the database; In the case where the statement type is a second type of statement in the target type, the backup timing corresponding to the statement type is to back up after executing the target operation statement; the second type of statement is used to insert new data into the database.

3. The method according to claim 1, wherein: The step of backing up the table structure and data content within the data range involved in the target operation statement based on the operation table and the condition information to obtain partial backup data includes: Obtaining the operation number and time information of the target operation statement; The operation number, the time information, the operation table, and the table structure of the operation table are recorded in association in a backup database, and the data content within the data range is backed up to the operation table in the backup database according to the table structure of the operation table.

4. The method according to claim 1, wherein: Determining that the target operation statement is an erroneous operation statement includes: In response to a restore operation by a user, determining a candidate object; Verifying the consistency between the table structure of the local backup data of the candidate object and the table structure of the candidate object in the database; When the table structure verification is consistent, the recovery status is displayed to the user based on the local backup data and the data in the database; In response to a selection operation by a user, determining at least one piece of data to be restored that needs to be restored in the candidate object; At least one operation statement in the operation record corresponding to the at least one piece of data to be recovered is respectively determined as an erroneous operation statement, wherein, when the at least one operation statement includes the target operation statement, the target operation statement is determined to be the erroneous operation statement.

5. The method according to any one of claims 1 to 4, wherein: The generating of the inverse operation statement of the target operation statement comprises: For the data to be restored corresponding to the target operation statement, if the data to be restored has a primary key, searching the database for data to be modified that matches the first primary key of the data to be restored in the local backup data to obtain a search result; Based on the search result, the inverse operation statement is generated.

6. The method according to claim 5, wherein: The generating the inverse operation statement based on the search result includes: When the data to be modified is found and the second primary key of the data to be modified in the database is inconsistent with the first primary key, generating the reverse operation statement including a delete statement and an insert statement; Wherein, the delete statement is used to delete the data to be changed in the database; The insert statement is used to insert the data to be restored in the backup database into the database.

7. The method according to claim 5, wherein: The generating of the inverse operation statement of the target operation statement comprises: For the data to be restored corresponding to the target operation statement, if the data to be restored does not have a primary key, based on the uniqueness of the data to be restored, querying the database for multiple candidate data matching the data to be restored; Based on the number of rows affected by the target operation statement, selecting candidate data of the number of rows from the plurality of candidate data to generate the inverse operation statement; The inverse operation statement is used to perform the inverse operation of the target operation statement on the selected candidate data of the number of rows, and keep the candidate data of other rows in the multiple candidate data unchanged.

8. A recovery device for database misoperation, comprising: A parsing module, used to parse the target operation statement of the database to obtain the statement type, operation table and condition information of the target operation statement; A determination module, configured to determine a backup opportunity corresponding to the statement type when the statement type is a target type; The backup timing is to back up after executing the target operation statement, or to back up before executing the target operation statement; A backup module, configured to execute the target operation statement in the database to update the database; and, at the backup timing, back up the table structure and data content within the data range involved in the target operation statement based on the operation table and the condition information to obtain local backup data; A generating module, configured to generate a reverse operation statement of the target operation statement when determining that the target operation statement is an erroneous operation statement; A recovery module is used to execute the reverse operation statement on the database based on the local backup data.

9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the method as claimed in any one of claims 1 to 7.

Citation Information

Cited By

  • Business data management method and device for online spreadsheet

    CN121501803A