CN110874287A - Method and device for backing up and recovering data in database and electronic equipment - Google Patents

Method and device for backing up and recovering data in database and electronic equipment Download PDF

Info

Publication number
CN110874287A
CN110874287A CN201811014535.9A CN201811014535A CN110874287A CN 110874287 A CN110874287 A CN 110874287A CN 201811014535 A CN201811014535 A CN 201811014535A CN 110874287 A CN110874287 A CN 110874287A
Authority
CN
China
Prior art keywords
backup
database
data
checkpoint
file
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
CN201811014535.9A
Other languages
Chinese (zh)
Other versions
CN110874287B (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.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding 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 Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201811014535.9A priority Critical patent/CN110874287B/en
Publication of CN110874287A publication Critical patent/CN110874287A/en
Application granted granted Critical
Publication of CN110874287B publication Critical patent/CN110874287B/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/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore

Abstract

The embodiment of the invention provides a method and a device for backing up and recovering data in a database and electronic equipment, wherein the backing up method comprises the following steps: creating backup checkpoints in a database, all old checkpoints except the backup checkpoints being automatically deleted after a new checkpoint is created; generating a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup checkpoint operation; copying the backup metadata file and the table data file to a backup storage path; and marking the database to be in a backup stage in the process of generating and copying the backup metadata file and the table data file to a backup storage path so as to enable other components of the database to enter a preset backup working state. The scheme of the embodiment of the invention can effectively solve the problem that the storage space occupied by the data file and the Journal log is rapidly increased during the database backup.

Description

Method and device for backing up and recovering data in database and electronic equipment
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for backing up and restoring data in a database, and an electronic device.
Background
Contemporary databases often use checkpoint (checkpoint) techniques to achieve persistence of data. In addition to checkpoint technology, contemporary databases also typically use Journal logs to achieve finer grained data persistence.
checkpoint technology can be used to implement backup recovery in addition to data persistence. In the backup process, the database closes the automatic deleting function of the checkpoint (a new checkpoint is still automatically created periodically), and simultaneously closes the automatic deleting function of the Journal log file. If the database still continues to provide normal services, the storage space occupied by the data file and the Journal log will grow quickly because the old checkpoint and Journal log files are not deleted. Therefore, there are also existing solutions that add a global write lock to the database during the backup process and suspend the continued provision of services, but this sacrifices the availability of services and has a greater impact.
Disclosure of Invention
The invention provides a method, a device and electronic equipment for backing up and recovering data in a database, which can effectively solve the problem that the storage space occupied by a data file and a Journal log is rapidly increased during the backing up of the database.
In order to achieve the above purpose, the embodiment of the invention adopts the following technical scheme:
in a first aspect, a method for backing up data in a database is provided, which includes:
creating backup checkpoints in a database, all old checkpoints except the backup checkpoints being automatically deleted after a new checkpoint is created;
generating a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup checkpoint operation;
copying the backup metadata file and the table data file to a backup storage path;
and marking the database to be in a backup stage in the process of generating and copying the backup metadata file and the table data file to a backup storage path so as to enable other components of the database to enter a preset backup working state.
In a second aspect, a method for recovering data in a database is provided, including:
copying the backup metadata file and the table data file obtained by backup into a specified directory of a database;
starting and controlling a database to load data in the backup metadata file and the table data file in the specified directory so as to recover the data in the database;
the backup metadata file and the table data file are obtained by backing up data in the database according to the backup method of the first aspect.
In a third aspect, an apparatus for backing up data in a database is provided, including:
the system comprises a check point creating module, a check point creating module and a check point creating module, wherein the check point creating module is used for creating backup check points in a database, and all the old check points except the backup check points are automatically deleted after a new check point is created;
the backup data generation module is used for generating a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup check point operation;
the backup data storage module is used for copying the backup metadata file and the table data file to a backup storage path;
and the backup state control module is used for marking that the database is in a backup stage in the process of generating and copying the backup metadata file and the table data file to a backup storage path so as to enable other components of the database to enter a preset backup working state.
In a fourth aspect, an apparatus for recovering data in a database is provided, including:
the backup data copying module is used for copying the backup metadata file and the table data file obtained by backup into a specified directory of the database;
the database recovery module is used for starting and controlling a database to load the data in the backup metadata file and the table data file in the specified directory so as to recover the data in the database;
the backup metadata file and the table data file are obtained by backing up data in the database according to the backup method of the first aspect.
In a fifth aspect, an electronic device is provided, comprising:
a memory for storing a program;
a processor, coupled to the memory, for executing the program for:
creating backup checkpoints in a database, all old checkpoints except the backup checkpoints being automatically deleted after a new checkpoint is created;
generating a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup checkpoint operation;
copying the backup metadata file and the table data file to a backup storage path;
and marking the database to be in a backup stage in the process of generating and copying the backup metadata file and the table data file to a backup storage path so as to enable other components of the database to enter a preset backup working state.
In a sixth aspect, another electronic device is provided, including:
a memory for storing a program;
a processor, coupled to the memory, for executing the program for:
copying the backup metadata file and the table data file obtained by backup into a specified directory of a database;
starting and controlling a database to load data in the backup metadata file and the table data file in the specified directory so as to recover the data in the database;
the backup metadata file and the table data file are obtained by backing up data in the database according to the backup method of the first aspect.
The invention provides a method and a device for backing up and recovering data in a database and electronic equipment. When the database is backed up, a backup check point is created, and all the old check points except the backup check point are set to be automatically deleted after the new check point is created; then generating and copying a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup check point operation; meanwhile, in the process of generating and copying the backup metadata file and the table data file, the marking database is in a backup stage, so that other components of the database enter a preset backup working state, and the sequential progress of the backup process is ensured. Based on the copied metadata file and the table data file in the backup process, the data in the database can be quickly restored. The scheme only keeps an old check point, namely the backup check point, during the backup of the database, and only restores the data of the backup check point during the recovery of the database, thereby effectively solving the problem of rapid increase of the disk space during the backup although the real-time property of some restored data is sacrificed.
The foregoing description is only an overview of the technical solutions of the present application, and the present application can be implemented according to the content of the description in order to make the technical means of the present application more clearly understood, and the following detailed description of the present application is given in order to make the above and other objects, features, and advantages of the present application more clearly understandable.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the application. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
FIG. 1 is a schematic diagram illustrating a data backup process in a database according to the prior art;
FIG. 2a is a logic diagram of the pre-backup stage shown in FIG. 1;
FIG. 2b is a logical view of the backup phase shown in FIG. 1;
FIG. 2c is a logical view of the post-backup phase shown in FIG. 1;
FIG. 3 is a diagram illustrating a data recovery logic in a database according to the prior art;
FIG. 4a is a logic diagram of a pre-share stage according to an embodiment of the present invention;
FIG. 4b is a logic diagram of a backup phase according to an embodiment of the present invention;
FIG. 4c is a logic diagram of a backup stage in accordance with an embodiment of the present invention;
FIG. 5 is a diagram illustrating a data recovery logic in a database according to an embodiment of the present invention;
FIG. 6 is a block diagram of a data backup and restore system in a database according to an embodiment of the present invention;
FIG. 7 is a flowchart of a first method for backing up data in a database according to an embodiment of the present invention;
FIG. 8 is a flowchart of a method for backing up data in a database according to an embodiment of the present invention;
FIG. 9 is a flowchart of a method for recovering data in a database according to an embodiment of the present invention;
FIG. 10 is a first block diagram of an apparatus for backing up data in a database according to an embodiment of the present invention;
FIG. 11 is a block diagram of a backup device for data in a database according to an embodiment of the present invention;
FIG. 12 is a diagram illustrating an apparatus for restoring data in a database according to an embodiment of the present invention;
FIG. 13 is a first schematic structural diagram of an electronic device according to an embodiment of the invention;
fig. 14 is a second structural illustration of an electronic device according to an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
Generally, the data backup process in the database mainly includes three stages, as shown in fig. 1, a pre-backup stage, a backup stage, and a post-backup stage. Wherein:
in the pre-backup stage, the primary operation is to acquire the backup metadata file of checkpoint and the table data file of the data table pointed by the metadata file based on checkpoint technology.
In the backup stage, the main operation is to copy the backup data (metadata file and table data file) generated in the preliminary stage to the backup storage path. The backup storage path is a storage path outside the database system path, so that the backup data cannot be lost or damaged after the database is down.
The back-up stage is mainly a pre-backup stage, and is an additional setting operation performed for the backup process, for example, an automatic deletion function of checkpoint needs to be closed in the pre-backup stage (an old checkpoint will be automatically deleted after a new checkpoint is created) to prevent backup metadata from being automatically deleted, and after the backup stage is completed, the automatic deletion function of checkpoint needs to be opened, so that the database can perform a normal checkpoint operation function.
Correspondingly, the data recovery process in the database is simpler than the storage process, and the data in the database can be recovered after the pre-backed up data file is loaded in the starting process of the database.
As shown in fig. 2a, fig. 2b and fig. 2c, which are schematic diagrams of process logics of a preparation stage, a backup stage and a backup stage included in a data backup process in a database in the prior art.
As shown in fig. 2a, the preliminary portion stage includes:
step 1, setting a backup mark in a database for marking that the current database is in a backup state, so that other components in the database assist in successfully completing a backup process, for example, ensuring that only one backup can be performed at the same time point, preventing a table data file to be backed up from being deleted, preventing the table data file from being truncated, and the like.
And step 2, closing the automatic deleting function of the checkpoint (a new checkpoint is still automatically created periodically).
And step 3, closing the automatic deleting function of the Journal log file.
The step 2 and the step 3 are executed to ensure that data is not lost in the database backup process.
And 4, step 4: and generating a backup metadata file according to the latest checkpoint.
And generating a backup metadata file, and outputting the metadata corresponding to the latest checkpoint to the file.
And 5: and outputting the table data file, the journal log file and the backup metadata file which need to be copied.
Wherein, the table data file is a file (not limited to a table form) recorded with table data contained in the database; the Journal in the Journal log file is the Journal log generated after the latest checkpoint.
For example, the file data can be output to a certain storage path of a directory in which the database system is located, or output to a designated data output port.
As shown in fig. 2b, the backup phase includes:
and copying the table data file, the journal log file and the backup metadata file to a backup storage path so as to complete the substantial backup process of database backup. The backup storage path is a storage path other than the database system path, so that the backup data is not lost or damaged after the database is down.
As shown in fig. 2c, the backup stage includes:
step 1, canceling the backup mark in the database, so that other components in the database know that the backup state of the current database is released, and the components are restored to a normal working state.
And 2, recovering the automatic deleting function of checkpoint.
And 3, recovering the automatic deleting function of the journal log file.
Fig. 3 is a schematic logic diagram of a data recovery process in a database in the prior art, which includes:
step 1, copying all files (including table data files, journal log files and backup metadata files) copied in the backup stage into a specified directory of a database. The specified directory is dedicated to storing load data required at startup of the database.
And 2, starting the database.
And after the database is started, automatically loading data in the designated directory, thereby recovering the data corresponding to the database at the backup time node.
In summary, the reason for the existing database backup method to close the automatic deletion function of the checkpoint and Journal log files is to prevent the data space pointed by the checkpoint that backs up the corresponding data file in the process of copying the data file from being recycled, and to prevent the data from being unable to be restored to the current update state due to the deletion of the required Journal log file. However, the biggest problem caused by the automatic deletion function for automatically closing the checkpoint and the Journal log files is that in the whole backup process, if the database still continues to provide normal services, the storage space occupied by the data files and the Journal log files will increase rapidly because the old checkpoint and Journal log files are not deleted, thereby bringing huge storage pressure to the disk.
The embodiment of the invention improves the backup process aiming at the data in the database in the prior art, only one old checkpoint, namely backup checkpoint, is reserved during the backup of the database, and only the data of the backup checkpoint is recovered during the recovery of the database, thereby effectively solving the problem of rapid increase of the disk space during the backup although the real-time property of some recovered data is sacrificed.
The embodiment of the invention still follows the whole backup process of database backup in the prior art, namely, the embodiment still comprises the following steps: a pre-backup stage, a backup stage and a backup stage. But with some modifications to each stage.
First, as shown in fig. 4a, a schematic process logic diagram of a preliminary backup stage in a data backup process in a database according to an embodiment of the present invention includes:
step 1, enabling the database to create a backup checkpoint.
First, the database is made to create a special backup checkpoint that needs to be explicitly created and deleted. I.e. it needs to be created and deleted by the outside world through an interface. This backup checkpoint is created at each backup and only one. Correspondingly, when the database is restored, the data is also restored to the checkpoint.
At this time, the database deletes the old checkpoint except the backup checkpoint while continuing to create the new checkpoint. This is so set that, in addition to the automatic deletion function that guarantees not to close ordinary checkpoint except backup checkpoint during backup, the automatic deletion function is not closed for Journal log files.
Step 2: a backup mark is set in the database.
The main function of the backup mark is the same as that of the backup mark in the prior art, and is used for marking that the current database is in a backup state, so that other components in the database assist the backup process to be successfully completed, for example, only one backup can be performed at the same time point, the table data file to be backed up is prevented from being deleted, the table data file is prevented from being cut off, and the like.
And step 3: and generating a backup metadata file according to the backup checkpoint.
And generating a backup metadata file and outputting the metadata corresponding to the backup checkpoint to the file.
And 4, step 4: and outputting the table data file and the backup metadata file which need to be copied.
The table data file is a file (not limited to a table format) in which table data included in the database is recorded.
For example, the file data can be output to a certain storage path of a directory in which the database system is located, or output to a designated data output port.
Next, as shown in fig. 4b, a schematic process logic diagram of a backup stage in a data backup process in a database according to an embodiment of the present invention includes:
copying the table data file, the backup metadata file to the backup storage path. The difference from the backup stage in the prior art is that the copied files do not contain the journal log files.
Next, as shown in fig. 4c, a process logic diagram of a backup stage in a data backup process in a database provided in the embodiment of the present invention includes:
and step 1, canceling the backup marks in the database.
And 2, explicitly deleting the backup checkpoint.
The explicit deletion of the backup checkpoint means that the backup checkpoint can be deleted only by a deletion operation (for example, manual deletion) triggered from the outside of the database system.
Correspondingly, as shown in fig. 5, a schematic diagram of a restoration process logic in a data backup process in a database provided by the embodiment of the present invention includes:
step 1, copying all files (including table data files and backup metadata files) copied in the backup stage into an empty data directory. The specified directory is dedicated to storing load data required at startup of the database.
And 2, starting the database and loading data.
And after the database is started, automatically loading data in the designated directory, thereby recovering the data corresponding to the database at the backup time node.
In summary, the database backup method provided by the embodiment of the present invention does not need to close the automatic deletion function of the checkpoint and Journal log files, and can implement the backup process as long as one old backup checkpoint is reserved. Therefore, in the whole backup process, the database can still continuously provide normal service, and as the checkpoint of other old non-backup checkpoint is still deleted normally, the problem that the storage space occupied by the data file and the Journal log is increased quickly is not caused, so that huge storage pressure is not brought to the disk, and only the backup checkpoint needs to be stored additionally.
Based on the above-mentioned concept of the scheme for backing up and restoring data in the database according to the embodiment of the present invention, fig. 6 is a diagram of a system for backing up and restoring data in the database according to the embodiment of the present invention. As shown in fig. 6, the system includes a database system 610, a backup device 620 for data in the database, and a recovery device 630 for data in the database, wherein:
the database system 610 may adopt a data modification manner of non-in-place update and adopt a checkpoint technology to implement data persistence.
The backup device 620 for data in the database is configured to backup the backup metadata file of the backup checkpoint and the corresponding table data file by setting the backup checkpoint in the database.
And a data restoring means 630 for restoring the data in the database based on the backup metadata file and the corresponding table data file backed up by the data backing up means 620 in the database.
The backup device 620 for data in the database comprises:
the system comprises a check point creating module, a database and a database, wherein the check point creating module is used for creating backup check points in the database, and all the old check points except the backup check points are automatically deleted after a new check point is created;
the backup data generation module is used for generating a backup metadata file and a table data file of the data table based on metadata of the data table generated after backup check point operation;
the backup data storage module is used for copying the backup metadata file and the table data file to a backup storage path;
and the backup state control module is used for marking the database to be in a backup stage in the process of generating and copying the backup metadata file and the table data file to the backup storage path so as to enable other components of the database to enter a preset backup working state.
The data recovery device 630 in the database comprises:
the backup data copying module is used for copying the backup metadata file and the table data file obtained by backup into a specified directory of the database;
the database recovery module is used for starting and controlling the database to load the backup metadata files in the appointed directory and the data in the table data files so as to recover the data in the database;
the backup metadata file and the table data file are obtained by backing up the data in the database by the backup device 620.
The technical solution of the present application is further illustrated by the following examples.
Example one
Based on the above idea of a data backup scheme in a database, as shown in fig. 7, which is a flowchart of a method for backing up data in a database according to an embodiment of the present invention, an execution subject of the method may be the backup apparatus 620 for data in a database shown in fig. 6. As shown in fig. 7, the method for backing up data in the database includes the following steps:
s710, creating backup check points in the database, wherein all the old check points except the backup check points are automatically deleted after the new check point is created.
First, the database is made to create a special backup checkpoint that needs to be explicitly created and deleted. I.e. it needs to be created and deleted by the outside world through an interface. This backup checkpoint is created at each backup and only one. The database may be a database that is updated in-place.
At this time, the database deletes the old checkpoint except the backup checkpoint while continuing to create the new checkpoint. This is so set that, in addition to the automatic deletion function that guarantees not to close ordinary checkpoint except backup checkpoint during backup, the automatic deletion function is not closed for Journal log files.
S720, generating a backup metadata file and a table data file of the data table based on the metadata of the data table generated after the backup checkpoint operation.
The backup checkpoint and the ordinary checkpoint are created and operated in the same process, and corresponding metadata is generated and persisted for each data table in the current database, and meanwhile, a table data file of the data table is persisted. Therefore, based on the backup checkpoint operation, the generated metadata can be summarized to generate a backup metadata file. According to the data table pointed in the backup metadata file, the table data file with corresponding content can be extracted. The table data file is a file (not limited to a table format) in which table data included in the database is recorded.
S730, copying the backup metadata file and the table data file to a backup storage path.
The backup storage path is a storage location independent of the storage path occupied by the database system, and is intended to prevent data loss or damage under the storage path after the database is crashed.
In addition, the difference between this step and the backup stage in the prior art is that the copied file does not contain the journal log file, which can reduce the complexity of the backup operation and realize the fast backup.
And S740, marking the database to be in a backup stage in the process of generating and copying the backup metadata file and the table data file to the backup storage path so as to enable other components of the database to enter a preset backup working state.
When the backup process is started, the current database can be marked to be in a backup state, so that other components of the database assist the backup process to be successfully completed. The assistance contents mainly include, for example, ensuring that only one backup can be performed at the same time point, preventing the table data file to be backed up from being deleted, preventing the table data file from being truncated, and the like. After the backup process is finished, the backup state of the database can be released again, so that each component can restore the respective normal working state.
It should be noted that the preset backup operating state corresponding to other components may be customized as long as it can ensure that the backup process is normally performed, and the definition of the content of the preset backup operating state is not limited to the above example. Of course, the implementation process and effect of this step can also be achieved by adopting or combining the manner of setting the backup mark in the prior art.
According to the method for backing up the data in the database, when the database is backed up, a backup check point is created, and all old check points except the backup check point are set to be automatically deleted after a new check point is created; then generating and copying a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup check point operation; meanwhile, in the process of generating and copying the backup metadata file and the table data file, the marking database is in a backup stage, so that other components of the database enter a preset backup working state, and the sequential progress of the backup process is ensured. According to the scheme, only one old check point, namely the backup check point, is reserved during the backup of the database, and the problem that the disk space is rapidly increased during the backup is effectively solved.
Example two
The present embodiment adds the following expansion content on the basis of the previous embodiment.
First, as shown in fig. 8, a flowchart of a backup method for data in a database according to an embodiment of the present invention is shown in fig. two. On the basis of the method shown in the previous embodiment, a step of setting a backup mark is added to ensure that the backup process is normally performed. As shown in fig. 8, after step S710, the following steps are performed:
s810, creating a backup mark in the database, wherein the backup mark is used for identifying that the database is in a backup stage so as to enable other components to enter a preset backup working state.
This step may be a refinement of the step S740, and the function of the specific backup mark is the same as that of the backup mark in the prior art. The benefit of such a process is that the cost of modification to existing methods is reduced.
However, in the prior art, after the backup mark is set, an automatic deletion function of a checkpoint is automatically turned off, and an automatic deletion function of a journal log is automatically turned off, which results in that other old checkpoints except the backup checkpoint cannot be deleted, thereby occupying a disk storage space. As can be understood, the preset backup operating states of other components include: automatically turning off the functionality that all old checkpoints in a normal operating state will be automatically deleted after a new checkpoint is created.
The method can firstly decouple the steps of the two existing links, and separates the process of setting the backup mark from the automatic deleting function of automatically closing checkpoint and the automatic deleting function of automatically closing the journal log. Then only the step of setting the backup mark is executed, the step of automatically closing the automatic deleting function of the checkpoint and the step of automatically closing the automatic deleting function of the journal log are not executed, and therefore the effect that all the old checkpoints except the backup checkpoint are automatically deleted after the new checkpoint is created is achieved.
However, the cost of the modification of the prior art is high, and the original backup process is damaged. Aiming at the situation, the scheme provides a scheme with smaller modification cost, namely, if the process of setting the backup mark and the process of automatically closing the automatic deleting function of checkpoint are not decoupled, the preset backup working state comprises the following steps: automatically closing the function that all old check points in the normal working state are automatically deleted after the new check point is created; then step 710 may be performed before creating an additional marker for causing other components to automatically turn off only the functionality of the old checkpoint in normal operation that will be automatically deleted after the new checkpoint is created for the backup checkpoint after entering the preset backup operating state, such that all old checkpoints, except the backup checkpoint, will be automatically deleted after the new checkpoint is created.
After step S810 is executed again in this way, when other components want to execute deletion of the backup checkpoint according to the backup marker, since the additional marker is seen (the execution priority of the additional marker is set higher than that of the backup marker), only the backup checkpoint is retained, and other old checkpoints will still be automatically deleted after the new checkpoint is created. When the backup mark is cancelled and disabled, the additional mark is automatically cancelled and disabled.
After step S730, the following steps may be performed:
s820, the backup mark is cancelled.
And S830, restoring other components to enter a normal working state.
After the backup stage is finished, the backup mark can be cancelled and invalidated, so that other components can be restored to normal working states.
At this time, a backup checkpoint is also stored in the database, and the following steps may be selectively performed in order to reduce the storage pressure of the disk:
s840, in response to the operation of deleting the backup checkpoint triggered by the external port, deleting the metadata of the data table generated by the backup checkpoint operation.
It should be emphasized here that the manner of deleting the backup checkpoint is explicit deletion, that is, the backup checkpoint can be deleted only by a deletion operation (such as manual deletion) triggered from outside the database system.
The method for backing up data in the database provided by the invention is expanded on the basis of the first embodiment:
firstly, the backup marks in the prior art are quoted to realize that the mark database is in a backup stage, so that other components enter a preset backup working state. By multiplexing the prior art, the complexity of the improvement scheme is reduced.
And secondly, after the backup stage is finished, recovering the normal functional states of other components, and ensuring that the database provides services to the outside in sequence.
And finally, deleting the backup checkpoint through external triggering of the database after the backup stage is finished, so that on one hand, the backup checkpoint is ensured not to be randomly deleted in the backup stage, and on the other hand, the corresponding disk storage space can be released after the backup stage is finished, and the disk storage pressure is reduced.
EXAMPLE III
Based on the above concept of the recovery scheme of the data in the database, as shown in fig. 9, it is a flowchart of a method for recovering data in a database according to an embodiment of the present invention, and an execution subject of the method may be the recovery apparatus 630 of the data in the database shown in fig. 6. As shown in fig. 9, the method for recovering data in the database includes the following steps:
s910, copying the backup metadata file and the table data file obtained by backup to a specified directory of the database.
For example, the data file may be copied to an empty data directory under the database system. The specified directory is dedicated to storing load data required at startup of the database.
S920, starting and controlling the database to load the data in the backup metadata file and the table data file in the appointed directory so as to recover the data in the database.
The backup metadata file and the table data file are obtained by the backup method of the data in the database according to any one of the first embodiment and the second embodiment.
The database recovery method provided by the embodiment of the invention can quickly recover the data of the database to the data at the moment of backing up the checkpoint based on the metadata file and the table data file backed up in advance.
Example four
Fig. 10 is a diagram illustrating a first structure of a backup device for data in a database according to an embodiment of the present invention, where the backup device for data in a database may be disposed in the backup and recovery system for data in a database shown in fig. 6, and is configured to perform the method steps shown in fig. 7, and include:
a checkpoint creating module 101, configured to create backup checkpoints in the database, where all old checkpoints except the backup checkpoint are automatically deleted after a new checkpoint is created;
the backup data generation module 102 is configured to generate a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup checkpoint operation;
a backup data storage module 103, configured to copy the backup metadata file and the table data file to a backup storage path;
the backup state control module 104 is configured to mark that the database is in a backup stage in a process of generating and copying the backup metadata file and the table data file to the backup storage path, so that other components of the database enter a preset backup working state.
Further, the backup state control module 104 may be specifically configured to create a backup mark in the database, where the backup mark is used to identify that the database is in a backup stage, so as to enable other components to enter a preset backup working state;
accordingly, the backup state control module 104 may be further configured to restore other components to a normal operating state after the backup flag is cancelled.
Further, the preset backup operating state may include: automatically closing a closing deletion function that all old check points in a normal working state are automatically deleted after a new check point is created;
correspondingly, as shown in fig. 11, the backup device for the data in the database may further include:
an additional state control module 111 for the checkpoint creation module to create an additional marker after creating a backup checkpoint in the database, the additional marker being used to cause other components to automatically turn off only the function of the old checkpoint in the normal operating state that will be automatically deleted after the new checkpoint is created, after entering the preset backup operating state, for the backup checkpoint, so that all old checkpoints, except the backup checkpoint, will be automatically deleted after the new checkpoint is created.
Further, the backup device for data in the database shown in fig. 11 may further include:
the backup mark canceling module 112 is configured to cancel the backup mark after the backup data generating module copies the backup metadata file and the table data file to the backup storage path.
Further, the backup device for data in the database shown in fig. 11 may further include:
a backup checkpoint deletion module 113 for deleting metadata of the data table generated by the backup checkpoint operation in response to a delete backup checkpoint operation triggered by the external port.
The device structure shown in fig. 11 may be used to perform the method steps shown in fig. 8.
According to the data backup device in the database, when the database is backed up, the backup check point is created, and all the old check points except the backup check point are automatically deleted after the new check point is created; then generating and copying a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup check point operation; meanwhile, in the process of generating and copying the backup metadata file and the table data file, the marking database is in a backup stage, so that other components of the database enter a preset backup working state, and the sequential progress of the backup process is ensured. According to the scheme, only one old check point, namely the backup check point, is reserved during the backup of the database, and the problem that the disk space is rapidly increased during the backup is effectively solved.
Furthermore, the scheme refers to the backup marks in the prior art, and realizes that the mark database is in a backup stage, so that other components enter a preset backup working state. By multiplexing the prior art, the complexity of the improvement scheme is reduced.
Furthermore, after the backup stage is finished, the normal function states of other components are recovered, and the database is ensured to provide services to the outside in sequence.
Further, after the backup stage is finished, the backup checkpoint is deleted through external triggering of the database, so that on one hand, the backup checkpoint is ensured not to be randomly deleted in the backup stage, and on the other hand, after the backup stage is finished, the corresponding disk storage space is released, and the disk storage pressure is reduced.
EXAMPLE five
As shown in fig. 12, which is a structural diagram of a recovery device for data in a database according to an embodiment of the present invention, the recovery device for data in a database may be disposed in the backup and recovery system for data in a database shown in fig. 6, and is configured to perform the method steps shown in fig. 9, and include:
a backup data copying module 121, configured to copy the backup metadata file and the table data file obtained through backup into an assigned directory of the database;
the database recovery module 122 is configured to start and control the database to load data in the backup metadata file and the table data file in the designated directory to recover the data in the database;
the backup metadata file and the table data file are obtained by the backup method of the data in the database according to any one of the first embodiment and the second embodiment.
The database recovery device provided by the embodiment of the invention can quickly recover the data of the database to the data at the moment of backing up the checkpoint based on the metadata file and the table data file backed up in advance.
EXAMPLE six
The foregoing embodiment describes an overall architecture of a device for backing up data in a database, where the function of the device can be implemented by an electronic device, as shown in fig. 13, which is a schematic structural diagram of the electronic device according to an embodiment of the present invention, and specifically includes: a memory 131 and a processor 132.
The memory 131 stores programs.
In addition to the above-described programs, the memory 131 may also be configured to store other various data to support operations on the electronic device. Examples of such data include instructions for any application or method operating on the electronic device, contact data, phonebook data, messages, pictures, videos, and so forth.
The memory 131 may be implemented by any type or combination of volatile or non-volatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
A processor 132, coupled to the memory 131, for executing programs in the memory 131 for:
creating backup check points in the database, wherein all the old check points except the backup check points are automatically deleted after the new check point is created;
generating a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup check point operation;
copying the backup metadata file and the table data file to a backup storage path;
in the process of generating and copying the backup metadata file and the table data file to the backup storage path, marking the database to be in a backup stage so as to enable other components of the database to enter a preset backup working state.
The above specific processing operations have been described in detail in the foregoing embodiments, and are not described again here.
Further, as shown in fig. 13, the electronic device may further include: communication components 133, power components 134, audio components 135, a display 136, and the like. Only some of the components are schematically shown in fig. 13, and the electronic device is not meant to include only the components shown in fig. 13.
The communication component 133 is configured to facilitate wired or wireless communication between the electronic device and other devices. The electronic device may access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 133 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 133 further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
A power supply component 134 provides power to the various components of the electronic device. The power components 134 may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for an electronic device.
The audio component 135 is configured to output and/or input audio signals. For example, the audio component 135 includes a Microphone (MIC) configured to receive external audio signals when the electronic device is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal may further be stored in the memory 131 or transmitted via the communication component 133. In some embodiments, audio assembly 135 also includes a speaker for outputting audio signals.
The display 136 includes a screen, which may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
EXAMPLE seven
The foregoing embodiment describes an overall architecture of a device for recovering data in a database, where the function of the device can be implemented by an electronic device, as shown in fig. 14, which is a schematic structural diagram of the electronic device according to an embodiment of the present invention, and specifically includes: a memory 141 and a processor 142.
The memory 141 stores a program.
In addition to the above-described programs, the memory 141 may also be configured to store other various data to support operations on the electronic device. Examples of such data include instructions for any application or method operating on the electronic device, contact data, phonebook data, messages, pictures, videos, and so forth.
The memory 141 may be implemented by any type or combination of volatile or non-volatile memory devices, such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
A processor 142, coupled to the memory 141, for executing programs in the memory 141 to:
copying the backup metadata file and the table data file obtained by backup into a specified directory of a database;
starting and controlling a database to load data in a backup metadata file and a table data file in a specified directory so as to recover the data in the database;
the backup metadata file and the table data file are obtained by backing up data in a database by a backup method.
The above specific processing operations have been described in detail in the foregoing embodiments, and are not described again here.
Further, as shown in fig. 14, the electronic device may further include: communication components 143, power components 144, audio components 145, displays 146, and other components. Only some of the components are schematically shown in fig. 14, and it is not meant that the electronic device includes only the components shown in fig. 14.
The communication component 143 is configured to facilitate wired or wireless communication between the electronic device and other devices. The electronic device may access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 143 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 143 further includes a Near Field Communication (NFC) module to facilitate short-range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
A power supply component 144 provides power to the various components of the electronic device. The power components 144 may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for an electronic device.
The audio component 145 is configured to output and/or input audio signals. For example, the audio component 145 includes a Microphone (MIC) configured to receive external audio signals when the electronic device is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal may further be stored in the memory 141 or transmitted via the communication component 143. In some embodiments, audio component 145 also includes a speaker for outputting audio signals.
The display 146 includes a screen, which may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present application.

Claims (14)

1. A method of backing up data in a database, comprising:
creating backup checkpoints in a database, all old checkpoints except the backup checkpoints being automatically deleted after a new checkpoint is created;
generating a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup checkpoint operation;
copying the backup metadata file and the table data file to a backup storage path;
and marking the database to be in a backup stage in the process of generating and copying the backup metadata file and the table data file to a backup storage path so as to enable other components of the database to enter a preset backup working state.
2. The method of claim 1, wherein marking the database as being in a backup phase to cause other components of the database to enter respective operational states comprises:
creating a backup mark in a database, wherein the backup mark is used for identifying that the database is in a backup stage so as to enable the other components to enter the preset backup working state;
the method further comprises the following steps:
and after the backup mark is cancelled, restoring the other components to enter a normal working state.
3. The method of claim 2, wherein the preset backup operating state comprises: automatically closing the function that all the old check points in the normal working state are automatically deleted after the new check point is created;
after creating the backup checkpoint in the database, the method further comprises:
creating an additional mark for causing the other components to automatically turn off, after entering the preset backup operating state, only for the backup checkpoint a function in which an old checkpoint in the normal operating state will be automatically deleted after a new checkpoint is created, so that all old checkpoints except the backup checkpoint will be automatically deleted after a new checkpoint is created.
4. The method of claim 2, wherein said copying said backup metadata file and said table data file to a backup storage path further comprises:
canceling the backup mark.
5. The method of claim 4, wherein said canceling further comprises after said canceling said backup mark;
in response to a delete operation triggered by an external port for the backup checkpoint, deleting metadata of the data table generated by the backup checkpoint operation.
6. A method of recovering data in a database, comprising:
copying the backup metadata file and the table data file obtained by backup into a specified directory of a database;
starting and controlling a database to load data in the backup metadata file and the table data file in the specified directory so as to recover the data in the database;
wherein, the backup metadata file and the table data file are obtained by backup by using the backup method of the data in the database according to any one of claims 1 to 5.
7. An apparatus for backing up data in a database, comprising:
the system comprises a check point creating module, a check point creating module and a check point creating module, wherein the check point creating module is used for creating backup check points in a database, and all the old check points except the backup check points are automatically deleted after a new check point is created;
the backup data generation module is used for generating a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup check point operation;
the backup data storage module is used for copying the backup metadata file and the table data file to a backup storage path;
and the backup state control module is used for marking that the database is in a backup stage in the process of generating and copying the backup metadata file and the table data file to a backup storage path so as to enable other components of the database to enter a preset backup working state.
8. The apparatus according to claim 7, wherein the backup state control module is specifically configured to create a backup flag in a database, where the backup flag is used to identify that the database is in a backup stage, so as to cause the other components to enter the preset backup operating state;
and the backup state control module is also used for restoring the other components to enter a normal working state after the backup mark is cancelled.
9. The apparatus of claim 8, wherein the preset backup operating state comprises: automatically closing a closing deletion function that all the old check points in the normal working state are automatically deleted after the new check point is created;
the device further comprises:
an additional state control module, configured to create, by the checkpoint creation module, an additional mark after the backup checkpoint is created in the database, where the additional mark is used to enable the other components to, after entering the preset backup operating state, automatically turn off, only for the backup checkpoint, a function that an old checkpoint in the normal operating state will be automatically deleted after a new checkpoint is created, so that all old checkpoints, except the backup checkpoint, will be automatically deleted after the new checkpoint is created.
10. The apparatus of claim 8, wherein the apparatus further comprises:
and the backup mark canceling module is used for canceling the backup mark after the backup data generating module copies the backup metadata file and the table data file to a backup storage path.
11. The apparatus of claim 10, wherein the apparatus further comprises:
and the backup checkpoint deleting module is used for responding to the operation of deleting the backup checkpoint triggered by the external port and deleting the metadata of the data table generated by the backup checkpoint operation.
12. An apparatus for recovering data in a database, comprising:
the backup data copying module is used for copying the backup metadata file and the table data file obtained by backup into a specified directory of the database;
the database recovery module is used for starting and controlling a database to load the data in the backup metadata file and the table data file in the specified directory so as to recover the data in the database;
wherein, the backup metadata file and the table data file are obtained by backup by using the backup method of the data in the database according to any one of claims 1 to 5.
13. An electronic device, comprising:
a memory for storing a program;
a processor, coupled to the memory, for executing the program for:
creating backup checkpoints in a database, all old checkpoints except the backup checkpoints being automatically deleted after a new checkpoint is created;
generating a backup metadata file and a table data file of the data table based on metadata of the data table generated after the backup checkpoint operation;
copying the backup metadata file and the table data file to a backup storage path;
and marking the database to be in a backup stage in the process of generating and copying the backup metadata file and the table data file to a backup storage path so as to enable other components of the database to enter a preset backup working state.
14. An electronic device, comprising:
a memory for storing a program;
a processor, coupled to the memory, for executing the program for:
copying the backup metadata file and the table data file obtained by backup into a specified directory of a database;
starting and controlling a database to load data in the backup metadata file and the table data file in the specified directory so as to recover the data in the database;
wherein, the backup metadata file and the table data file are obtained by backup by using the backup method of the data in the database according to any one of claims 1 to 5.
CN201811014535.9A 2018-08-31 2018-08-31 Backup and recovery method and device for data in database and electronic equipment Active CN110874287B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811014535.9A CN110874287B (en) 2018-08-31 2018-08-31 Backup and recovery method and device for data in database and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811014535.9A CN110874287B (en) 2018-08-31 2018-08-31 Backup and recovery method and device for data in database and electronic equipment

Publications (2)

Publication Number Publication Date
CN110874287A true CN110874287A (en) 2020-03-10
CN110874287B CN110874287B (en) 2023-05-02

Family

ID=69715852

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811014535.9A Active CN110874287B (en) 2018-08-31 2018-08-31 Backup and recovery method and device for data in database and electronic equipment

Country Status (1)

Country Link
CN (1) CN110874287B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6345282B1 (en) * 1999-09-30 2002-02-05 Nortel Networks Limited Multi-processor data synchronization method and apparatus
US20020103814A1 (en) * 2000-12-12 2002-08-01 Edouard Duvillier High speed, non-log based database recovery technique
CN102541691A (en) * 2011-12-27 2012-07-04 北京人大金仓信息技术股份有限公司 Log check point recovery method applied to memory data base OLTP (online transaction processing)
CN102750317A (en) * 2012-05-02 2012-10-24 华为技术有限公司 Method and device for data persistence processing and data base system
US8364648B1 (en) * 2007-04-09 2013-01-29 Quest Software, Inc. Recovering a database to any point-in-time in the past with guaranteed data consistency
CN105339939A (en) * 2013-06-25 2016-02-17 国际商业机器公司 Replication for on-line hot-standby database
US20160140132A1 (en) * 2014-11-19 2016-05-19 Unisys Corporation Online redistribution
CN105677509A (en) * 2015-12-25 2016-06-15 北京奇虎科技有限公司 Method and apparatus for recovering data in database
CN106155838A (en) * 2015-04-24 2016-11-23 中国移动通信集团河南有限公司 A kind of database back-up data restoration methods and device

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6345282B1 (en) * 1999-09-30 2002-02-05 Nortel Networks Limited Multi-processor data synchronization method and apparatus
US20020103814A1 (en) * 2000-12-12 2002-08-01 Edouard Duvillier High speed, non-log based database recovery technique
US8364648B1 (en) * 2007-04-09 2013-01-29 Quest Software, Inc. Recovering a database to any point-in-time in the past with guaranteed data consistency
CN102541691A (en) * 2011-12-27 2012-07-04 北京人大金仓信息技术股份有限公司 Log check point recovery method applied to memory data base OLTP (online transaction processing)
CN102750317A (en) * 2012-05-02 2012-10-24 华为技术有限公司 Method and device for data persistence processing and data base system
CN105339939A (en) * 2013-06-25 2016-02-17 国际商业机器公司 Replication for on-line hot-standby database
US20160140132A1 (en) * 2014-11-19 2016-05-19 Unisys Corporation Online redistribution
CN106155838A (en) * 2015-04-24 2016-11-23 中国移动通信集团河南有限公司 A kind of database back-up data restoration methods and device
CN105677509A (en) * 2015-12-25 2016-06-15 北京奇虎科技有限公司 Method and apparatus for recovering data in database

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
覃雄派;肖艳芹;曹巍;王珊;: "面向更新密集型应用的内存数据库高效检查点技术" *

Also Published As

Publication number Publication date
CN110874287B (en) 2023-05-02

Similar Documents

Publication Publication Date Title
RU2636671C2 (en) Method, device and terminal for restoring firmware
JP4944686B2 (en) Software update method and portable terminal device
CN108416040B (en) Database repair method and device, terminal equipment and storage medium
US8578203B2 (en) Providing a backup service from a remote backup data center to a computer through a network
KR20130138635A (en) Method and apparatus for fault tolerant fota update with single backup block write
CN105204959A (en) Method and device for restoring deleted files in ext file system
US8694470B2 (en) Mobile terminal environment snapshot management and backup recovery
JP2008501180A (en) Method and system for in-place updating of content stored in a storage device
WO2021218300A1 (en) Blockchain data clipping method and apparatus, node recovery method and apparatus, and device and medium
US20100145915A1 (en) Storage apparatus and data restoring method used therein
CN105095025A (en) Method and apparatus for recovering deleted file in ext file system
CN116048644B (en) System migration method, device and readable storage medium
CN105867962A (en) System upgrading method and device
US20120185440A1 (en) Method and apparatus for providing address book restoration
WO2018177193A1 (en) Software upgrade method and device
KR20120027219A (en) Capturing and loading operating system states
CN110874287A (en) Method and device for backing up and recovering data in database and electronic equipment
KR101085681B1 (en) System and method for recovering data in mobile terminal
CN109325005B (en) Data processing method and electronic equipment
US20230108138A1 (en) Techniques for preserving clone relationships between files
WO2016110065A1 (en) Method and device for safely deleting data in mobile terminal
CN110704243A (en) Data recovery method and device, terminal equipment and storage medium
US11269739B2 (en) Method and system for managing backup data
CN107357536B (en) Data modification and writing method and system for distributed storage system
CN111274210B (en) Metadata processing method and device and electronic equipment

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