Method for merging data of fast synchronization and abnormal rollback among multiple databases
By generating and compressing data script files on the front-end page, it supports the export and import of full or incremental data, records operation logs, and realizes fast synchronization and data merging for exception rollback between multiple databases. This solves the problems of cumbersome and error-prone synchronization and rollback operations in existing technologies and improves data recovery efficiency.
Patent Information
- Application Number
- CN202210754245.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-28
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2042-06-28
AI Technical Summary
The existing technology has the following technical problems in the synchronization and rollback process between multiple databases: In the existing technology, developers need to manually operate the method of exporting data synchronization and abnormal rollback merging data. In the existing technology, developers often find that the synchronization and abnormal rollback operations of data synchronization and abnormal rollback functions are cumbersome and error-prone, and cannot be quickly recovered when data is misoperated.
By providing table structure queries on the front-end page, data script files are generated and compressed, supporting full or incremental data export and import, recording operation logs, supporting one-click import and rollback operations, and using interfaces and shell scripts to realize synchronization between multiple databases and abnormal rollback and data merging.
It enables rapid synchronization and rollback merging of data across multiple databases, reducing human error, improving data recovery efficiency, reducing the possibility of misoperation, and providing detailed operation log query and rollback functions.
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of databases and provides a method for fast synchronization and abnormal rollback of merged data among multiple databases. BACKGROUND
[0002] The present application is applied to the field of microservice architecture. In the existing development process, we often forget to synchronize the relevant development data of the developer to other environments, whether other developers have synchronized the data of the table, and when operating the data, there may be operations such as forgetting to back up, etc. Therefore, it is necessary to manually query the log to filter out the SQL statements for rollback operation, and to judge whether the current environment data has new operation data changes and other operations. In some cases, the table data is directly modified from the database, which causes the system to be inaccessible and cannot be recovered.
[0003] For a long time, we have realized the synchronization and abnormal rollback function of the database script of different environments by means of the data developer operating the table data from the database level and manually judging the data rollback logic. It is not very convenient to use, the steps are relatively cumbersome, and it is more prone to problems. For example, we often find that a certain table used in development is suddenly emptied or some data is suddenly modified, and we developers may not know whether the data needs to be rolled back or not. If it needs to be rolled back, how do we roll back the data, and whether it will affect other developers who use the data of this table. At the same time, in some scenarios where data backup is forgotten or the database record log is not turned on, some data is modified or deleted by mistake and cannot be quickly recovered. Only by checking the system log to troubleshoot the relevant operation statements can we save time and effort. SUMMARY
[0004] The purpose of the present application is to solve the problem that when a file is generated from a database A and data is imported into a database B, if it is found that the imported data is incorrect, and the database B has a frequent item field, new data has been generated on the basis of the imported data, and direct rollback will cause errors.
[0005] In order to achieve the above purpose, the present application adopts the following technical means:
[0006] A method for fast synchronization and abnormal rollback of merged data among multiple databases, characterized in that it comprises the following steps:
[0007] Step 1: The table structure of database A is queried through an interface and displayed to the front page, providing a selection of exported tables for subsequent use;
[0008] Step 2: Click the export button according to the selected table name to obtain a data script file and compress all data script files to obtain a data script file compression package;
[0009] Step 3: Click the upload button of the exported data file, and import the data in the data script file into the corresponding table;
[0010] Step 4: If an exception occurs during the import process or the imported data is abnormal or not expected, select the current operation or a table under the current operation, and click the rollback button to rollback the table data;
[0011] Step 5: The operation log can be queried, including the basic information of the current operator and the detailed information of which tables are operated in the current operation;
[0012] In the above technical solution, the step 1 comprises the following steps:
[0013] Step 1.1: Configure the related information of an exportable table, including basic information, filtering information, condition information when updating the table, and field frequent item flag information;
[0014] The basic information includes the Chinese name and English name of the table;
[0015] The filtering information includes date, agency, and state, which can be used as field information for incremental data filtering,
[0016] The field frequent item flag information: If the field belongs to a frequent item, the modified data of the field needs to be retained in the rollback operation to retain the current real-time updated data, which can be used for subsequent query table information and display;
[0017] Step 1.2: The related information of the exportable table is queried through the interface and displayed in the foreground, which can be used for subsequent selection of the table and configuration according to the related information.
[0018] In the above technical solution, the step 2 comprises the following steps:
[0019] Step 2.1: According to the related information of the table displayed in step 1, select one or more tables whose related information needs to be exported;
[0020] Step 2.2: Configure the current table to export full data or incremental data according to the related information of the selected table data. If incremental data is selected, the filtering field of the incremental data needs to be selected. The field information comes from the filtering information of the exportable table in step 1.1, including the field frequent item flag information for the frequently updated field, which is used as the update basis in the subsequent rollback operation;
[0021] Step 2.3: After configuring all the selected table information according to step 2.2, click the export button to perform the data export operation, obtain the data script file, and compress all the data script files to obtain a data script file compression package;
[0022] Step 2.3.1: After the interface obtains the current table related information and full incremental information, the current export operation record is stored in the operation log table, such as operation type, operator, operation time, and the log ID record is recorded;
[0023] Step 2.3.2: After the interface obtains all selected tables and corresponding configuration information, a data file including table information and operation log ID information is generated and stored in the server specified path;
[0024] Step 2.3.3: Call the shell script to obtain the data file of step 2.5 and connect the database A server. In the shell script, the data export script file is exported by the command;
[0025] Step 2.3.4: After the data script file is exported, the current export operation record is stored in the operation log detail table according to the specific table information of the operation and the operation log ID information in the file;
[0026] Step 2.3.5: If the incremental or full table query has no data, directly return a prompt that the current export table has no data. If multiple tables are exported, no data file will be generated for the data without data, and other data files with data will be generated through step 2.3.6;
[0027] Step 2.3.6: According to the selected table, the corresponding table data file is directly generated, and the data script file is named after the table name. Finally, all the generated data files are compressed into a zip package, and the zip package is named after the export time. The generated data file is placed in the server fixed directory, and all the data script files are compressed into a data script file compression package, and the file is returned to the front-end page for saving.
[0028] In the above technical solution, the step 3 includes the following steps:
[0029] Step 3.1: Click the import button of the data script file compression package exported in step 2 to prepare to import the data script file into the database B;
[0030] Step 3.2: According to the import button, the uploaded data script file compression package is obtained. When the button is clicked, it is necessary to verify whether the data script file suffix is correct. If it is not correct, directly prompt that the uploaded file is abnormal, please upload again;
[0031] Step 3.3: After the verification in step 3.2, it is also necessary to judge whether there is a data script file with the same name in the data script file compression package. If there is a duplicate, directly return a prompt that there is a data script file duplication, please upload again;
[0032] Step 3.4: After the interface obtains the relevant information of the current import table, the full-delta information, the operation type, the operator, and the operation time, the current import operation record is stored in the operation log table, and the operation log ID is recorded;
[0033] Step 3.5: After the above step is verified, the code is first decompressed, and then all data script files are uploaded to the server through the code. At the same time, the corresponding table name is parsed from the data script file, and the related information table mentioned in step 1.1 is queried according to the table name to obtain the basic information of the uploaded table, the condition information of the operation time, the corresponding update field information, and whether the field information is frequently updated in real time. The operation log ID of step 3.4 is obtained, and all the above information is generated into a data file and saved to the specified path of the server;
[0034] Step 3.6: The shell script is called to connect the database B server and obtain the data file generated in step 3.5. The table basic information, update condition, field information, and operation log ID are obtained by parsing the data file, and the merge into statement is spliced according to the parsed content. If the data exists, it is updated, and if it does not exist, it is inserted;
[0035] Step 3.7: At the same time, a backup table is created according to the corresponding table name, so that the corresponding backup table can be found for data rollback in subsequent rollback operations.
[0036] Step 3.8: Then find the data script file uploaded in step 3.5 under the corresponding folder. First, create a corresponding temporary table according to the data file and insert the data in the data script file into the temporary table;
[0037] Step 3.9: According to the backup table generated in step 3.7 and the temporary table in step 3.8, the difference set and intersection set of the two tables can be obtained by MINUS and INTERSECT methods, and the corresponding data script file is generated, which is convenient for subsequent query log to query the updated data and inserted data of this operation, and for manual data checking in abnormal rollback operation;
[0038] Step 3.10: According to step 3.6, execute the merge into statement to insert the data to be imported into the corresponding table;
[0039] Step 3.11: After execution, the table information of the current import operation, the operation log ID information parsed in step 3.6, and the table name information of the backup table generated in step 3.7 are spliced into an insert statement and stored in the operation log detail table. The operation log table is associated through the operation log ID, and the temporary table information in step 3.8 is deleted.
[0040] In the technical solution, the step 4 comprises the following steps:
[0041] Step 4.1: For the rollback action of the import operation, the operation log list is queried, the information including the log information stored in step 3.4 is displayed, the import operation to be rolled back is selected by the operator or the operation time, all table data of the current operation execution can be batch-rolled back, or the detailed log information of the operation is viewed by clicking the operation log ID of the operation, the table information of the import operation in step 3.11 is displayed, the backup table name is selected, the table information in the detailed list is selected, the rollback button is clicked, and the rollback operation is performed;
[0042] Step 4.2: According to the selected rollback data, if the batch rollback is executed, according to the operation log ID, if the rollback of the specific table of the detailed table is selected, the operation log detail ID is transmitted, all table information involved in the selected import operation log and the corresponding backup table name are queried, and the backup table name is used to find the corresponding backup table in the database B for subsequent rollback operation;
[0043] Step 4.3: After the corresponding data is queried according to the selected operation log information, the current rollback operation record is stored in the operation log table, for example, the operation type, the operator, the operation time, and the operation log ID record;
[0044] Step 4.4: After all the table information and the corresponding backup table are queried in step 4.2, the information, the backup table name, and the operation log ID information in step 4.3 are generated into a data file and stored in the server specified path according to the table information;
[0045] The table name is queried in step 1.1. The related information table is obtained, such as the table name information, the condition information during the update operation, the corresponding update field information, and the information whether the field is frequently updated in real time;
[0046] Step 4.5: The shell script is called to obtain the data file information generated in step 4.4 and connect the database B server, and the rollback operation data script is executed in the script by the command;
[0047] Step 4.6: The table name information, the backup table name, the update condition information, and the configuration of the frequently updated field information are obtained by parsing the data file generated in step 4.5, the table data of the operation to be rolled back is backed up, and the current backup table name is recorded, the corresponding backup table data file is found according to the backup table name given during the current file uploading, the corresponding merge into statement is spliced according to the obtained related table configuration information including the frequently updated field, if the frequently updated field has new data, the new data is updated, and if the frequently updated field does not exist, the new data is inserted;
[0048] Step 4.7: After deleting the table data that needs to be rolled back, the backup statement is imported into the table, and the real-time updated or newly added data in the production is inserted into the table according to the spliced merge into data in step 4.6, and the current rollback operation record is stored in the operation log detail table according to the specific table information of the operation and the operation log ID information in the file, and the newly generated backup table name, etc.
[0049] Step 4.8: After rolling back the data script file, the current export operation record is stored in the operation log detail table according to the specific table information of the operation and the operation log ID information in the file.
[0050] The above technical solution comprises the following steps:
[0051] Step 5.1: Query all operation logs, including operator, operation time, operation type including import, export, rollback operation, etc.
[0052] Step 5.2: According to the selected operation log, the information of the related tables involved in this operation can be queried, that is, each operation involves multiple tables respectively as an operation record, the data file information of the current table operation can be queried, and the update data file and the deletion data file of the corresponding table can be generated for the import operation.
[0053] Because the application adopts the above technical solution, the following beneficial effects are achieved:
[0054] 1. One-key generation of corresponding data script files is realized, and there is no need to manually log in to the database to operate the data export file.
[0055] 2. When the import file is clicked, there is no need for manual backup operation, which avoids forgetting the backup operation and reduces the possibility of misoperation.
[0056] 3. In some scenarios where data backup is forgotten and the database record log is opened, some data is mismodified or deleted and cannot be quickly recovered, and only through the system log to investigate the relevant operation, the rollback operation of the application scheme can be performed to recover the data.
[0057] 4, In order to solve the problem that the table data needs to be manually exported by the developer when the development data is arranged on the test environment or the test environment data is synchronized, a one-key data generation function is developed from the front-end page, only the full or incremental table data to be exported is checked on the front page, and the export button is clicked, and then the corresponding data script compression package can be generated, so that the data on the production line or synchronized to other test environment can be quickly obtained, and at the same time, the single table or the entire current abnormal import operation can be matched to the corresponding log information according to the operation error data file during the online process, so that the corresponding backup file information is obtained for rollback operation, and the processing of the production data that may have been modified during the data rollback operation is also included. At the same time, all operations in this process and the operation log of a specific table can be clearly found.
[0058] 5, At this time, the operation time of the operator can be located through the log viewing operation of the scheme, and if rollback is needed, the data recovery can be directly performed by clicking the rollback operation. The operator can find the corresponding backup file to perform data rollback according to the operation log to be rolled back, and according to whether the frequently real-time modification flag information is selected on the page, it is confirmed that when the rollback operation is performed, if the data has been modified, how to roll back the current data, complete the recovery of abnormal data and retain the current modified data. Therefore, this method of selecting table data through the page solves the problem well. The developer only needs to select the corresponding table data on the front page, configure the full and incremental and incremental filtering fields and other attributes, and click the export button, and then the corresponding data file can be exported, and the data file can be imported into the required database through the import function. If the import data operation fails or abnormal update occurs, data rollback can also be performed, including merging and rolling back the production real-time modification data, and viewing the specific operation log and other operations. The direct database operation is placed on the page to perform the data export operation, which greatly solves the problem of operation errors caused by non-data developers directly operating the database. At the same time, when the manual operation is prone to errors and the data is updated in real time during the rollback, the backup file and the specific update rule can be found through the rollback of this scheme, the production data is synchronized in real time, and the error operation data is rolled back. DETAILED DESCRIPTION
[0059] The embodiments of the present application will be described in detail below. Although the present application will be described and illustrated by combining some specific embodiments, it should be noted that the present application is not limited to only these embodiments. On the contrary, the modifications or equivalent replacements of the present application should be covered in the scope of the claims of the present application.
[0060] Also, in order to better illustrate the present application, numerous specific details are given in the following detailed description. One skilled in the art will understand that the application can be practiced without these specific details.
[0061] In order to achieve the above-mentioned purpose, the present application adopts the following technical means:
[0062] A method for quickly synchronizing and merging data of exceptions in multiple databases, characterized in that it comprises the following steps:
[0063] Step 1: The table structure of database A is queried through an interface and displayed to the front page, providing a selection of exported tables for subsequent use;
[0064] Step 2: Click the export button according to the selected table name to obtain a data script file and compress all data script files to obtain a data script file compression package;
[0065] Step 3: Click the upload button to import the data in the data script file into the corresponding table;
[0066] Step 4: If an exception occurs during the import process or the imported data is abnormal or not the expected content, select the current operation or a certain table under the current operation and click the rollback button to rollback the table data;
[0067] Step 5: The operation log can be queried, including the basic information of the current operator and the detailed information of the tables operated by the current operation;
[0068] In the above technical solution, the step 1 comprises the following steps:
[0069] Step 1.1: Configure the related information of an exportable table, including basic information, filtering information, condition information when updating the table, and field frequent item flag information;
[0070] The basic information includes the Chinese name and English name of the table;
[0071] The filtering information includes date, agency, and state, which can be used as field information for incremental data filtering,
[0072] The field frequent item flag information: If the field belongs to a frequent item, the modified data of this field needs to be retained in the rollback operation to provide subsequent query table information and display.
[0073] Step 1.2: The related information of the exportable table is queried through an interface and displayed in the front page, which can be used for subsequent selection of the table and configuration according to the related information.
[0074] In the above technical solution, the step 2 comprises the following steps:
[0075] Step 2.1: According to the relevant information of the table displayed on the page in step 1, select one or more relevant information of the table to be exported;
[0076] Step 2.2: According to the selected table data, configure whether the current table is to export full data or incremental data, if incremental data, select the incremental data filtering field, here the field information comes from the exportable table filtering information in step 1.1, including the field frequent item flag information for frequently updated fields, which is used as the basis for updating in subsequent rollback operation;
[0077] Step 2.3: After configuring all selected table information according to step 2.2, click the export button to perform data export operation, get data script file, and compress all data script files to get data script file compression package;
[0078] Step 2.3.1: After the interface obtains the current table related information and full incremental information, store the current export operation record in the operation log table, such as operation type, operator, operation time, and log ID record;
[0079] Step 2.3.2: After the interface obtains all selected tables and corresponding configuration information, generate data file including table information and operation log ID information and store it in the specified path of the server;
[0080] Step 2.3.3: Call shell script to get data file in step 2.5 and connect database A server, export data script file through command in shell script;
[0081] Step 2.3.4: After exporting the data script file, store the current export operation record in the operation log detail table according to the specific table information of the operation and the operation log ID information in the file;
[0082] Step 2.3.5: If there is no data in the exported incremental or full table query, directly return a prompt that there is no data in the current export table, if multiple tables are exported, no data file will be generated, and other data files will be generated through step 2.3.6;
[0083] Step 2.3.6: According to the selected table, generate the corresponding table data file, and name the data script file with the table name; finally, compress all data files into a zip package, and name the zip package with the export time; and put the generated data file and all data script files into the server fixed directory, and return the file to the front end page for saving.
[0084] In the technical solution, the step 3 comprises the following steps:
[0085] Step 3.1: Click the import button of the data script file package derived in step 2, and prepare to import the data script file into the database B;
[0086] Step 3.2: According to the imported data script file package, the data script file suffix name is verified when the button is clicked. If it is incorrect, directly prompt that the uploaded file is abnormal, please upload again;
[0087] Step 3.3: After the verification in step 3.2, it is further judged whether there is a data script file with repeated name in the data script file package. If it is repeated, directly return a prompt that there is a data script file duplication, please upload again;
[0088] Step 3.4: After the interface obtains the related information of the current import table, the full incremental information, the operation type, the operator, the operation time, the current import operation record is stored in the operation log table, and the operation log ID is recorded;
[0089] Step 3.5: After the above steps are verified, the data script file is uploaded to the server through the code after decompression, and the corresponding table name is parsed according to the data script file. The related information table mentioned in step 1.1 is queried according to the table name to obtain the uploaded table basic information, the condition information of the operation, the corresponding update field information, and whether the field information is frequently updated in real time. The operation log ID of step 3.4 is obtained, and all the above information is generated into a data file and saved to the specified path of the server;
[0090] Step 3.6: The shell script is called to connect the database B server and obtain the data file generated in step 3.5. The table basic information, update condition, field information and operation log ID are obtained by parsing the data file. The merge into statement is spliced according to the parsed content. If the data exists, it is updated, and if it does not exist, it is inserted;
[0091] Step 3.7: At the same time, the backup table is created according to the corresponding table name, so that the corresponding backup table can be found for data rollback in subsequent rollback operation.
[0092] Step 3.8: Then find the data script file uploaded in step 3.5 under the corresponding folder. First, create a corresponding temporary table according to the data file, and insert the data in the data script file into the temporary table;
[0093] Step 3.9: According to the backup table generated in step 3.7 and the temporary table in step 3.8, the difference set and intersection of the two tables can be obtained by MINUS and INTERSECT method, and the corresponding data script file is generated, which facilitates subsequent query log to query the updated data and inserted data of this operation, and manual data checking when abnormal rollback operation is performed;
[0094] Step 3.10: According to the execution of merge into statement in step 3.6, the data to be imported is inserted into the corresponding table;
[0095] Step 3.11: After the execution, the table information of the current import operation, the operation log ID information parsed in step 3.6, and the table name information of the backup table generated in step 3.7 are spliced into an insert statement and stored in the operation log detail table, and the operation log table is associated through the operation log ID, and the information of the temporary table in step 3.8 is deleted.
[0096] In the above technical solution, the step 4 comprises the following steps:
[0097] Step 4.1: For rollback action of import operation, by querying operation log list, the information including the log information stored in step 3.4 is displayed, and the import operation to be rolled back can be selected by operation person or operation time to batch rollback all table data of the current operation execution or click the operation log ID of the operation to view the detail log information of this operation, display the table information of the import operation in step 3.11, backup table name, select certain table information in the detail list, and click the rollback button to perform rollback operation;
[0098] Step 4.2: According to the selected rollback data, if batch rollback is performed, according to the operation log ID, if the rollback of a specific table in the rollback detail table is selected, the selected import operation log involves all table information and corresponding backup table name are queried according to the input operation log detail ID, and the backup table name is used to find the corresponding backup table in database B for subsequent rollback operation;
[0099] Step 4.3: After the corresponding data is queried according to the selected operation log information, the current rollback operation record is stored in the operation log table, such as operation type, operation person, operation time, and operation log ID record;
[0100] Step 4.4: After querying all table information and corresponding backup table in step 4.2, the information, backup table name and operation log ID information in step 4.3 are generated into a data file and stored in a specified path of the server according to the table information;
[0101] The table name query step 1.1 mentioned related information table, get table name information, update operation condition information, corresponding update field information, and whether the frequent real-time update field information;
[0102] Step 4.5: call shell script to get data file information generated in step 4.4 and connect database B server, and rollback operation data script in the script through command;
[0103] Step 4.6: by parsing the data file generated in step 4.5, get table name information, backup table name, update condition information, configure frequent real-time update field information, first backup the table data to be rolled back, and record the current backup table name, at the same time, according to the backup table name given by the current file upload, find the corresponding backup table data file, and according to the related table configuration information including frequent real-time update field, splice the corresponding merge into statement, if there is new data in the frequent real-time update field, update it, if not, insert it;
[0104] Step 4.7: delete the table data to be rolled back, import the backup statement into the table, and insert the real-time update or new data on the production into the table according to the merge into data spliced in step 4.6, and according to the specific table information of the operation and the operation log ID information in the file, and the newly generated backup table name, store the current rollback operation record into the operation log detail table;
[0105] Step 4.8: after rolling back the data script file, according to the specific table information of the operation and the operation log ID information in the file, store the current export operation record into the operation log detail table;
[0106] In the above technical solution, the step 5 includes the following steps:
[0107] Step 5.1: query all operation logs, including operator, operation time, operation type including import, export, rollback operation, etc.;
[0108] Step 5.2: according to the selected operation log, query the information of the related tables involved in this operation, that is, each operation involves multiple tables respectively as an operation record, the data file information of the current table operation can be queried, and the update data file and the delete data file of the corresponding table can be generated for the import operation.
Claims
1. A method for fast synchronization and exception rollback merge data among multiple databases, characterized in that, The method comprises the following steps: Step 1: querying and displaying the database A table structure to the front page through an interface, so as to provide selection of exported tables for subsequent use; Step 2: clicking the export button according to the selected table name to obtain data script files and compress all the data script files to obtain a data script file compression package; Step 3: clicking the upload button to import the data in the data script files into the corresponding tables of the database B; Step 4: if an exception occurs during the import process or the imported data is abnormal or not the expected content, selecting the current operation or a table under the current operation and clicking the rollback button to rollback the table data; Before the rollback is performed, the system identifies the fields marked as frequent items in the target table according to the pre-configured "field frequent item flag information"; during the rollback process, the backup data is directly used to overwrite the non-frequent item fields; for the frequent item fields, if the fields have been updated by the production environment after the import, the latest values are retained, and only the non-frequent item fields or the frequent item fields that have not been updated are subjected to the rollback, so as to realize intelligent merging of abnormal data rollback and real-time production data; Step 5: the operation log can be queried, including the basic information of the current operator and the detailed information of the tables subjected to the current operation.
2. The method for fast synchronization and exception rollback of merged data among multiple databases according to claim 1, characterized in that, The step 1 comprises the following steps: Step 1.1: configuring the related information of a table that can be exported, and the related information comprises basic information, screening information, condition information when the table is updated, and field frequent item flag information; The basic information comprises a Chinese name and an English name of the table; The screening information comprises date, agency, and state, which can be used as field information for screening incremental data; The field frequent item flag information: if a field belongs to a frequent item, the modified data of the field needs to retain the current real-time updated data during the rollback operation, and can be used for subsequent query and display of table information; Step 1.2: querying and displaying the related information of the table that can be exported through an interface, so as to provide selection of the table and configuration according to the related information.
3. The method for fast synchronization and exception rollback of merged data among multiple databases according to claim 2, characterized in that, The step 2 comprises the following steps: Step 2.1: selecting one or more tables that need to be exported according to the related information of the tables displayed on the page in step 1; Step 2.2: configuring whether the current table exports full data or incremental data according to the related information of the selected table data, and if the incremental data is selected, the screening fields of the incremental data need to be selected, wherein the field information comes from the screening information of the table that can be exported in step 1.1, and the field frequent item flag information is marked on the frequently updated field, which is used as an update basis during the subsequent rollback operation; Step 2.3: after the information of all the selected tables is configured in step 2.2, clicking the export button to perform the data export operation, obtaining data script files, and compressing all the data script files to obtain a data script file compression package; Step 2.3.1: after the interface obtains the related information of the current table and the full / incremental information, storing the current export operation record in an operation log table, including the operation type, the operator, the operation time, and the log ID. Step 2.3.2: After the interface obtains all selected tables and corresponding configuration information, it stores the data file including table information and operation log ID information into the server specified path; Step 2.3.3: Call the shell script to obtain the data file of step 2.5 and connect the database A server. In the shell script, export the data script file through the command; Step 2.3.4: After exporting the data script file, store the current export operation record into the operation log detail table according to the specific table information of the operation and the operation log ID information in the file; Step 2.3.5: If the exported incremental or full table query has no data, directly return a prompt that the current export table has no data. If multiple tables are exported, no data file will be generated for the tables without data, and the data script files for the tables with data will be generated through step 2.3.6; Step 2.3.6: Directly generate the data script file for the selected table according to the selected table. The data script file is named after the table name. Finally, all the generated data script files are compressed into a data script file compression package, which is named after the export time. The data script file compression package is placed in the server fixed directory and returned to the front-end page for saving.
4. The method for fast synchronization and exception rollback of merged data among multiple databases according to claim 3, characterized in that, The step 3 includes the following steps: Step 3.1: Click the import button to prepare to import the data script file into the database B after the data script file compression package exported in step 2 is clicked; Step 3.2: According to the import button, obtain the uploaded data script file compression package. When the button is clicked, it is necessary to verify whether the data script file suffix is correct. If it is not correct, directly prompt that the uploaded file is abnormal, please upload again; Step 3.3: After the verification in step 3.2, it is also necessary to judge whether there are data script files with repeated names in the data script file compression package. If there are repeated files, directly return a prompt that there are repeated data script files, please upload again; Step 3.4: After obtaining the related information of the current import table, full / incremental information, operation type, operator, operation time, store the current import operation record into the operation log table and record the operation log ID; Step 3.5: After the above steps are verified, it is necessary to first decompress through the code, and then upload all the data script files to the server through the code. At the same time, parse the corresponding table name from the data script file, and call the query method to query the related information table mentioned in step 1.1 according to the table name to obtain the uploaded table basic information, condition information for updating, corresponding update field information, and whether the field information is frequently updated in real time. Get the operation log ID of step 3.4, and generate a data file including all the above information and save it to the server specified path; Step 3.6: Call the shell script to connect the database B server and obtain the data file generated in step 3.
5. Through the analysis of the data file, obtain the table basic information, update condition, field information and operation log ID. According to the parsed content, splice the merge into statement. If the data exists, update it, otherwise, insert it; Step 3.7: Backup tables are created according to the corresponding table names so that the corresponding backup tables can be found for data rollback in subsequent rollback operations; Step 3.8: The data script file uploaded in step 3.5 is found in the corresponding folder, and a corresponding temporary table is created according to the data file, and the data in the data script file is inserted into the temporary table; Step 3.9: According to the backup table generated in step 3.7 and the temporary table in step 3.8, the difference set and intersection of the two tables are obtained by MINUS and INTERSECT methods, and the corresponding data script file is generated, so that the updated data and inserted data of this operation can be queried in subsequent query logs, and manual data checking can be performed in abnormal rollback operations; Step 3.10: According to step 3.6, the merge into statement is executed to insert the data to be imported into the corresponding table; Step 3.11: After the execution, the table information of the current import operation, the operation log ID information parsed in step 3.6, and the table name information of the backup table generated in step 3.7 are spliced into an insert statement and stored in the operation log detail table, and the operation log table is associated through the operation log ID, and the temporary table information in step 3.8 is deleted.
5. The method for fast synchronization and exception rollback of merged data among multiple databases according to claim 4, characterized in that, The step 4 includes the following steps: Step 4.1: Only import operations have rollback actions, and the operation log list is queried to display information including the log information stored in step 3.
4. The import operation to be rolled back can be selected by the operator or the operation time to batch roll back all table data of the current operation execution, or the detailed log information of this operation can be viewed by clicking the operation log ID of the operation, and the table information of the import operation in step 3.11, the backup table name, and the specific table information in the detail list can be selected. Click the rollback button to perform the rollback operation; Step 4.2: According to the selected rollback data, if batch rollback is performed, the operation log ID is queried according to the selected rollback detail table, and if a specific table rollback is selected, the operation log detail ID is queried to obtain all table information and corresponding backup table name involved in the selected import operation log. The backup table name is used to find the corresponding backup table in database B for subsequent rollback operations; Step 4.3: After querying the corresponding data according to the selected operation log information, the current rollback operation record is stored in the operation log table, including the operation type, the operator, the operation time, and the operation log ID record; Step 4.4: After querying all table information and corresponding backup tables in step 4.2, the information, backup table name, and operation log ID information in step 4.3 are generated to generate a data file and store it in a specified path of the server; The table name query step 1.1 obtains information such as table name, condition information during update, corresponding update field information, and whether the field is frequently updated in real time; Step 4.5: The shell script is called to obtain the data file information generated in step 4.4 and connect to the database B server. In the script, the rollback operation data script is obtained by the command. Step 4.6: By parsing the data file generated in step 4.5, get the table name information, backup table name, update condition information, configure frequent real-time update field information, first backup the table data of the operation to be rolled back, record the current backup table name, and find the corresponding backup table data file according to the backup table name given when uploading the current file, and according to the relevant table configuration information including frequent real-time update field, splice the corresponding merge into statement, if there is new data in the frequent real-time update field, update it, if not, insert it; Step 4.7: After deleting the table data that needs to be rolled back, import the backup statement into the table, and insert the real-time update or new data on the production into the table according to the merge into data spliced in step 4.6, and according to the specific table information of the operation and the operation log ID information in the file, as well as the newly generated backup table name, store the current rollback operation record into the operation log detail table; Step 4.8: After rolling back the data script file, according to the specific table information of the operation and the operation log ID information in the file, store the current export operation record into the operation log detail table.
6. The method for fast synchronization and exception rollback of merged data among multiple databases according to claim 1, characterized in that, The step 5 includes the following steps: Step 5.1: Query all operation logs, including operator, operation time, operation type including import, export, rollback operation, etc. Step 5.2: According to the selected operation log, query the information of the related tables involved in this operation, that is, each operation involves multiple tables respectively as an operation record, the data file information of the current table operation can be queried, and for import operation, the update data file and delete data file of the corresponding table can be generated.
Citation Information
Patent Citations
Method for uploading data file
CN102457545A
Method and system for data synchronization of relational heterogeneous databases
CN103761318A
System and method for synchronizing structured data between relational databases
CN108052681A
General data entry method and device based on data model, equipment and medium
CN114510478A