CN112817798A - Data recovery method, device, medium and electronic equipment - Google Patents
Data recovery method, device, medium and electronic equipment Download PDFInfo
- Publication number
- CN112817798A CN112817798A CN202110217337.8A CN202110217337A CN112817798A CN 112817798 A CN112817798 A CN 112817798A CN 202110217337 A CN202110217337 A CN 202110217337A CN 112817798 A CN112817798 A CN 112817798A
- Authority
- CN
- China
- Prior art keywords
- information
- log file
- operation information
- name
- backup
- 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.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 40
- 238000011084 recovery Methods 0.000 title claims abstract description 24
- 230000004048 modification Effects 0.000 claims description 22
- 238000012986 modification Methods 0.000 claims description 22
- 238000004590 computer program Methods 0.000 claims description 9
- 230000006870 function Effects 0.000 description 9
- 238000010586 diagram Methods 0.000 description 7
- 238000012545 processing Methods 0.000 description 7
- 238000004891 communication Methods 0.000 description 6
- 230000003287 optical effect Effects 0.000 description 6
- 238000004458 analytical method Methods 0.000 description 4
- 230000008569 process Effects 0.000 description 3
- 239000013307 optical fiber Substances 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 230000010076 replication Effects 0.000 description 2
- 239000004065 semiconductor Substances 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 230000008520 organization Effects 0.000 description 1
- 238000005096 rolling process Methods 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/07—Responding to the occurrence of a fault, e.g. fault tolerance
- G06F11/14—Error detection or correction of the data by redundancy in operation
- G06F11/1402—Saving, restoring, recovering or retrying
- G06F11/1446—Point-in-time backing up or restoration of persistent data
- G06F11/1458—Management of the backup or restore process
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Data Mining & Analysis (AREA)
- Quality & Reliability (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The disclosure provides a data recovery method, device, medium and electronic equipment. According to the method and the device, the misoperation information is obtained from the backup log file, and the reverse rollback operation instruction is generated based on the misoperation information, so that the access burden of the operation log file is reduced. When the backup log file is stored in another server outside the database, the pressure of the database can be reduced, and the stable operation of the database can be ensured.
Description
Technical Field
The present disclosure relates to the field of data processing, and in particular, to a data recovery method, apparatus, medium, and electronic device.
Background
When the database is added, deleted or modified, misoperation is often caused, so that normal data is damaged, even important data is damaged, and irrecoverable mischief is caused.
After the misoperation is found, the original data is recovered by adopting a rollback operation mode. For example, before rolling back the mysql database, a binlog2SQL tool needs to be authorized, so that the binlog2SQL tool can read an information _ schema. For example, a mishandled SQL statement, a SQL statement required for rollback, an insert SQL statement with the primary key removed.
However, when log content is searched and analyzed on-line for the mysql instance, performance pressure is caused to the mysql instance, and particularly, the mysql database is accessed in a large amount and has many log files. When the binlog2sql tool works by adopting a single process, both the analysis operation and the rollback operation take a long time, so that the normal operation of the whole system is slowed down.
Disclosure of Invention
An object of the present disclosure is to provide a data recovery method, apparatus, medium, and electronic device, which can solve at least one of the above-mentioned technical problems. The specific scheme is as follows:
according to a specific embodiment of the present disclosure, in a first aspect, the present disclosure provides a data recovery method, including:
acquiring an operation time period, a library name of a target library and a table name of a target table;
obtaining meta information of a target table of a target library based on the library name and the table name;
acquiring operation information aiming at the target table in the backup log file within the operation time period;
generating an operation instruction corresponding to the operation information based on the operation information and the meta information;
judging whether the operation instruction is a misoperation instruction or not;
and if so, sequentially generating a rollback operation instruction based on the misoperation instructions according to the reverse order of the execution sequence of the misoperation instructions.
Optionally, the obtaining operation information of the backup log file for the target table in the operation time period includes:
judging whether a first operation time point of a first piece of operation information or a second operation time point of a last piece of operation information in the backup log file is within the operation time period or not;
and if so, acquiring the operation information aiming at the target table in the operation time period from the backup log file.
Optionally, the obtaining operation information for the target table in the operation time period from the backup log file includes:
acquiring first operation information in the operation time period in the backup log file;
analyzing the first operation information to obtain a first table name;
judging whether the first table name is matched with the table name of the target table;
and when the first table name is matched with the table name of the target table, determining the first operation information as the operation information.
Optionally, the obtaining, in the backup log file, first operation information in the operation time period includes:
acquiring second operation information in the backup log file;
analyzing the second operation information to obtain an operation time point of the second operation information;
when the operation time point is within the operation time period, determining that the second operation information is the first operation information.
Optionally, the obtaining of the meta information of the target table of the target repository based on the repository name and the table name includes:
and acquiring the meta information from a preset meta information file based on the library name and the table name.
Optionally, the obtaining of the meta information of the target table of the target repository based on the repository name and the table name includes:
generating a query meta-information obtaining instruction based on the library name and the table name;
and executing the meta information query instruction to obtain the meta information.
Optionally, the generating an operation instruction corresponding to the operation information based on the operation information and the meta information includes:
acquiring feature information and data information of the operation information based on the operation information, wherein the feature information comprises: the data information comprises a first corresponding relation between field serial numbers of the arrangement positions of the field names in the meta information and the field values;
acquiring corresponding instruction template information based on the operation type information and the operation condition information;
obtaining a second corresponding relation between the field sequence number and the field name from the meta information based on the field sequence number;
obtaining a third corresponding relation between the field name and the field value based on the first corresponding relation and the second corresponding relation;
and generating the operation instruction based on the instruction template information and the third corresponding relation.
Optionally, the method further includes:
and sequentially backing up the operation log files according to the modification time sequence of the operation log files to generate the backup log files.
Optionally, the method further includes:
and when the backup interruption is detected, the operation log file is backed up again.
Optionally, when detecting that the backup is interrupted, resuming the backup of the operation log file includes:
when the backup interruption is detected, acquiring the last modification time of the backup log file which is backed up last from the storage path of the backup log file;
obtaining the operation log file which is not backed up based on the last modification time from the storage path of the operation log file;
and continuing to backup the operation log file which is not backed up.
According to a second aspect, the present disclosure provides a data recovery apparatus, including:
a basic information acquisition unit for acquiring an operation time period, a library name of a target library and a table name of a target table;
a meta information acquiring unit configured to acquire meta information of a target table of a target library based on the library name and the table name;
an operation information obtaining unit, configured to obtain operation information for the target table in the backup log file within the operation time period;
an operation instruction generating unit configured to generate an operation instruction corresponding to the operation information based on the operation information and the meta information;
the instruction judging unit is used for judging whether the operation instruction is an misoperation instruction or not;
and if so, sequentially generating a rollback operation instruction based on the misoperation instructions according to a reverse order of the execution order of the misoperation instructions.
Optionally, the operation information obtaining unit includes:
a first judging subunit, configured to judge whether a first operation time point of a first piece of operation information or a second operation time point of a last piece of operation information in the backup log file is within the operation time period;
a first obtaining subunit, configured to obtain, from the backup log file, operation information for the target table in the operation time period.
Optionally, the first obtaining subunit includes:
the second obtaining subunit is configured to obtain, in the backup log file, first operation information in the operation time period;
the first obtaining subunit is used for analyzing the first operation information to obtain a first table name;
the second judgment subunit is used for judging whether the first table name is matched with the table name of the target table;
a first determining subunit, configured to determine that the first operation information is the operation information when the first table name matches the table name of the target table.
Optionally, the second obtaining subunit includes:
a third obtaining subunit, configured to obtain second operation information in the backup log file;
the second obtaining subunit is configured to analyze the second operation information to obtain an operation time point of the second operation information;
a second determining subunit, configured to determine that the second operation information is the first operation information when the operation time point is within the operation time period.
Optionally, the meta information obtaining unit includes:
and the meta information acquiring subunit is used for acquiring the meta information from a preset meta information file based on the library name and the table name.
Optionally, the meta information obtaining unit includes:
the instruction acquisition subunit is used for generating an instruction for acquiring the query meta information based on the library name and the table name;
and the meta-information obtaining subunit is used for executing the meta-information inquiring instruction to obtain the meta-information.
Optionally, the instruction generating unit includes:
an information analysis subunit, configured to obtain feature information and data information of the operation information based on the operation information, where the feature information includes: the data information comprises a first corresponding relation between field serial numbers of the arrangement positions of the field names in the meta information and the field values;
a template obtaining subunit, configured to obtain corresponding instruction template information based on the operation type information and the operation condition information;
a third obtaining subunit, configured to obtain, from the meta information, a second correspondence between the field sequence number and the field name based on the field sequence number;
a fourth obtaining subunit, configured to obtain a third corresponding relationship between the field name and the field value based on the first corresponding relationship and the second corresponding relationship;
and the instruction generating subunit is configured to generate the operation instruction based on the instruction template information and the third corresponding relationship.
Optionally, the apparatus further comprises:
and the log backup unit is used for sequentially backing up the operation log files according to the modification time sequence of the operation log files and generating the backup log files.
Optionally, the apparatus further comprises:
and the backup restarting unit is used for restarting the backup of the operation log file when the backup interruption is detected.
Optionally, the backup restart unit includes:
a time obtaining subunit, configured to, when a backup interruption is detected, obtain, from a storage path of the backup log file, a last modification time of the backup log file that was backed up last;
a remaining file acquiring subunit, configured to acquire an operation log file that is not backed up based on the last modification time from a storage path of the operation log file;
and the residual file backup subunit is used for continuously backing up the operation log file which is not backed up.
According to a third aspect, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a data recovery method as defined in any one of the first aspects.
According to a fourth aspect thereof, the present disclosure provides an electronic device, comprising: one or more processors; storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the data recovery method of any of the first aspects.
Compared with the prior art, the scheme of the embodiment of the disclosure at least has the following beneficial effects:
according to the method and the device, the misoperation information is obtained from the backup log file, and the reverse rollback operation instruction is generated based on the misoperation information, so that the access burden of the operation log file is reduced. When the backup log file is stored in another server outside the database, the pressure of the database can be reduced, and the stable operation of the database can be ensured.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and elements are not necessarily drawn to scale. In the drawings:
FIG. 1 shows a flow diagram of a data recovery method according to an embodiment of the present disclosure;
FIG. 2 illustrates a block diagram of elements of a data recovery apparatus, according to an embodiment of the present disclosure;
fig. 3 shows an electronic device connection structure schematic according to an embodiment of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
Alternative embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
The first embodiment provided by the present disclosure, namely, an embodiment of a data recovery method.
The embodiments of the present disclosure are described in detail below with reference to fig. 1.
Step S101, acquiring an operation time period, a library name of a target library and a table name of a target table.
The operation time period is used for finding the operation information in the time range from the backup log file.
The target library in the embodiment of the present disclosure is a relational database. The relational database is a database which organizes data by using a relational model and stores data in the form of rows and columns so as to be convenient for a user to understand, a series of rows and columns of the relational database are called data tables, and a group of data tables form the database. The relational model can be simply understood as a two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and relations therebetween, for example, MySQL database. The target table is a data table which needs to be rolled back in the target library.
For a large database application, a distributed database is typically employed. A distributed database system typically includes a plurality of computer systems, each of which may be individually located in a single location, and each of which may have a complete copy, or a partial copy, of the database management system, and has separate local databases, with many computers located at different locations interconnected via a network to form a complete, globally logically centralized, physically distributed, large database. The distributed database comprises at least one relational database, and each relational database is provided with an operation log file for recording operation information of the database. For example, a binary binlog log file in the MySQL database is used to record SQL statement (except for data query statements) information of user operations on the database.
The data table is composed of three parts of table name, field name and field value.
Step S102, obtaining the meta information of the target table of the target library based on the library name and the table name.
The meta information of the data table is definition information of the data table, and defines a table name of the data table and the data table including a field name, a field type, a field length and an interrelation between fields.
For example, the meta information of the data table is:
CREATE TABLE`person_table`(
`id`int(11)NOT NULL AUTO_INCREMENT,
"name" varchar (20) NOT NULL COMMENT 'name',
zone 'varchar (255) DEFAULT NULL COMMENT' region,
PRIMARY KEY(`id`),
KEY`views_zone_idx_dns`(`views`,`zone`)
)ENGINE=InnoDB AUTO_INCREMENT=6005DEFAULT CHARSET=utf8;
wherein, the 'person _ table' is a table name, the 'id', 'name' and 'zone' are field names, the 'int' and 'varchar' are field types, the field types comprise field lengths in the definition, and the arrangement sequence among the field indicates the mutual relationship among the field.
In a specific embodiment, the obtaining meta information of the target table of the target repository based on the repository name and the table name includes the following steps:
step S102a, obtaining the meta information from a preset meta information file based on the library name and the table name.
That is, the meta information file holds the meta information of the data table in advance. And when needed, retrieving corresponding meta information from the meta information file according to the library name of the target library and the table name of the target table.
In another specific embodiment, the obtaining meta information of the target table of the target repository based on the repository name and the table name includes the following steps:
step S102b-1, generating an instruction for acquiring query meta-information based on the library name and the table name.
Optionally, the query meta-information instruction is written by a data operation language.
For example, the data operation language is SQL language, and in MySQL database, the query meta information instruction is: "select table _ name, table _ comment _ schema, tables where table _ schema ═ library name 'and table _ name ═ table name'.
Step S102b-2, executing the query meta-information instruction to obtain the meta-information.
For example, the above SQL language is executed to obtain the meta information corresponding to the 'table name'.
The operation time period can be larger than the time range of misoperation, so that the phenomenon that the range is too narrow and misoperation information is missed is avoided.
The operation time period, the target library name and the target table name can be obtained through user interface input; or the data can be stored in a batch file in a batch processing mode and read from the batch file in batches; the disclosed embodiments are not limiting.
Step S103, acquiring operation information for the target table in the backup log file within the operation time period.
Wherein, the backup log file is a mirror image file of the operation log file. The embodiment of the disclosure acquires the misoperation information from the backup log file, and generates the reverse rollback operation instruction based on the misoperation information, thereby reducing the access burden aiming at the operation log file. When the backup log file is stored in another server outside the database, the pressure of the database can be reduced, and the stable operation of the database can be ensured.
Optionally, the obtaining operation information of the backup log file for the target table in the operation time period includes the following steps:
step S103-1, determining whether a first operation time point of a first piece of operation information or a second operation time point of a last piece of operation information in the backup log file is within the operation time period.
For a distributed database, there may be a plurality of operation log files, and correspondingly, there are a plurality of backup log files, the number of which is the same as that of the operation log files, and the plurality of backup log files are stored in a plurality of computers. The operating time point of at least one operating information in the first backup log file is within the operating time period, namely, the required backup log file.
The backup log file may be backed up in a different computer. While in the same computer, the backup log files may be backed up under different directories. In order to facilitate finding the backup log file, typically, the storage path of the backup log file is saved in a configuration file. The storage path includes a computer name or an IP address and a storage directory in the computer.
And step S103-2, if yes, acquiring the operation information aiming at the target table in the operation time period from the backup log file.
And when the first operation time point of the first piece of operation information or the second operation time point of the last piece of operation information in the backup file is within the operation time period, determining that at least one piece of operation information in the backup log file is the information aiming at the target table within the operation time period.
And determining a first backup log file according to the judgment of the first piece of operation information and the last piece of operation information in the backup file. The method avoids judging the operation information one by one, shortens the judging time and improves the execution efficiency.
Since the backup log file includes operations of a plurality of data tables. In order to generate a rollback operation instruction for a target table, the operation information for other data tables is removed, and the operation information for the target table in the operation time period is acquired.
Specifically, the obtaining of the operation information for the target table in the operation time period from the backup log file includes the following steps:
step S103-2-1, in the backup log file, acquiring first operation information in the operation time period.
In the backup log file, the operation information is arranged in time sequence, each line records one piece of operation information, and each piece of operation information includes an operation time point.
In a specific embodiment, the obtaining, in the backup log file, the first operation information in the operation time period includes the following steps:
and step S103-2-1-1, second operation information is acquired in the backup log file.
And step S103-2-1-2, analyzing the second operation information to obtain the operation time point of the second operation information.
For example, the second operation information records: "at the 19:05 time point, a piece of data with id of 5 and name of zhangjie is added in the staff table," wherein, the 19:05 time point "is the operation time point of the second operation information.
And step S103-2-1-3, when the operation time point is within the operation time period, determining that the second operation information is the first operation information.
For example, continuing the above example, when the operating period is: when the '19: 05 time point' is within the operation time period from 18:30 to 19:30, the second operation information is determined to be the first operation information, namely the second operation information meets the operation information of the operation time period.
And step S103-2-2, analyzing the first operation information to obtain a first table name.
For example, continuing the above example, the "people table" is the first table name.
And step S103-2-3, judging whether the first table name is matched with the table name of the target table.
Step S103-2-4, when the first table name is matched with the table name of the target table, determining that the first operation information is the operation information aiming at the target table in the operation time period.
And step S104, generating an operation instruction corresponding to the operation information based on the operation information and the meta information.
The operation instruction is written by a data operation language, for example, the data operation language is SQL language.
Specifically, the generating an operation instruction corresponding to the operation information based on the operation information and the meta information includes:
and step S104-1, acquiring characteristic information and data information of the operation information based on the operation information.
Wherein the feature information includes: table names, operation type information, and operation condition information, the data information including a first correspondence of field numbers of the arrangement positions of the field names in the meta information and the field values.
Where the field number is counted from the number "0".
For example, continuing the above example of meta information of the data table, the start time point of the operation period is "2020-12-17: 00:00 ", an end time point of" 2020-12-18: 00:00 ", a target table of" person _ table "; one piece of operation information is recorded in the backup log file: "2020-12-17: 30: 00", deleting data of which 0 is 8 in the person _ table, "the table name" person _ table, "operation type information" delete, "and the first correspondence relationship is" 0 is 8, "the field number" 0, "and the field value corresponding to the field number" 0 "is" 8.
And step S104-2, acquiring corresponding instruction template information based on the operation type information and the operation condition information.
The instruction template information is preset, and for example, the instruction template information corresponding to the above example is: delete from < table > where < data >; wherein, the sharp brackets are pending information.
And step S104-3, obtaining a second corresponding relation between the field sequence number and the field name from the meta information based on the field sequence number.
For example, continuing with the above example, the field name corresponding to the field sequence number "0" in the meta information of the data table "person _ table" is "id", i.e., the second correspondence.
And step S104-4, obtaining a third corresponding relation between the field name and the field value based on the first corresponding relation and the second corresponding relation of the words.
For example, continuing the above example, the field value corresponding to the field name "id" is determined to be "8" due to the above correspondence.
And step S104-5, generating the operation instruction based on the instruction template information and the third corresponding relation.
For example, continuing the above example, the operation command is "delete from person _ table where id is 8".
According to the embodiment of the disclosure, the preset instruction template information can be used for quickly generating the corresponding operation instruction based on the operation information, so that the information analysis time is reduced, and the data recovery efficiency is improved.
Step S105, judging whether the operation instruction is an misoperation instruction.
Usually, whether the operation instruction is the misoperation instruction is judged according to the misoperation time, so that the misoperation is avoided, and the reliability of data recovery is improved.
And step S106, if yes, sequentially generating a rollback operation instruction based on the misoperation instruction according to the reverse order of the execution order of the misoperation instruction.
Wherein the rollback operation instruction is written by the data operation language.
The execution sequence of the misoperation instructions can be obtained by the operation time of the corresponding operation information in the backup log file.
And executing the rollback operation instruction through the reverse order of the execution sequence of the misoperation instruction, recovering the data, meeting the logic requirement, avoiding data conflict and ensuring the normal and reliable operation of the data.
In order to reduce the influence of data recovery on the database, the method of the embodiment of the present disclosure further includes the following steps:
and step S111, sequentially backing up the operation log files according to the modification time sequence of the operation log files, and generating the backup log files.
The backup log file is also an image file of the operation log file.
For example, the MySQL log real-time binary Replication function in the MySQL database acquires the binary events in real time through the Replication API, and can realize the real-time and delay-free backup of the operation log file of the remote server.
Optionally, the method further comprises the following steps:
and step S121, when the interruption of the backup is detected, the operation log file is backed up again.
When the interruption is detected, the backup operation is restarted, the automatic pull-up function is realized, and the reliability and the real-time performance of the backup are ensured.
Optionally, when detecting that the backup is interrupted, resuming the backup of the operation log file includes the following steps:
step S121-1, when the backup interruption is detected, the last modification time of the backup log file which is backed up last is obtained from the storage path of the backup log file.
The modification time is attribute information of the file, and the last modification time of each file is recorded. The modification time of each operation log file is different. If the modification time of the backup log file under the second storage path is the maximum, the backup log file can be determined to be the backup log file backed up last.
And step S121-2, obtaining the operation log file which is not backed up based on the last modification time from the storage path of the operation log file.
Because the operation log files under the storage path of the operation log files are backed up according to the modification time sequence of the files, when the backup is interrupted, if the modification time of the operation log files is greater than the last modification time of the backup log files backed up last, the operation log files can be determined to be the operation log files which are not backed up.
And step S121-3, continuing to backup the operation log file which is not backed up.
The operation log file is backed up from the breakpoint, so that repeated backup is avoided, backup time is reduced, and backup efficiency is improved.
According to the embodiment of the invention, the misoperation information is obtained from the backup log file, and the reverse rollback operation instruction is generated based on the misoperation information, so that the access burden aiming at the operation log file is reduced. When the backup log file is stored in another server outside the database, the pressure of the database can be reduced, and the stable operation of the database can be ensured.
Corresponding to the first embodiment provided by the present disclosure, the present disclosure also provides a second embodiment, namely, a data recovery apparatus. Since the second embodiment is basically similar to the first embodiment, the description is simple, and the relevant portions should be referred to the corresponding description of the first embodiment. The device embodiments described below are merely illustrative.
Fig. 2 shows an embodiment of a data recovery apparatus provided by the present disclosure.
As shown in fig. 2, the present disclosure provides a data recovery apparatus including:
a basic information acquisition unit 201 for acquiring an operation time period, a library name of a target library, and a table name of a target table;
a meta information obtaining unit 202 configured to obtain meta information of a target table of a target library based on the library name and the table name;
an operation information obtaining unit 203, configured to obtain operation information for the target table in the backup log file within the operation time period;
an operation instruction generating unit 204 configured to generate an operation instruction corresponding to the operation information based on the operation information and the meta information;
an instruction judging unit 205, configured to judge whether the operation instruction is an erroneous operation instruction;
and if so, sequentially generating a rollback operation instruction based on the misoperation instructions according to a reverse order of the execution order of the misoperation instructions.
Optionally, the operation information obtaining unit 203 includes:
a first judging subunit, configured to judge whether a first operation time point of a first piece of operation information or a second operation time point of a last piece of operation information in the backup log file is within the operation time period;
a first obtaining subunit, configured to obtain, from the backup log file, operation information for the target table in the operation time period.
Optionally, the first obtaining subunit includes:
the second obtaining subunit is configured to obtain, in the backup log file, first operation information in the operation time period;
the first obtaining subunit is used for analyzing the first operation information to obtain a first table name;
the second judgment subunit is used for judging whether the first table name is matched with the table name of the target table;
a first determining subunit, configured to determine that the first operation information is the operation information when the first table name matches the table name of the target table.
Optionally, the second obtaining subunit includes:
a third obtaining subunit, configured to obtain second operation information in the backup log file;
the second obtaining subunit is configured to analyze the second operation information to obtain an operation time point of the second operation information;
a second determining subunit, configured to determine that the second operation information is the first operation information when the operation time point is within the operation time period.
Optionally, the meta information obtaining unit 202 includes:
and the meta information acquiring subunit is used for acquiring the meta information from a preset meta information file based on the library name and the table name.
Optionally, the meta information obtaining unit 202 includes:
the instruction acquisition subunit is used for generating an instruction for acquiring the query meta information based on the library name and the table name;
and the meta-information obtaining subunit is used for executing the meta-information inquiring instruction to obtain the meta-information.
Optionally, the instruction generating unit includes:
an information analysis subunit, configured to obtain feature information and data information of the operation information based on the operation information, where the feature information includes: the data information comprises a first corresponding relation between field serial numbers of the arrangement positions of the field names in the meta information and the field values;
a template obtaining subunit, configured to obtain corresponding instruction template information based on the operation type information and the operation condition information;
a third obtaining subunit, configured to obtain, from the meta information, a second correspondence between the field sequence number and the field name based on the field sequence number;
a fourth obtaining subunit, configured to obtain a third corresponding relationship between the field name and the field value based on the first corresponding relationship and the second corresponding relationship;
and the instruction generating subunit is configured to generate the operation instruction based on the instruction template information and the third corresponding relationship.
Optionally, the apparatus further comprises:
and the log backup unit is used for sequentially backing up the operation log files according to the modification time sequence of the operation log files and generating the backup log files.
Optionally, the apparatus further comprises:
and the backup restarting unit is used for restarting the backup of the operation log file when the backup interruption is detected.
Optionally, the backup restart unit includes:
a time obtaining subunit, configured to, when a backup interruption is detected, obtain, from a storage path of the backup log file, a last modification time of the backup log file that was backed up last;
a remaining file acquiring subunit, configured to acquire an operation log file that is not backed up based on the last modification time from a storage path of the operation log file;
and the residual file backup subunit is used for continuously backing up the operation log file which is not backed up.
According to the embodiment of the invention, the misoperation information is obtained from the backup log file, and the reverse rollback operation instruction is generated based on the misoperation information, so that the access burden aiming at the operation log file is reduced. When the backup log file is stored in another server outside the database, the pressure of the database can be reduced, and the stable operation of the database can be ensured.
An embodiment of the present disclosure provides a third embodiment, that is, an electronic device, where the electronic device is used in a data recovery method, and the electronic device includes: at least one processor; and a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the one processor to cause the at least one processor to perform the data recovery method of the first embodiment.
The disclosed embodiments provide a fourth embodiment, which is a data recovery computer storage medium storing computer-executable instructions that can execute the data recovery method as described in the first embodiment.
Referring now to FIG. 3, shown is a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 3 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 3, the electronic device may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 301 that may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)302 or a program loaded from a storage device 308 into a Random Access Memory (RAM) 303. In the RAM 303, various programs and data necessary for the operation of the electronic apparatus are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input/output (I/O) interface 305 is also connected to bus 304.
Generally, the following devices may be connected to the I/O interface 305: input devices 306 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 307 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage devices 308 including, for example, magnetic tape, hard disk, etc.; and a communication device 309. The communication means 309 may allow the electronic device to communicate wirelessly or by wire with other devices to exchange data. While fig. 3 illustrates an electronic device having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication means 309, or installed from the storage means 308, or installed from the ROM 302. The computer program, when executed by the processing device 301, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), systems on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.
Claims (16)
1. A method for data recovery, comprising:
acquiring an operation time period, a library name of a target library and a table name of a target table;
obtaining meta information of a target table of a target library based on the library name and the table name;
acquiring operation information aiming at the target table in the backup log file within the operation time period;
generating an operation instruction corresponding to the operation information based on the operation information and the meta information;
judging whether the operation instruction is a misoperation instruction or not;
and if so, sequentially generating a rollback operation instruction based on the misoperation instructions according to the reverse order of the execution sequence of the misoperation instructions.
2. The method of claim 1, wherein the obtaining operation information for the target table in the backup log file during the operation time period comprises:
judging whether a first operation time point of a first piece of operation information or a second operation time point of a last piece of operation information in the backup log file is within the operation time period or not;
and if so, acquiring the operation information aiming at the target table in the operation time period from the backup log file.
3. The method of claim 2, wherein the obtaining operation information for the target table in the operation time period from the backup log file comprises:
acquiring first operation information in the operation time period in the backup log file;
analyzing the first operation information to obtain a first table name;
judging whether the first table name is matched with the table name of the target table;
and when the first table name is matched with the table name of the target table, determining the first operation information as the operation information.
4. The method of claim 3, wherein the obtaining, in the backup log file, the first operation information in the operation time period comprises:
acquiring second operation information in the backup log file;
analyzing the second operation information to obtain an operation time point of the second operation information;
when the operation time point is within the operation time period, determining that the second operation information is the first operation information.
5. The method of claim 1, wherein obtaining meta information of a target table of a target repository based on the repository name and the table name comprises:
and acquiring the meta information from a preset meta information file based on the library name and the table name.
6. The method of claim 1, wherein obtaining meta information of a target table of a target repository based on the repository name and the table name comprises:
generating a query meta-information obtaining instruction based on the library name and the table name;
and executing the meta information query instruction to obtain the meta information.
7. The method of claim 1, wherein the generating the operation instruction corresponding to the operation information based on the operation information and the meta information comprises:
acquiring feature information and data information of the operation information based on the operation information, wherein the feature information comprises: the data information comprises a first corresponding relation between field serial numbers of the arrangement positions of the field names in the meta information and the field values;
acquiring corresponding instruction template information based on the operation type information and the operation condition information;
obtaining a second corresponding relation between the field sequence number and the field name from the meta information based on the field sequence number;
obtaining a third corresponding relation between the field name and the field value based on the first corresponding relation and the second corresponding relation;
and generating the operation instruction based on the instruction template information and the third corresponding relation.
8. The method of claim 1, further comprising:
and sequentially backing up the operation log files according to the modification time sequence of the operation log files to generate the backup log files.
9. The method of claim 8, further comprising:
and when the backup interruption is detected, the operation log file is backed up again.
10. The method of claim 9, wherein resuming the backup of the oplog file when the backup interruption is detected comprises:
when the backup interruption is detected, acquiring the last modification time of the backup log file which is backed up last from the storage path of the backup log file;
obtaining the operation log file which is not backed up based on the last modification time from the storage path of the operation log file;
and continuing to backup the operation log file which is not backed up.
11. A data recovery apparatus, comprising:
a basic information acquisition unit for acquiring an operation time period, a library name of a target library and a table name of a target table;
a meta information acquiring unit configured to acquire meta information of a target table of a target library based on the library name and the table name;
an operation information obtaining unit, configured to obtain operation information for the target table in the backup log file within the operation time period;
an operation instruction generating unit configured to generate an operation instruction corresponding to the operation information based on the operation information and the meta information;
the instruction judging unit is used for judging whether the operation instruction is an misoperation instruction or not;
and if so, sequentially generating a rollback operation instruction based on the misoperation instructions according to a reverse order of the execution order of the misoperation instructions.
12. The apparatus according to claim 11, wherein the operation information obtaining unit includes:
a first judging subunit, configured to judge whether a first operation time point of a first piece of operation information or a second operation time point of a last piece of operation information in the backup log file is within the operation time period;
a first obtaining subunit, configured to obtain, from the backup log file, operation information for the target table in the operation time period.
13. The apparatus of claim 12, wherein the first obtaining subunit comprises:
the second obtaining subunit is configured to obtain, in the backup log file, first operation information in the operation time period;
the first obtaining subunit is used for analyzing the first operation information to obtain a first table name;
the second judgment subunit is used for judging whether the first table name is matched with the table name of the target table;
a first determining subunit, configured to determine that the first operation information is the operation information when the first table name matches the table name of the target table.
14. The apparatus of claim 13, wherein the second obtaining subunit comprises:
a third obtaining subunit, configured to obtain second operation information in the backup log file;
the second obtaining subunit is configured to analyze the second operation information to obtain an operation time point of the second operation information;
a second determining subunit, configured to determine that the second operation information is the first operation information when the operation time point is within the operation time period.
15. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, carries out the method according to any one of claims 1 to 10.
16. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to carry out the method of any one of claims 1 to 10.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110217337.8A CN112817798A (en) | 2021-02-26 | 2021-02-26 | Data recovery method, device, medium and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110217337.8A CN112817798A (en) | 2021-02-26 | 2021-02-26 | Data recovery method, device, medium and electronic equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN112817798A true CN112817798A (en) | 2021-05-18 |
Family
ID=75864061
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110217337.8A Pending CN112817798A (en) | 2021-02-26 | 2021-02-26 | Data recovery method, device, medium and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112817798A (en) |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20160147616A1 (en) * | 2014-11-25 | 2016-05-26 | Andre Schefe | Recovery strategy with dynamic number of volumes |
CN106547801A (en) * | 2015-09-23 | 2017-03-29 | 北京奇虎科技有限公司 | Database data flash back method and apparatus |
CN110888718A (en) * | 2019-11-27 | 2020-03-17 | 武汉虹旭信息技术有限责任公司 | Method and device for realizing distributed transaction |
CN111176887A (en) * | 2018-11-09 | 2020-05-19 | 上海擎感智能科技有限公司 | MySQL misoperation rollback method, equipment and system |
WO2021012932A1 (en) * | 2019-07-22 | 2021-01-28 | 中兴通讯股份有限公司 | Transaction rollback method and device, database, system, and computer storage medium |
CN112306743A (en) * | 2019-07-26 | 2021-02-02 | 阿里巴巴集团控股有限公司 | Data processing method and device, electronic equipment and computer storage medium |
-
2021
- 2021-02-26 CN CN202110217337.8A patent/CN112817798A/en active Pending
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20160147616A1 (en) * | 2014-11-25 | 2016-05-26 | Andre Schefe | Recovery strategy with dynamic number of volumes |
CN106547801A (en) * | 2015-09-23 | 2017-03-29 | 北京奇虎科技有限公司 | Database data flash back method and apparatus |
CN111176887A (en) * | 2018-11-09 | 2020-05-19 | 上海擎感智能科技有限公司 | MySQL misoperation rollback method, equipment and system |
WO2021012932A1 (en) * | 2019-07-22 | 2021-01-28 | 中兴通讯股份有限公司 | Transaction rollback method and device, database, system, and computer storage medium |
CN112306743A (en) * | 2019-07-26 | 2021-02-02 | 阿里巴巴集团控股有限公司 | Data processing method and device, electronic equipment and computer storage medium |
CN110888718A (en) * | 2019-11-27 | 2020-03-17 | 武汉虹旭信息技术有限责任公司 | Method and device for realizing distributed transaction |
Non-Patent Citations (4)
Title |
---|
吴洪贵等: "《物联网应用系统开发》", vol. 1, 30 November 2012, 东软电子出版社, pages: 103 - 106 * |
王晓燕: "MySQL 数据库中误操作删除数据的恢复问题", 《办公自动化》, pages 45 * |
郭文明: "《数据库运维》", vol. 1, 31 December 2019, 国家开放大学出版社, pages: 220 - 227 * |
陈爱华: "SYBASE数据库磁盘镜像机制", 《河北林业科技》, pages 1 - 3 * |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10019536B2 (en) | Snapshot-consistent, in-memory graph instances in a multi-user database | |
US9811577B2 (en) | Asynchronous data replication using an external buffer table | |
US7933866B2 (en) | Systems, methods and software programs for data synchronization | |
CN109657174B (en) | Method and device for updating data | |
US11238011B2 (en) | Intelligent method to index storage system files accounting for snapshots | |
CN112948409A (en) | Data processing method and device, electronic equipment and storage medium | |
CN111176887A (en) | MySQL misoperation rollback method, equipment and system | |
CN111753141B (en) | Data management method and related equipment | |
CN113163023B (en) | Domain name management method, device, medium and electronic equipment | |
CN106776136A (en) | Data base processing method and device | |
US11522975B2 (en) | Double persistence layer using an in-memory map | |
US20160179866A1 (en) | Method and system to search logs that contain a massive number of entries | |
CN112948494A (en) | Data synchronization method and device, electronic equipment and computer readable medium | |
CN112817798A (en) | Data recovery method, device, medium and electronic equipment | |
CN118069745A (en) | SQL SERVER increment acquisition method, storage medium and equipment based on transaction log | |
CN113760600B (en) | Database backup method, database restoration method and related devices | |
CN113963763B (en) | Partition changing method and device for medical data storage | |
CN111291130A (en) | Hive table consistency checking method, system, equipment and storage medium | |
CN112685431B (en) | Asynchronous caching method, device, system, electronic equipment and storage medium | |
CN110413603B (en) | Method and device for determining repeated data, electronic equipment and computer storage medium | |
US20150220548A1 (en) | Searching for and retrieving files from a database using metadata defining accesses to files that do not modify the accessed file | |
CN118312501B (en) | Database version rollback method and device, electronic equipment and storage medium | |
US11526491B1 (en) | Method and system for collecting data from data sources with commit lag to maintain data consistency in a data store | |
CN117971827B (en) | Data table association method, device, electronic equipment and computer readable medium | |
US20230409594A1 (en) | Conditional replication of data |
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 |