CN111045868A - Method and device for automatically recovering database data - Google Patents

Method and device for automatically recovering database data Download PDF

Info

Publication number
CN111045868A
CN111045868A CN201911280100.3A CN201911280100A CN111045868A CN 111045868 A CN111045868 A CN 111045868A CN 201911280100 A CN201911280100 A CN 201911280100A CN 111045868 A CN111045868 A CN 111045868A
Authority
CN
China
Prior art keywords
preset
file
recovered
database
mistaken
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201911280100.3A
Other languages
Chinese (zh)
Other versions
CN111045868B (en
Inventor
谢麦善
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Zhongtongji Network Technology Co Ltd
Original Assignee
Shanghai Zhongtongji Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Zhongtongji Network Technology Co Ltd filed Critical Shanghai Zhongtongji Network Technology Co Ltd
Priority to CN201911280100.3A priority Critical patent/CN111045868B/en
Publication of CN111045868A publication Critical patent/CN111045868A/en
Application granted granted Critical
Publication of CN111045868B publication Critical patent/CN111045868B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1415Saving, restoring, recovering or retrying at system level
    • G06F11/1417Boot up procedures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1471Saving, restoring, recovering or retrying involving logging of persistent data for recovery
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to a method for automatically recovering database data, which comprises the following steps: judging whether the operation type is increased or not by executing a rollback command; when the judgment result shows that the added operation types are the mistaken updating operation and the mistaken deleting operation, the information of the database to be recovered is obtained; if the target operation type is the false update operation, executing a preset false update operation recovery program according to the database information to be recovered to obtain a false update recovery script file; if the target operation type is the mistaken deletion operation, executing a preset mistaken deletion operation recovery program according to the database information to be recovered to obtain a mistaken deletion recovery script file; and recovering the database corresponding to the database information to be recovered according to the mistaken updating recovery script file and/or the mistaken deletion recovery script file. By the method, after misoperation, an experienced professional is not required to be found, other tools are not required to be installed on the database, and the executable recovery script file can be obtained by operating on the database, so that time and labor are saved.

Description

Method and device for automatically recovering database data
Technical Field
The present application relates to the field of databases, and in particular, to a method and an apparatus for automatically recovering database data.
Background
With the rapid development of the internet, the mysql database is more and more widely applied, and more enterprises use the mysql database on the linux server. In actual use, however, there are always applications or human operations in the mysql database that result in erroneous updates to records or deletion of one or more records that cannot be rolled back quickly. This requires the assistance of a database administrator, however, each database administrator is not experienced the same. Even experienced database administrators require a significant amount of time to recover data. The database manager is required to have high professional ability, and the manual data recovery requires that the operation is not intelligent enough and the recovery time is long.
Disclosure of Invention
To overcome, at least to some extent, the problems in the related art, the present application provides an XX method and apparatus.
According to a first aspect of the present application, a method for automatically recovering database data is provided, which includes determining whether an operation type is added by executing a rollback command, and obtaining a first determination result; the rollback command is used for rolling back the history of the operation type;
when the first judgment result is yes, judging whether the increased operation types are target operation types or not to obtain a second judgment result; the target operation type is error updating operation or error deleting operation;
when the second judgment result is yes, acquiring the information of the database to be recovered;
if the target operation type is the false update operation, executing a preset false update operation recovery program according to the database information to be recovered to obtain a false update recovery script file; if the target operation type is the mistaken deletion operation, executing a preset mistaken deletion operation recovery program according to the database information to be recovered to obtain a mistaken deletion recovery script file;
and recovering the database corresponding to the database information to be recovered according to the mistakenly updated recovery script file and/or the mistakenly deleted recovery script file.
Preferably, the database information to be recovered includes a binary log location, a binary log name, and a start update time and an end update time of the mis-update operation;
the executing a preset mistaken updating operation recovery program according to the information of the database to be recovered to obtain a mistaken updating recovery script file comprises the following steps:
analyzing by using a binary log analysis command according to the binary log position, the binary log name, the update starting time and the update ending time to obtain a first analysis file;
assembling the word eyes in the first data table to be recovered corresponding to the error updating operation according to the information of the database to be recovered, and assigning the assembled result to a first preset variable; the first data table to be recovered is a table with data change caused by the error updating operation in the database corresponding to the information of the database to be recovered;
acquiring the column name of the first data table to be recovered according to the information of the database to be recovered and storing the column name of the first data table to be recovered in a first preset file;
and obtaining a mistaken updating recovery script file according to the first analysis file, the first preset variable and the first preset file and a preset text processing mode.
Preferably, the obtaining of the mistaken update recovery script file according to the first parsing file, the first preset variable, and the first preset file in a preset text processing manner includes:
counting the total number of the fields of the first data table to be restored and assigning the total number of the fields to a second preset variable according to a first preset assignment mode;
processing the content in the first preset file according to a first preset file processing mode to obtain a first processed file;
storing lines from the first preset variable to a preset field in the first analysis file to obtain a first processing analysis file;
reading an analysis text of the first processing analysis file, and storing the analysis text processed according to a first preset analysis text processing mode into a preset script file to obtain an initial mistakenly updated recovery script file;
and processing the initial mistaken updating recovery script file according to the content of the first processing file and a first preset script file processing mode to obtain a mistaken updating recovery script file.
Preferably, the database information to be recovered includes a binary log position, a binary log name, and a deletion start time and a deletion end time of the erroneous deletion operation;
the executing a preset mistaken deletion operation recovery program according to the information of the database to be recovered to obtain a mistaken deletion recovery script file comprises the following steps:
analyzing by using a binary log analysis command according to the binary log position, the binary log name, the deletion starting time and the deletion ending time to obtain a second analysis file;
assembling the word eyes in a second data table to be recovered corresponding to the mistaken deletion operation according to the information of the database to be recovered, and assigning an assembled result to a second preset variable; the second to-be-recovered data table is a table with data change caused by the mistaken deletion operation in the database corresponding to the to-be-recovered database information;
acquiring the column name of the second data table to be recovered according to the information of the database to be recovered and storing the column name of the second data table to be recovered in a second preset file;
and obtaining a mistaken deletion recovery script file according to the second analysis file, the second preset variable and the second preset file in a preset text processing mode.
Preferably, the obtaining of the mistaken deletion recovery script file according to the second parsing file, the second preset variable, and the second preset file in a preset text processing manner includes:
counting the total number of the fields of the second data table to be restored and assigning the total number of the fields to a second preset variable according to a second preset assignment mode;
processing the content in the second preset file according to a second preset file processing mode to obtain a second processed file;
storing lines from the second preset variable to a preset field in the second analysis file to obtain a second processing analysis file;
reading an analysis text of the second processing analysis file, and storing the analysis text processed according to a second preset analysis text processing mode in a preset script file to obtain an initial mistakenly deleted recovery script file;
and processing the initial mistaken deletion recovery script file according to the content of the second processing file and a second preset script file processing mode to obtain a mistaken deletion recovery script file.
According to a second aspect of the present application, there is provided an apparatus for automatic recovery of database data, comprising:
the judging module judges whether the operation type is increased or not by executing the rollback command to obtain a first judgment result; the rollback command is used for rolling back the history of the operation type;
the result module is used for judging whether the added operation types are the target operation types or not when the first judgment result is yes, and obtaining a second judgment result; the target operation type is error updating operation or error deleting operation;
the execution module is used for acquiring the information of the database to be recovered when the second judgment result is yes; if the target operation type is the false update operation, executing a preset false update operation recovery program according to the database information to be recovered to obtain a false update recovery script file; if the target operation type is the mistaken deletion operation, executing a preset mistaken deletion operation recovery program according to the database information to be recovered to obtain a mistaken deletion recovery script file;
and the recovery module recovers the database corresponding to the database information to be recovered according to the mistakenly updated recovery script file and/or the mistakenly deleted recovery script file.
Preferably, the database information to be recovered comprises a binary log position, a binary log name, and the start update time and the end update time of the mis-update operation;
the device for executing the preset mistaken updating operation recovery program according to the information of the database to be recovered to obtain the mistaken updating recovery script file comprises the following steps:
the first analysis module is used for analyzing by using a binary log analysis command according to the binary log position, the binary log name, the update starting time and the update ending time to obtain a first analysis file;
the first assignment module is used for assembling word eyes in a first data table to be recovered corresponding to the error updating operation according to the information of the database to be recovered and assigning an assembled result to a first preset variable; the first data table to be recovered is a table with data change caused by the error updating operation in the database corresponding to the information of the database to be recovered;
the first storage module is used for acquiring the column name of the first data table to be recovered according to the information of the database to be recovered and storing the column name of the first data table to be recovered in a first preset file;
and the first result module is used for obtaining the mistaken updating recovery script file according to the first analysis file, the first preset variable and the first preset file and a preset text processing mode.
Preferably, the device for obtaining the mistaken update recovery script file according to the first parsing file, the first preset variable and the first preset file in a preset text processing manner includes:
the second assignment module is used for counting the total number of the fields of the first data table to be restored and assigning the total number of the fields to a second preset variable according to a first preset assignment mode;
the first processing module is used for processing the content in the first preset file according to a first preset file processing mode to obtain a first processed file;
the second storage module is used for storing lines from the first preset variable to a preset field into the first analysis file to obtain a first processing analysis file;
the third storage module is used for reading the analytic text of the first processing analytic file and storing the analytic text processed according to the first preset analytic text processing mode into a preset script file to obtain an initial mistaken updating recovery script file;
and the first acquisition module is used for processing the initial mistaken updating recovery script file according to the content of the first processing file and a first preset script file processing mode to obtain a mistaken updating recovery script file.
Preferably, the database information to be recovered comprises a binary log position, a binary log name, and the start deletion time and the end deletion time of the false deletion operation;
the device for executing the preset mistaken deletion operation recovery program according to the database information to be recovered to obtain the mistaken deletion recovery script file comprises the following steps:
the second analysis module is used for analyzing according to the binary log position, the binary log name, the deletion starting time and the deletion ending time by using a binary log analysis command to obtain a second analysis file;
the third assignment module is used for assembling word eyes in a second data table to be recovered corresponding to the mistaken deletion operation according to the information of the database to be recovered and assigning an assembled result to a second preset variable; the second to-be-recovered data table is a table with data change caused by the mistaken deletion operation in the database corresponding to the to-be-recovered database information;
the fourth storage module is used for acquiring the column name of the second data table to be recovered according to the information of the database to be recovered and storing the column name of the second data table to be recovered in a second preset file;
and the second result module is used for obtaining the mistaken deletion recovery script file according to the second analysis file, the second preset variable and the second preset file and a preset text processing mode.
Preferably, the device for obtaining the mistaken deletion recovery script file according to the second parsing file, the second preset variable and the second preset file in a preset text processing manner includes:
the fourth assignment module is used for counting the total number of the fields of the second data table to be restored and assigning the total number of the fields to a second preset variable according to a second preset assignment mode;
the second processing module is used for processing the content in the second preset file according to a second preset file processing mode to obtain a second processed file;
a fifth storage module, configured to store lines from the second preset variable to a preset field in the second analysis file, so as to obtain a second processing analysis file;
the sixth storage module is used for reading the analytic text of the second processing analytic file and storing the analytic text processed according to a second preset analytic text processing mode into a preset script file to obtain an initial mistaken deletion recovery script file;
and the second acquisition module is used for processing the initial mistaken deletion recovery script file according to the content of the second processing file and a second preset script file processing mode to obtain a mistaken deletion recovery script file.
The technical scheme provided by the application can comprise the following beneficial effects: a method of automatic database data recovery, comprising: judging whether the operation type is increased or not by executing a rollback command, wherein the rollback command is used for rolling back the history of the operation type; when the judgment result is that the operation type is added, judging whether the added operation type is the error updating operation or the error deleting operation; when the judgment result shows that the added operation types are the mistaken updating operation and the mistaken deleting operation, the information of the database to be recovered is obtained; if the target operation type is the false update operation, executing a preset false update operation recovery program according to the database information to be recovered to obtain a false update recovery script file; if the target operation type is the mistaken deletion operation, executing a preset mistaken deletion operation recovery program according to the database information to be recovered to obtain a mistaken deletion recovery script file; and recovering the database corresponding to the database information to be recovered according to the mistakenly updated recovery script file and/or the mistakenly deleted recovery script file. By the method, after misoperation, an experienced professional is not required to be found, other tools are not required to be installed on the database, and the executable recovery script file can be obtained by operating on the database, so that time and labor are saved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and together with the description, serve to explain the principles of the application.
Fig. 1 is a flowchart of a method for automatically recovering database data according to an embodiment of the present application.
Fig. 2 is a flowchart of a method for automatically recovering database data according to a second embodiment of the present application.
Fig. 3 is a device for automatically recovering database data according to a third embodiment of the present application.
Fig. 4 is a device for obtaining a recovery script file for a false update according to a fourth embodiment of the present application.
Fig. 5 is a device for obtaining a recovery script file for an erroneous deletion according to a fifth embodiment of the present application.
Fig. 6 is a device for obtaining a recovery script file with an erroneous update according to a preset text processing method according to a sixth embodiment of the present application.
Fig. 7 is a device for obtaining a recovery script file deleted by mistake according to a preset text processing manner according to a seventh embodiment of the present application.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
Example one
Referring to fig. 1, fig. 1 is a flowchart illustrating a method for automatically recovering database data according to an embodiment of the present disclosure. As shown in fig. 1, the method for automatically recovering database data provided in this embodiment includes:
step 101, executing a rollback command to judge whether the operation type is increased.
The rollback command is used to rollback the history of the operation type.
102, judging whether the operation type is a target operation type or not when the judgment result is that the operation type is added; the target operation type is error updating operation or error deleting operation.
And 103, judging whether the operation type is the error updating operation or not when the judgment result is the target operation type.
And step 104, when the target operation type is the false update operation, acquiring the information of the database to be recovered, and executing a preset false update operation recovery program according to the information of the database to be recovered to obtain a false update recovery script file.
And 105, when the target operation type is not the mistaken updating operation, acquiring the information of the database to be recovered, and executing a preset mistaken deleting operation recovery program according to the information of the database to be recovered to obtain a mistaken deleting recovery script file.
By the method, after misoperation, an experienced professional is not required to be found, other tools are not required to be installed on the database, and the executable recovery script file can be obtained by operating on the database, so that time and labor are saved.
Example two
Referring to fig. 2, fig. 2 is a flowchart of a method for automatically recovering database data according to a second embodiment of the present application. As shown in fig. 2, the method for automatically recovering database data of this embodiment includes:
step 201, executing the rollback command to determine whether the operation type is increased.
The rollback command is used to rollback the history of the operation type.
And step 202, when the judgment result is that the operation type is added, judging whether the added operation type is the target operation type.
The target operation types are error updating operation and error deleting operation.
And step 203, judging whether the operation type is the error updating operation or not when the operation type is the target operation type.
And step 204, when the operation type is the error updating operation type, acquiring the information of the database to be recovered, wherein the information comprises the position of the binary log, the name of the binary log, and the starting updating time and the ending updating time of the error updating operation.
Specifically, f-input-tb-desc is executed to acquire the database information to be restored, including the binlog position and name, and the start and end times.
And step 205, analyzing by using a binary log analysis command according to the binary log position, the binary log name, the update starting time and the update ending time to obtain a first analysis file.
Specifically, a Mysql library analysis command carried by Mysql is used for analyzing the position and name of the binlog and the starting time and the ending time and storing the binlog position and the name and the starting time and the ending time in an analysis-binlog txt file under the current directory.
And step 206, assembling the word eyes in the first to-be-recovered data table corresponding to the error updating operation according to the to-be-recovered database information, and assigning an assembled result to a first preset variable.
And the first data table to be recovered is a table with data change caused by the error updating operation in the database corresponding to the information of the database to be recovered.
Specifically, word eyes in a table corresponding to the mistaken updating operation are assembled according to the f-input-tb-desc information of the database to be recovered, and an assembled result is assigned to the variable update-con.
And step 207, acquiring the column name of the first data table to be restored according to the information of the database to be restored, and storing the column name of the first data table to be restored in a first preset file.
Specifically, the column name of the data table to be recovered is obtained by using a MySQL command carried by MySQL according to the database information to be recovered obtained by the f-input-tb-desc, and the column name is stored in a tb-desc.
And 208, counting the total number of the fields of the first to-be-restored data table, and assigning the total number of the fields to a third preset variable according to a first preset assignment mode.
Specifically, a linux text processing command is used for reading tb-desc.
Step 209, processing the content in the first preset file according to a first preset file processing mode to obtain a first processed file.
Specifically, the column name in the tb-desc.txt file is increased by a character "using the linux text processing command, for example, coll is changed to coll.
Step 210, storing the line from the first preset variable to a preset field in the first analysis file to obtain a first processing analysis file.
Specifically, an analysis-binlog.txt file is read and lines between update-con to "COMMIT" and update-con to "# at" are transferred in the analysis-update.txt file.
Txt, add the corresponding field value in analysis-update to MySQL's own from-unixtime function.
And step 211, reading the analysis text of the first processing analysis file, and storing the analysis text processed according to the first preset analysis text processing mode in a preset script file to obtain an initial mistaken updating recovery script file.
Specifically, the ' WHERE ' prefixed with "#### ' recorded in each update in the analysis _ update.txt is exchanged with ' SET ' and the" ### "in each row is removed; the comments between "/" to "/" are replaced with ","; the row beginning with "# at" is replaced with "; "; the row corresponding to at _ col _ num is replaced by the "at"; "; replace "AND" for every line "between all" WHERE "to at _ col _ num; will "SET" to "WHERE"; "remove; the results are stored in rollback _ update.
Sql removes redundant information of the corresponding field in rollback-update if the integer field contains negative values, and only retains the correct negative values.
And 212, processing the initial mistaken updating recovery script file according to the content of the first processing file and a first preset script file processing mode to obtain a mistaken updating recovery script file.
Specifically, the corresponding line value of "at-n ═ in the rolback _ update.sql file is replaced with the line value of the tb _ desc.txt file, where n represents the nth line in the tb _ desc.txt file.
And step 213, when the target operation type is not the false update operation, acquiring the database information to be recovered, wherein the database information to be recovered comprises a binary log position, a binary log name, and the start deletion time and the end deletion time of the false deletion operation.
Specifically, f-input-tb-desc is executed to acquire the database information to be restored, including the binlog position and name, and the start and end times.
And 214, analyzing by using a binary log analysis command according to the binary log position, the binary log name, the deletion starting time and the deletion ending time to obtain a second analysis file.
Specifically, a Mysql library analysis command carried by Mysql is used for analyzing the position and name of the binlog and the starting time and the ending time and storing the binlog position and the name and the starting time and the ending time in an analysis-binlog txt file under the current directory.
Step 215, assembling the word eyes in the second to-be-recovered data table corresponding to the mistaken deletion operation according to the to-be-recovered database information, and assigning an assembled result to a second preset variable.
And the second to-be-recovered data table is a table with data change caused by the mistaken deletion operation in the database corresponding to the to-be-recovered database information.
Specifically, word eyes in a table corresponding to the mistaken deletion operation are assembled according to the f-input-tb-desc information of the database to be recovered, and an assembled result is assigned to the variable delete-con.
Step 216, obtaining the column name of the second data table to be restored according to the information of the database to be restored, and storing the column name of the second data table to be restored in a second preset file.
Specifically, the column name of the data table to be deleted is obtained by using a MySQL command carried by MySQL according to the database information to be recovered obtained by the f-input-tb-desc, and the column name is stored in a tb-desc.
And step 217, counting the total number of the fields of the second data table to be restored and assigning the total number of the fields to a fourth preset variable according to a second preset assignment mode.
Specifically, a linux text processing command is used for reading tb-desc.
Step 218, processing the content in the second preset file according to a second preset file processing mode to obtain a second processed file.
Specifically, the column name in the tb-desc.txt file is increased by a character "using the linux text processing command, for example, coll is changed to coll.
Step 219, storing the line from the second preset variable to the preset field in the second analysis file to obtain a second processing analysis file.
Specifically, an analysis-binlog. txt file is read and lines between delete-con to "COMMIT" and delete-con to "# at" are transferred in the analysis-delete. txt file.
Txt, add the corresponding field value in analysis-update to MySQL's own from-unixtime function.
And step 220, reading the analysis text of the second processing analysis file, and storing the analysis text processed according to the second preset analysis text processing mode in a preset script file to obtain an initial mistaken deletion recovery script file.
Specifically, exchange the "WHERE" prefixed with "####" of each delete record in the analysis _ delete.txt with "SET" and remove "###" in each row; the comments between "/" to "/" are replaced with ","; the row beginning with "# at" is replaced with "; "; the row corresponding to at _ col _ num is replaced by the "at"; "; replace "AND" for every line "between all" WHERE "to at _ col _ num; will "SET" to "WHERE"; "remove; the results are stored in rolback _ delete.
If the integer field contains a negative value, redundant information of the corresponding field in the rollback-delete.
And step 221, processing the initial mistaken deletion recovery script file according to the content of the second processing file and a second preset script file processing mode to obtain a mistaken deletion recovery script file.
Specifically, the corresponding line value of "at-n ═ in the rolback _ delete.sql file is replaced with the line value of the tb _ desc.txt file, where n represents the nth line in the tb _ desc.txt file.
In the embodiment, specific file names, names and the like mentioned in the embodiment can be replaced by professionals, and the embodiment belongs to the protection scope of the application.
EXAMPLE III
Referring to fig. 3, fig. 3 is a diagram illustrating an apparatus for automatically recovering database data according to a third embodiment of the present application. As shown in fig. 3, the apparatus for automatically restoring database data of the present embodiment includes:
the judging module 301 judges whether the operation type is increased by executing the rollback command, and obtains a first judgment result; the rollback command is used to rollback the history of the operation type.
A result module 302, configured to determine whether the added operation type is a target operation type when the first determination result is yes, and obtain a second determination result; the target operation type is error updating operation or error deleting operation.
The executing module 303, when the second judgment result is yes, acquiring information of the database to be recovered; if the target operation type is the false update operation, executing a preset false update operation recovery program according to the database information to be recovered to obtain a false update recovery script file; and if the target operation type is the mistaken deletion operation, executing a preset mistaken deletion operation recovery program according to the database information to be recovered to obtain a mistaken deletion recovery script file.
And the recovery module 304 is used for recovering the database corresponding to the information of the database to be recovered according to the mistakenly updated recovery script file and/or the mistakenly deleted recovery script file.
Example four
The database information to be recovered comprises the position of the binary log, the name of the binary log, and the starting updating time and the ending updating time of the error updating operation.
Referring to fig. 4, fig. 4 is a device for obtaining a recovery script file with an incorrect update according to a fourth embodiment of the present application. As shown in fig. 4, the apparatus for executing a preset mis-update operation recovery program according to the database information to be recovered to obtain a mis-update recovery script file includes:
the first parsing module 401 parses the binary log according to the binary log location, the binary log name, the update start time, and the update end time by using a binary log parsing command to obtain a first parsing file.
A first assignment module 402, which assembles a word eye in the first to-be-recovered data table corresponding to the mis-update operation according to the to-be-recovered database information and assigns an assembly result to a first preset variable; and the first data table to be recovered is a table with data change caused by the error updating operation in the database corresponding to the information of the database to be recovered.
The first storage module 403 acquires the column name of the first to-be-recovered data table according to the to-be-recovered database information, and stores the column name of the first to-be-recovered data table in a first preset file.
The first result module 404 obtains a false update recovery script file according to the first parsing file, the first preset variable, and the first preset file in a preset text processing manner.
EXAMPLE five
The database information to be recovered comprises the position of the binary log, the name of the binary log, and the starting deletion time and the ending deletion time of the mistaken deletion operation.
Referring to fig. 5, fig. 5 is a device for obtaining a recovery script file for an erroneous deletion according to a fifth embodiment of the present application. As shown in fig. 5, the apparatus for executing a preset mistaken deletion operation recovery program according to the information of the database to be recovered to obtain a mistaken deletion recovery script file includes:
the second parsing module 501 parses the binary log according to the binary log location, the binary log name, the deletion start time, and the deletion end time by using a binary log parsing command to obtain a second parsing file.
A third assignment module 502, which assembles the word eye in the second to-be-recovered data table corresponding to the mistaken deletion operation according to the to-be-recovered database information and assigns the assembled result to a second preset variable; and the second to-be-recovered data table is a table with data change caused by the mistaken deletion operation in the database corresponding to the to-be-recovered database information.
The fourth storage module 503 acquires the column name of the second data table to be restored according to the information of the database to be restored and stores the column name of the second data table to be restored in a second preset file.
And a second result module 504, configured to obtain the mistaken deletion recovery script file according to the second parsing file, the second preset variable, and the second preset file in a preset text processing manner.
EXAMPLE six
The embodiment is a device for obtaining the mistaken update recovery script file according to a preset text processing mode on the basis of the fourth embodiment.
Referring to fig. 6, fig. 6 is a device for obtaining a recovery script file with an incorrect update according to a preset text processing method according to a sixth embodiment of the present application.
As shown in fig. 6, the apparatus for obtaining the mis-update recovery script file according to the first parsing file, the first preset variable, and the first preset file and according to the preset text processing manner includes:
the second assigning module 601 is configured to count a total number of fields of the first to-be-restored data table and assign the total number of fields to a second preset variable according to a first preset assigning mode.
The first processing module 602 processes the content in the first preset file according to a first preset file processing manner to obtain a first processed file.
The second storage module 603 stores lines from the first preset variable to a preset field in the first analysis file to obtain a first processing analysis file.
The third storage module 604 reads the parsing text of the first processing parsing file, and stores the parsing text processed according to the first preset parsing text processing mode in a preset script file, so as to obtain an initial mistaken update recovery script file.
The first obtaining module 605 processes the initial mis-update recovery script file according to the content of the first processing file and a first preset script file processing mode to obtain a mis-update recovery script file.
EXAMPLE seven
The embodiment is a device for obtaining the mistaken deletion recovery script file according to a preset text processing mode on the basis of the fifth embodiment.
Referring to fig. 7, fig. 7 is a device for obtaining a recovery script according to a preset text processing manner according to a seventh embodiment of the present application.
As shown in fig. 7, the apparatus for obtaining the mistaken deletion recovery script file according to the second parsing file, the second preset variable, and the second preset file in a preset text processing manner includes:
a fourth assignment module 701, configured to count a total number of fields of the second to-be-restored data table and assign the total number of fields to a second preset variable according to a second preset assignment mode;
a second processing module 702, configured to process the content in the second preset file according to a second preset file processing manner to obtain a second processed file;
a fifth storage module 703, configured to store a line from the second preset variable to a preset field in the second analysis file, so as to obtain a second processing analysis file;
a sixth storage module 704, configured to read an analysis text of the second processing analysis file, and store the analysis text processed according to a second preset analysis text processing manner in a preset script file, so as to obtain an initial mistaken-deletion recovery script file;
the second obtaining module 705, according to the content of the second processing file and a second preset script file processing mode, processes the initial mistaken deletion recovery script file to obtain a mistaken deletion recovery script file.
It is understood that the same or similar parts in the above embodiments may be mutually referred to, and the same or similar parts in other embodiments may be referred to for the content which is not described in detail in some embodiments.
It should be noted that, in the description of the present application, the terms "first", "second", etc. are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. Further, in the description of the present application, the meaning of "a plurality" means at least two unless otherwise specified.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing specific logical functions or steps of the process, and the scope of the preferred embodiments of the present application includes other implementations in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the present application.
It should be understood that portions of the present application may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
It will be understood by those skilled in the art that all or part of the steps carried by the method for implementing the above embodiments may be implemented by hardware related to instructions of a program, which may be stored in a computer readable storage medium, and when the program is executed, the program includes one or a combination of the steps of the method embodiments.
In addition, functional units in the embodiments of the present application may be integrated into one processing module, or each unit may exist alone physically, or two or more units are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may also be stored in a computer readable storage medium.
The storage medium mentioned above may be a read-only memory, a magnetic or optical disk, etc.
In the description herein, reference to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the application. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
Although embodiments of the present application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present application, and that variations, modifications, substitutions and alterations may be made to the above embodiments by those of ordinary skill in the art within the scope of the present application.

Claims (10)

1. A method for automatically recovering database data, comprising:
judging whether the operation type is increased or not by executing a rollback command to obtain a first judgment result; the rollback command is used for rolling back the history of the operation type;
when the first judgment result is yes, judging whether the increased operation types are target operation types or not to obtain a second judgment result; the target operation type is error updating operation or error deleting operation;
when the second judgment result is yes, acquiring the information of the database to be recovered;
if the target operation type is the false update operation, executing a preset false update operation recovery program according to the database information to be recovered to obtain a false update recovery script file; if the target operation type is the mistaken deletion operation, executing a preset mistaken deletion operation recovery program according to the database information to be recovered to obtain a mistaken deletion recovery script file;
and recovering the database corresponding to the database information to be recovered according to the mistakenly updated recovery script file and/or the mistakenly deleted recovery script file.
2. The method for automatically recovering database data according to claim 1, wherein the database information to be recovered comprises a binary log location, a binary log name, a start update time and an end update time of the mis-update operation;
the executing a preset mistaken updating operation recovery program according to the information of the database to be recovered to obtain a mistaken updating recovery script file comprises the following steps:
analyzing by using a binary log analysis command according to the binary log position, the binary log name, the update starting time and the update ending time to obtain a first analysis file;
assembling the word eyes in the first data table to be recovered corresponding to the error updating operation according to the information of the database to be recovered, and assigning the assembled result to a first preset variable; the first data table to be recovered is a table with data change caused by the error updating operation in the database corresponding to the information of the database to be recovered;
acquiring the column name of the first data table to be recovered according to the information of the database to be recovered and storing the column name of the first data table to be recovered in a first preset file;
and obtaining a mistaken updating recovery script file according to the first analysis file, the first preset variable and the first preset file and a preset text processing mode.
3. The method for automatically recovering database data according to claim 2, wherein the obtaining of the mis-update recovery script file according to the first parsing file, the first preset variable and the first preset file in a preset text processing manner comprises:
counting the total number of the fields of the first data table to be restored and assigning the total number of the fields to a third preset variable according to a first preset assignment mode;
processing the content in the first preset file according to a first preset file processing mode to obtain a first processed file;
storing lines from the first preset variable to a preset field in the first analysis file to obtain a first processing analysis file;
reading an analysis text of the first processing analysis file, and storing the analysis text processed according to a first preset analysis text processing mode into a preset script file to obtain an initial mistakenly updated recovery script file;
and processing the initial mistaken updating recovery script file according to the content of the first processing file and a first preset script file processing mode to obtain a mistaken updating recovery script file.
4. The method for automatically recovering database data according to claim 1, wherein the database information to be recovered comprises a binary log location, a binary log name, a start deletion time and an end deletion time of the mis-deletion operation;
the executing a preset mistaken deletion operation recovery program according to the information of the database to be recovered to obtain a mistaken deletion recovery script file comprises the following steps:
analyzing by using a binary log analysis command according to the binary log position, the binary log name, the deletion starting time and the deletion ending time to obtain a second analysis file;
assembling the word eyes in a second data table to be recovered corresponding to the mistaken deletion operation according to the information of the database to be recovered, and assigning an assembled result to a second preset variable; the second to-be-recovered data table is a table with data change caused by the mistaken deletion operation in the database corresponding to the to-be-recovered database information;
acquiring the column name of the second data table to be recovered according to the information of the database to be recovered and storing the column name of the second data table to be recovered in a second preset file;
and obtaining a mistaken deletion recovery script file according to the second analysis file, the second preset variable and the second preset file in a preset text processing mode.
5. The method for automatically recovering database data according to claim 4, wherein the obtaining of the mistaken deletion recovery script file according to the second parsing file, the second preset variable and the second preset file in a preset text processing manner includes:
counting the total number of the fields of the second data table to be restored and assigning the total number of the fields to a second preset variable according to a second preset assignment mode;
processing the content in the second preset file according to a second preset file processing mode to obtain a second processed file;
storing lines from the second preset variable to a preset field in the second analysis file to obtain a second processing analysis file;
reading an analysis text of the second processing analysis file, and storing the analysis text processed according to a second preset analysis text processing mode in a preset script file to obtain an initial mistakenly deleted recovery script file;
and processing the initial mistaken deletion recovery script file according to the content of the second processing file and a second preset script file processing mode to obtain a mistaken deletion recovery script file.
6. An apparatus for automatic recovery of database data, comprising:
the judging module judges whether the operation type is increased or not by executing the rollback command to obtain a first judgment result; the rollback command is used for rolling back the history of the operation type;
the result module is used for judging whether the added operation types are the target operation types or not when the first judgment result is yes, and obtaining a second judgment result; the target operation type is error updating operation or error deleting operation;
the execution module is used for acquiring the information of the database to be recovered when the second judgment result is yes; if the target operation type is the false update operation, executing a preset false update operation recovery program according to the database information to be recovered to obtain a false update recovery script file; if the target operation type is the mistaken deletion operation, executing a preset mistaken deletion operation recovery program according to the database information to be recovered to obtain a mistaken deletion recovery script file;
and the recovery module recovers the database corresponding to the database information to be recovered according to the mistakenly updated recovery script file and/or the mistakenly deleted recovery script file.
7. The apparatus for automatically recovering database data according to claim 6, wherein the database information to be recovered includes a binary log location, a binary log name, a start update time and an end update time of the mis-update operation;
the device for executing the preset mistaken updating operation recovery program according to the information of the database to be recovered to obtain the mistaken updating recovery script file comprises the following steps:
the first analysis module is used for analyzing by using a binary log analysis command according to the binary log position, the binary log name, the update starting time and the update ending time to obtain a first analysis file;
the first assignment module is used for assembling word eyes in a first data table to be recovered corresponding to the error updating operation according to the information of the database to be recovered and assigning an assembled result to a first preset variable; the first data table to be recovered is a table with data change caused by the error updating operation in the database corresponding to the information of the database to be recovered;
the first storage module is used for acquiring the column name of the first data table to be recovered according to the information of the database to be recovered and storing the column name of the first data table to be recovered in a first preset file;
and the first result module is used for obtaining the mistaken updating recovery script file according to the first analysis file, the first preset variable and the first preset file and a preset text processing mode.
8. The apparatus for automatically restoring database data according to claim 7, wherein the apparatus for obtaining the mis-update recovery script file according to the first parsing file, the first preset variable and the first preset file in a preset text processing manner comprises:
the second assignment module is used for counting the total number of the fields of the first data table to be restored and assigning the total number of the fields to a second preset variable according to a first preset assignment mode;
the first processing module is used for processing the content in the first preset file according to a first preset file processing mode to obtain a first processed file;
the second storage module is used for storing lines from the first preset variable to a preset field into the first analysis file to obtain a first processing analysis file;
the third storage module is used for reading the analytic text of the first processing analytic file and storing the analytic text processed according to the first preset analytic text processing mode into a preset script file to obtain an initial mistaken updating recovery script file;
and the first acquisition module is used for processing the initial mistaken updating recovery script file according to the content of the first processing file and a first preset script file processing mode to obtain a mistaken updating recovery script file.
9. The apparatus for automatically recovering database data according to claim 6, wherein the database information to be recovered includes a binary log location, a binary log name, a start deletion time and an end deletion time of the mis-deletion operation;
the device for executing the preset mistaken deletion operation recovery program according to the database information to be recovered to obtain the mistaken deletion recovery script file comprises the following steps:
the second analysis module is used for analyzing according to the binary log position, the binary log name, the deletion starting time and the deletion ending time by using a binary log analysis command to obtain a second analysis file;
the third assignment module is used for assembling word eyes in a second data table to be recovered corresponding to the mistaken deletion operation according to the information of the database to be recovered and assigning an assembled result to a second preset variable; the second to-be-recovered data table is a table with data change caused by the mistaken deletion operation in the database corresponding to the to-be-recovered database information;
the fourth storage module is used for acquiring the column name of the second data table to be recovered according to the information of the database to be recovered and storing the column name of the second data table to be recovered in a second preset file;
and the second result module is used for obtaining the mistaken deletion recovery script file according to the second analysis file, the second preset variable and the second preset file and a preset text processing mode.
10. The apparatus for automatically recovering database data according to claim 9, wherein the means for obtaining the recovery script file for the mistaken deletion according to the second parsing file, the second preset variable and the second preset file in a preset text processing manner comprises:
the fourth assignment module is used for counting the total number of the fields of the second data table to be restored and assigning the total number of the fields to a second preset variable according to a second preset assignment mode;
the second processing module is used for processing the content in the second preset file according to a second preset file processing mode to obtain a second processed file;
a fifth storage module, configured to store lines from the second preset variable to a preset field in the second analysis file, so as to obtain a second processing analysis file;
the sixth storage module is used for reading the analytic text of the second processing analytic file and storing the analytic text processed according to a second preset analytic text processing mode into a preset script file to obtain an initial mistaken deletion recovery script file;
and the second acquisition module is used for processing the initial mistaken deletion recovery script file according to the content of the second processing file and a second preset script file processing mode to obtain a mistaken deletion recovery script file.
CN201911280100.3A 2019-12-13 2019-12-13 Method and device for automatically recovering database data Active CN111045868B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911280100.3A CN111045868B (en) 2019-12-13 2019-12-13 Method and device for automatically recovering database data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911280100.3A CN111045868B (en) 2019-12-13 2019-12-13 Method and device for automatically recovering database data

Publications (2)

Publication Number Publication Date
CN111045868A true CN111045868A (en) 2020-04-21
CN111045868B CN111045868B (en) 2023-12-05

Family

ID=70235947

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911280100.3A Active CN111045868B (en) 2019-12-13 2019-12-13 Method and device for automatically recovering database data

Country Status (1)

Country Link
CN (1) CN111045868B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117971565A (en) * 2024-03-29 2024-05-03 天津南大通用数据技术股份有限公司 Method and system for recovering misdeleted data of column storage distributed database

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101694637A (en) * 2009-11-06 2010-04-14 金蝶软件(中国)有限公司 Method and system for restoring database
CN103617277A (en) * 2013-12-09 2014-03-05 山东瀚高基础软件股份有限公司 Method for restoring data table content deleted mistakenly
US8874519B1 (en) * 2007-12-18 2014-10-28 Symantec Corporation Method and apparatus for restoring a table in a database
CN104765659A (en) * 2015-04-30 2015-07-08 北京奇虎科技有限公司 Data recovery method and device applied to database
CN108196980A (en) * 2017-12-28 2018-06-22 深圳市得微电子有限责任公司 Mistakenly deleted data recovery method, flash memory device and computer readable storage medium
CN109388523A (en) * 2018-09-26 2019-02-26 四川巧夺天工信息安全智能设备有限公司 A method of based on binary log file access pattern MySQL database
CN109634774A (en) * 2017-10-09 2019-04-16 北京国双科技有限公司 Data backup, restoration methods and device
CN109815233A (en) * 2018-12-27 2019-05-28 北京奇艺世纪科技有限公司 A kind of processing method and system of tables of data

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8874519B1 (en) * 2007-12-18 2014-10-28 Symantec Corporation Method and apparatus for restoring a table in a database
CN101694637A (en) * 2009-11-06 2010-04-14 金蝶软件(中国)有限公司 Method and system for restoring database
CN103617277A (en) * 2013-12-09 2014-03-05 山东瀚高基础软件股份有限公司 Method for restoring data table content deleted mistakenly
CN104765659A (en) * 2015-04-30 2015-07-08 北京奇虎科技有限公司 Data recovery method and device applied to database
CN109634774A (en) * 2017-10-09 2019-04-16 北京国双科技有限公司 Data backup, restoration methods and device
CN108196980A (en) * 2017-12-28 2018-06-22 深圳市得微电子有限责任公司 Mistakenly deleted data recovery method, flash memory device and computer readable storage medium
CN109388523A (en) * 2018-09-26 2019-02-26 四川巧夺天工信息安全智能设备有限公司 A method of based on binary log file access pattern MySQL database
CN109815233A (en) * 2018-12-27 2019-05-28 北京奇艺世纪科技有限公司 A kind of processing method and system of tables of data

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
黑马程序员: "《网页制作与网站建设实战教程》", 31 October 2018, pages: 346 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117971565A (en) * 2024-03-29 2024-05-03 天津南大通用数据技术股份有限公司 Method and system for recovering misdeleted data of column storage distributed database

Also Published As

Publication number Publication date
CN111045868B (en) 2023-12-05

Similar Documents

Publication Publication Date Title
JP4453323B2 (en) Replication data management method, apparatus, and program
CN109376142B (en) Data migration method and terminal equipment
CN111125298A (en) Method, equipment and storage medium for reconstructing NTFS file directory tree
CN113760476B (en) Task dependency processing method and related device
WO2017079619A1 (en) Method and apparatus for data processing
CN116149902A (en) Data recovery method and device, electronic equipment and computer readable storage medium
CN114721881B (en) Database management method, system, electronic device and storage medium
CN111045868B (en) Method and device for automatically recovering database data
CN112783749A (en) Static code scanning optimization method and device, electronic equipment and storage medium
CN112631826B (en) Backup processing method and device and computer readable storage medium
WO2017067397A1 (en) Data recovery method and device
CN111737331A (en) Transaction consistency processing method and system for database and object storage
CN109634845B (en) Method and device for generating context record text
CN113094208B (en) Method and system for realizing data recovery based on binding interface and Binlog log
CN110543452B (en) Data acquisition method and equipment
CN111698330B (en) Data recovery method and device of storage cluster and server
CN114625697A (en) File system recovery method and device, electronic equipment and storage medium
CN114996240A (en) Data table verification method, device, equipment, storage medium and program
CN109857519B (en) Processing method of virtual disk and related device
CN113326046A (en) Method and device for acquiring compiling time length
CN111221801A (en) Database migration method, system and related device
CN111142791A (en) Data migration method and device
CN112433738B (en) Firmware update test method, system, equipment and medium
CN113778997B (en) Database version management method, system and equipment
CN113127056B (en) Information processing method, device, equipment and readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant