WO2016058333A1 - 数据库的数据恢复方法、设备及计算机存储介质 - Google Patents

数据库的数据恢复方法、设备及计算机存储介质 Download PDF

Info

Publication number
WO2016058333A1
WO2016058333A1 PCT/CN2015/074734 CN2015074734W WO2016058333A1 WO 2016058333 A1 WO2016058333 A1 WO 2016058333A1 CN 2015074734 W CN2015074734 W CN 2015074734W WO 2016058333 A1 WO2016058333 A1 WO 2016058333A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
database
abnormal
backed
backup
Prior art date
Application number
PCT/CN2015/074734
Other languages
English (en)
French (fr)
Inventor
王涵毅
Original Assignee
中兴通讯股份有限公司
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 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2016058333A1 publication Critical patent/WO2016058333A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor

Definitions

  • the present invention relates to the field of data storage, and in particular, to a data recovery method, device and computer storage medium for a database.
  • the embodiments of the present invention are expected to provide a data recovery method, a device, and a computer storage medium for a database, which improve the stability and work efficiency of the service operation.
  • an embodiment of the present invention provides a data recovery device of a database, where the data recovery device includes: a detecting unit, a checking unit, a searching unit, and a restoring unit, where
  • the detecting unit is configured to detect that a data abnormality occurs in the database during the running, and trigger the verification unit when detecting that the database has abnormal data;
  • the checking unit is configured to: when the detecting unit detects that the data in the database is abnormal, check the data in the database index and the data in the database file, and determine the database. Exception data, and transmitting the abnormal data to the lookup unit;
  • the searching unit is configured to search for the abnormal data according to the verification unit Obtaining a log file and a backup file of the database, acquiring data to be backed up corresponding to the abnormal data, and transmitting the data to be backed up to the recovery unit;
  • the recovery unit is configured to replace the abnormal data by using the data to be backed up acquired by the searching unit.
  • the detecting unit is configured to detect the data abnormality when the database performs the structured query language SQL access or update data; or detect that the database is abnormally exited; or The database is started after an abnormal exit.
  • the searching unit is configured to search the log file according to the abnormal data, and obtain data to be backed up corresponding to the abnormal data in the log file;
  • the backup file is searched according to the abnormal data, and the data to be backed up corresponding to the abnormal data in the backup file is acquired;
  • the abnormal data is cleared.
  • the recovery unit is configured to clear abnormal data in the database; and insert the data to be backed up into the database.
  • the data recovery device further includes a backup unit configured to back up data in the database according to a preset backup policy to obtain the backup file.
  • the backup unit is further configured to: back up the database according to a preset period value and/or a system busyness of the database.
  • the backup unit is further configured to: back up data in the database that meets a preset importance level.
  • the backup unit is further configured to: before the data in the database is backed up according to the preset backup policy, clear the log file of the database, and instruct the database to re-record The log file.
  • an embodiment of the present invention provides a data recovery method for a database, where the method includes:
  • the abnormal data is replaced by the data to be backed up.
  • the detecting that the database has a data abnormality during the running process comprises: when the database is performing a structured query language SQL access or updating data, the data is abnormal; or the database is abnormally exited; Alternatively, the database is started after an abnormal exit.
  • the searching for the log file and the backup file of the database according to the abnormal data, and acquiring the data to be backed up corresponding to the abnormal data including:
  • the backup file is searched according to the abnormal data, and the data to be backed up corresponding to the abnormal data in the backup file is obtained;
  • the abnormal data is cleared.
  • the replacing the abnormal data with the data to be backed up includes:
  • the method further includes: backing up data in the database according to a preset backup policy, and obtaining the backup file.
  • the data in the database is backed up according to a preset backup policy, include:
  • the database is backed up according to a preset period value and/or system busyness of the database.
  • the backing up data in the database according to a preset backup policy, including:
  • the data in the database that meets the preset importance level is backed up.
  • the method further includes: clearing the log file of the database, and instructing the database to re-record the log file.
  • an embodiment of the present invention provides a computer storage medium, where the computer storage medium stores computer executable instructions, and the computer executable instructions are used to execute the data recovery method of the database described above.
  • the embodiment of the invention provides a data recovery method, a device and a computer storage medium for a database, which improves the stability of the service operation by performing data verification when the database is abnormal, and recovering the abnormal data through backup and log files. And work efficiency.
  • FIG. 1 is a schematic flowchart of a data recovery method of a database according to an embodiment of the present invention
  • FIG. 2 is a schematic diagram of a mapping relationship between a database index value and data in a database according to an embodiment of the present invention
  • FIG. 3 is a schematic structural diagram of a file for data recovery in a database according to an embodiment of the present invention.
  • FIG. 4 is a schematic structural diagram of a data recovery device of a database according to an embodiment of the present invention.
  • FIG. 5 is a schematic structural diagram of another data recovery device of a database according to an embodiment of the present invention.
  • the method may be applied to the database.
  • the method may include:
  • the database is abnormal in data, which may include: when the database accesses or updates data in a structured query language (SQL), the data is abnormal, such as: The index of the database has a duplicate key or the index value is an illegal value; or, the database is abnormally exited; or, the database is abnormally started after starting, and so on. After these exceptions occur, you need to determine whether these exceptions are caused by data or index anomalies.
  • SQL structured query language
  • the data in the database index and the data in the database file are verified, and the mapping relationship between the database index value and the data in the database may be performed according to FIG. 2
  • the test may specifically include the following steps: first obtaining a table in which the database is being operated when the data is abnormal; and then comparing the index of the table with the data in the database file, thereby judging the accuracy of the data: if consistent, The description is accurate; if it is inconsistent, the description is inaccurate, and the data is abnormal data.
  • S102 Searching the log file and the backup file of the database according to the abnormal data, and acquiring data to be backed up corresponding to the abnormal data;
  • the file for data recovery in the database shown in FIG. 3, the log file and the backup file of the database are searched according to the abnormal data, and the data to be backed corresponding to the abnormal data is obtained.
  • the log file and the backup file of the database are searched according to the abnormal data, and the data to be backed corresponding to the abnormal data is obtained.
  • the backup file is searched according to the abnormal data, and the data to be backed up corresponding to the abnormal data in the backup file is acquired;
  • the abnormal data is cleared, and the data to be backed corresponding to the abnormal data is not included in the log file and the backup file. Then, the abnormal data has a lower importance level, so that abnormal data that is not important can be directly deleted.
  • this file can be used to make up for the loss of data records caused by the time interval between two backup files, so that the data to be backed up can reflect the data situation at the moment when the data is abnormal in the database.
  • the replacing the abnormal data with the data to be backed up may specifically include:
  • the abnormal data in the database may be first cleared, and then the data to be backed up is formed into an insert statement into the database.
  • the method may further include: according to the preset The backup strategy backs up the data in the database.
  • the backing up data in the database according to a preset backup policy, including:
  • the backup file obtained by backing up the database may be a logical backup, such as a load operation, or a physical backup, such as an export operation.
  • a logical backup such as a load operation
  • a physical backup such as an export operation.
  • the backing up data in the database according to a preset backup policy, including:
  • the data in the database that meets the preset importance level is backed up.
  • the data in the database can be classified according to the degree of importance, and the data with lower importance level can be not backed up, so that when data with low importance levels is abnormal, the deletion process is directly performed.
  • Ability to recover from the database can be performed according to the degree of importance, and the data with lower importance level can be not backed up, so that when data with low importance levels is abnormal, the deletion process is directly performed.
  • the method further includes: clearing the log file of the database, and instructing the database to re-record the log file;
  • the log file is recorded by the database, when the backup is performed, the data before the backup time has been saved in the backup file, and then the portion of the log file before the backup time is not available. It is necessary to save. Therefore, in this embodiment, it is preferable to delete the portion of the log file before the backup time by instructing the database, thereby saving the storage space of the database. It can be understood that when the data abnormality occurs in the database, the data saved in the log file is data between the backup time and the data abnormal time; and the data before the backup time is saved in the backup file.
  • Embodiments of the present invention provide a data recovery method for a database by using a database
  • the data is abnormal
  • the data is verified
  • the abnormal data is found
  • the abnormal data is replaced according to the log file and the backup file of the database, thereby improving the stability and work efficiency of the business operation.
  • FIG. 4 shows a structure of a data recovery device 40 of a database provided by an embodiment of the present invention
  • the device 40 is applied to a database, and specifically, the device 40 may be separate.
  • the present invention is not limited to the above, and the functional units in the device 40 can be stored by a processor, a microprocessor or an application specific integrated circuit.
  • the medium such as a storage medium such as a hard disk, an optical disk, or a flash memory
  • the device 40 may include: a detecting unit 401, a checking unit 402, a searching unit 403, and a restoring unit 404, where
  • the detecting unit 401 is configured to detect that a data abnormality occurs in the database during the running, and trigger the verification unit 402 when detecting that the database has abnormal data;
  • the checking unit 402 is configured to: when the detecting unit 401 detects that the database has abnormal data, verify the data in the database index and the data in the database file, and determine the Abnormal data in the database, and the abnormal data is transmitted to the lookup unit 403;
  • the searching unit 403 is configured to search the log file and the backup file of the database according to the abnormal data determined by the verification unit 402, acquire data to be backed up corresponding to the abnormal data, and store the data to be backed up. Data is transmitted to the recovery unit 404;
  • the recovery unit 404 is configured to replace the abnormal data by using the data to be backed up acquired by the searching unit 403.
  • the detecting unit 401 is configured to detect the data abnormality when the database performs the structured query language SQL access or update data; or detect that the database abnormally exits; or, detect The database is detected to start abnormally after exiting.
  • the verification unit 402 can also be configured to acquire a table in which the database is operating when the data is abnormal; compare the index of the table with the data in the database file, thereby Judging the accuracy of the data: if they are consistent, the description is accurate; if they are inconsistent, the description is inaccurate, and the data is abnormal data.
  • the searching unit 403 is configured to search the log file according to the abnormal data, and acquire data to be backed up corresponding to the abnormal data in the log file;
  • the backup file is searched according to the abnormal data, and the data to be backed up corresponding to the abnormal data in the backup file is acquired;
  • the abnormal data is cleared. It should be noted that when there is no data to be backed up corresponding to the abnormal data in the log file and the backup file, the importance level of the abnormal data is low, so that abnormal data that is not important can be directly deleted. Drop it.
  • the recovery unit 404 is configured to clear abnormal data in the database; and insert the data to be backed up into the database.
  • the recovery unit 404 may first clear the abnormal data in the database, and then insert the data to be backed up into an insert statement into the database.
  • the data recovery device 40 is further configured to back up data in the database according to a preset backup policy to obtain the backup file.
  • the backup unit 405 is further configured to: back up the database according to a preset period value and/or a system busyness of the database.
  • the backup unit 405 can periodically back up the database, or when the database running state is idle, such as when the CPU usage of the database is relatively low and the disk IO of the database is idle, the backup can be performed. The time of the backup.
  • the backup file obtained by the backup unit 405 for backing up the database can be It is a logical backup, such as a load operation; it can also be a physical backup, such as an export operation. In this embodiment, it is preferred to perform a logical backup first, because the physical backup needs to back up the data of the entire database, so it is usually used in the case of a serious abnormality in the database.
  • the backup unit 405 is further configured to: back up data in the database that meets a preset importance level.
  • the backup unit 405 can classify the data in the database according to the degree of importance, and can not back up the data with lower importance level, so that when data with lower importance levels has data abnormality, directly The deletion process will be able to recover the database.
  • the backup unit 405 is further configured to: before the data in the database is backed up according to the preset backup policy, clear the log file of the database, and instruct the database to be re-re- Record the log file.
  • the backup unit 405 can save the storage space of the database by instructing the database to delete the part of the log file before the backup time. It can be understood that when the data abnormality occurs in the database, the data saved in the log file is data between the backup time and the data abnormal time; and the data before the backup time is saved in the backup file.
  • the embodiment of the present invention provides a database data recovery device 40, which improves data stability and work efficiency by performing data verification when a database is abnormal, and restoring abnormal data through backup and log files.
  • embodiments of the present invention can be provided as a method, system, or computer program product. Accordingly, the present invention can take the form of a hardware embodiment, a software embodiment, or a combination of software and hardware. Moreover, the invention may be employed in one or more of its A computer program product embodied on a computer usable storage medium (including but not limited to disk storage and optical storage, etc.) containing computer usable program code.
  • a computer usable storage medium including but not limited to disk storage and optical storage, etc.
  • the computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture comprising the instruction device.
  • the apparatus implements the functions specified in one or more blocks of a flow or a flow and/or block diagram of the flowchart.
  • These computer program instructions can also be loaded onto a computer or other programmable data processing device such that a series of operational steps are performed on a computer or other programmable device to produce computer-implemented processing for execution on a computer or other programmable device.
  • the instructions provide steps for implementing the functions specified in one or more of the flow or in a block or blocks of a flow diagram.

Abstract

公开了一种数据库的数据恢复方法、设备及计算机存储介质;方法可以包括:当数据库出现数据异常时,将数据库索引中的数据与所述数据库文件中的数据进行校验,确定所述数据库中的异常数据(S101);根据所述异常数据查找所述数据库的日志文件及备份文件,获取与所述异常数据对应的待备份数据(S102);将所述待备份数据替换所述异常数据(S103)。

Description

数据库的数据恢复方法、设备及计算机存储介质 技术领域
本发明涉及数据存储领域,尤其涉及一种数据库的数据恢复方法、设备及计算机存储介质。
背景技术
目前,数据库针对数据异常的一般处理方式是数据库停止服务或数据库在异常的状态下提供服务。然而,有时在数据库异常时,需要将数据库的数据恢复至前一段时间的状态。此时,若数据库无法以快速且准确的方式恢复数据,将造成数据库长时间无法提供正确的数据,而造成使用者的不便利或者造成相关的业务无法正常运作。
发明内容
本发明实施例期望提供一种数据库的数据恢复方法、设备及计算机存储介质,提高了业务运行的稳定性和工作效率。
本发明实施例的技术方案是这样实现的:
第一方面,本发明实施例提供了一种数据库的数据恢复设备,所述数据恢复设备包括:侦测单元、校验单元、查找单元和恢复单元,其中,
所述侦测单元,配置为侦测所述数据库在运行过程中出现数据异常,并当侦测到所述数据库出现数据异常时,触发所述校验单元;
所述校验单元,配置为当所述侦测单元侦测到所述数据库出现数据异常时,将所述数据库索引中的数据与所述数据库文件中的数据进行校验,确定所述数据库中的异常数据,并将所述异常数据传输至所述查找单元;
所述查找单元,配置为根据所述校验单元确定的所述异常数据查找所 述数据库的日志文件及备份文件,获取与所述异常数据对应的待备份数据,并将所述待备份数据传输至所述恢复单元;
所述恢复单元,配置为利用所述查找单元获取的所述待备份数据替换所述异常数据。
优选地,所述侦测单元,配置为当所述数据库在执行结构化查询语言SQL访问或更新数据时,侦测所述数据异常;或者,侦测所述数据库异常退出;或者,侦测所述数据库异常退出后启动。
优选地,所述查找单元,配置为根据所述异常数据查找所述日志文件,获取所述日志文件中与所述异常数据对应的待备份数据;以及,
当所述日志文件中没有找到与所述异常数据对应的待备份数据时,根据所述异常数据查找所述备份文件,获取所述备份文件中与所述异常数据对应的待备份数据;以及,
当所述备份文件中没有找到与所述异常数据对应的待备份数据时,清除所述异常数据。
优选地,所述恢复单元,配置为清除所述数据库中的异常数据;并将所述待备份数据插入到所述数据库中。
优选地,所述数据恢复设备还包括备份单元,配置为按照预设的备份策略对所述数据库中的数据进行备份,获得所述备份文件。
优选地,所述备份单元,还配置为:按照预设的周期值和/或所述数据库的系统繁忙程度对所述数据库进行备份。
优选地,所述备份单元,还配置为:将所述数据库中满足预设的重要性级别的数据进行备份。
优选地,所述备份单元,还配置为:在按照所述预设的备份策略对所述数据库的中的数据进行备份之前,将所述数据库的日志文件进行清除,并指示所述数据库重新记录所述日志文件。
第二方面,本发明实施例提供了一种数据库的数据恢复方法,所述方法包括:
侦测所述数据库在运行过程中出现数据异常,将所述数据库索引中的数据与所述数据库文件中的数据进行校验,确定所述数据库中的异常数据;
根据所述异常数据查找所述数据库的日志文件及备份文件,获取与所述异常数据对应的待备份数据;
利用所述待备份数据替换所述异常数据。
优选地,所述侦测所述数据库在运行过程中出现数据异常,包括:当所述数据库在执行结构化查询语言SQL访问或更新数据时,所述数据异常;或者,所述数据库异常退出;或者,所述数据库异常退出后启动。
优选地,所述根据所述异常数据查找所述数据库的日志文件及备份文件,获取与所述异常数据对应的待备份数据,包括:
根据所述异常数据查找所述日志文件,获取所述日志文件中与所述异常数据对应的待备份数据;
当所述日志文件中没有找到与所述异常数据对应的待备份数据时,根据所述异常数据查找所述备份文件,获取所述备份文件中与所述异常数据对应的待备份数据;
当所述备份文件中没有找到与所述异常数据对应的待备份数据时,清除所述异常数据。
优选地,所述将所述待备份数据替换所述异常数据,包括:
清除所述数据库中的异常数据;并将所述待备份数据插入到所述数据库中。
优选地,所述方法还包括:按照预设的备份策略对所述数据库中的数据进行备份,获得所述备份文件。
优选地,所述按照预设的备份策略对所述数据库中的数据进行备份, 包括:
按照预设的周期值和/或所述数据库的系统繁忙程度对所述数据库进行备份。
优选地,所述按照预设的备份策略对所述数据库中的数据进行备份,包括:
将所述数据库中满足预设的重要性级别的数据进行备份。
优选地,在按照所述预设的备份策略对所述数据库的中的数据进行备份之前,所述方法还包括:将所述数据库的日志文件进行清除,并指示所述数据库重新记录所述日志文件。
第三方面,本发明实施例提供一种计算机存储介质,所述计算机存储介质中存储有计算机可执行指令,所述计算机可执行指令用于执行上述记载的数据库的数据恢复方法。
本发明实施例提供了一种数据库的数据恢复方法、设备及计算机存储介质,通过在数据库异常时进行数据校验,并通过备份以及日志文件对异常数据进行恢复,从而提高了业务运行的稳定性和工作效率。
附图说明
图1为本发明实施例提供的一种数据库的数据恢复方法流程示意图;
图2为本发明实施例提供的一种数据库索引值与数据库中的数据之间的映射关系示意图;
图3为本发明实施例提供的一种数据库中用于数据恢复的文件的结构示意图;
图4为本发明实施例提供的一种数据库的数据恢复设备结构示意图;
图5为本发明实施例提供的另一种数据库的数据恢复设备结构示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述。
参见图1,其示出了本发明实施例提供的一种数据库的数据恢复方法流程,该方法可以应用于所述数据库中,该方法可以包括:
S101:当所述数据库出现数据异常时,将所述数据库索引中的数据与所述数据库文件中的数据进行校验,确定所述数据库中的异常数据;
示例性地,在本实施例中,所述数据库出现数据异常,可以包括:当所述数据库在执行结构化查询语言(SQL,Structured Query Language)访问或更新数据时,所述数据异常,比如:数据库的索引出现了重复键或索引值为一个非法值;或者,所述数据库异常退出;或者,所述数据库异常退出后启动等等。这些异常发生后,都需要通过确定这些异常情况是否是由于数据或索引的异常导致的。
示例性地,将所述数据库索引中的数据与所述数据库文件中的数据进行校验,可以依据图2所示的所述数据库索引值与所述数据库中的数据之间的映射关系进行校验,具体可以包括以下步骤:首先获取数据异常时数据库正在操作的表;然后将该表的索引跟数据库文件中的数据进行一一进行比对,由此来判断数据的准确性:若一致,则说明准确;若不一致,则说明不准确,该数据为异常数据。
S102:根据所述异常数据查找所述数据库的日志文件及备份文件,获取与所述异常数据对应的待备份数据;
示例性地,如图3所示的所述数据库中用于数据恢复的文件,所述根据所述异常数据查找所述数据库的日志文件及备份文件,获取与所述异常数据对应的待备份数据,包括:
根据所述异常数据查找所述日志文件,获取所述日志文件中与所述异 常数据对应的待备份数据;以及,
当所述日志文件中没有找到与所述异常数据对应的待备份数据时,根据所述异常数据查找所述备份文件,获取所述备份文件中与所述异常数据对应的待备份数据;以及,
当所述备份文件中没有找到与所述异常数据对应的待备份数据时,清除所述异常数据,需要说明的是,当日志文件和备份文件中均没有与所述异常数据对应的待备份数据,那么说明所述异常数据的重要性级别较低,因此,可以将将不重要的异常数据直接删掉。
还需要说明的是,由于每次备份之间具有一定的时间间隔,那么在这个时间间隔之内,只有日志文件才能够反映数据库的数据操作,比如用于记录数据库的修改以及潜在的修改行为的binlog日志,这个文件可以用来弥补由于两个备份文件的时间间隔导致的数据记录损失,从而使得待备份数据能够尽可能的反映出数据库出现数据异常那一时刻的数据情况。
S103:将所述待备份数据替换所述异常数据;
示例性地,所述将所述待备份数据替换所述异常数据,具体可以包括:
清除所述数据库中的异常数据;并将所述待备份数据插入到所述数据库中。
例如,在本实施例中,可以先将数据库中的异常数据清除掉,然后将待备份数据组成一条insert语句插入到数据库中。
需要说明的是,由于待备份数据是从日志文件和备份文件中获取,而日志文件是数据库在运行过程中进行记录的,因此,在本实施例中,所述方法还可以包括:按照预设的备份策略对所述数据库中的数据进行备份。
优选地,所述按照预设的备份策略对所述数据库中的数据进行备份,包括:
按照预设的周期值和/或所述数据库的繁忙程度对所述数据库进行备 份。
例如,可以定期地对数据库进行备份,也可以在数据库运行状态空闲时,比如数据库的CPU占用比较低和数据库的磁盘IO读取空闲时进行备份,也可以将两者进行结合考虑进行备份的时间。
可以理解的,对数据库进行备份所得到的备份文件,可以是逻辑备份,例如load操作;也可以是物理备份,例如export操作。本实施例中优选首先进行逻辑备份,因为物理备份需要备份整个数据库的数据,因此通常在数据库出现严重异常的情况下使用。
优选地,所述按照预设的备份策略对所述数据库中的数据进行备份,包括:
将所述数据库中满足预设的重要性级别的数据进行备份。
例如,可以将数据库中的数据按照重要性程度进行级别划分,对于重要性级别较低的数据可以不进行备份,从而使得当这些重要性级别较低的数据出现数据异常时,直接进行删除处理就能够对数据库进行恢复。
优选地,在按照所述预设的备份策略对所述数据库的中的数据进行备份之前,所述方法还包括:将所述数据库的日志文件进行清除,并指示所述数据库重新记录所述日志文件;
在本实施例中,由于日志文件是由数据库进行记录,因此,当进行备份的时候,备份时刻之前的数据已经保存在备份文件中,那么,日志文件中在备份时刻之前的那部分内容就没有必要进行保存,所以,本实施例优选地,通过指示数据库将日志文件中在备份时刻之前的那部分内容进行删除,从而能够节省数据库的存储空间。可以理解地,当数据库出现数据异常时,日志文件中所保存的数据为备份时刻至数据异常时刻之间的数据;而备份时刻之前的数据保存在备份文件中。
本发明实施例提供了一种数据库的数据恢复方法,通过当数据库出现 数据异常时对数据进行校验,发现异常数据,并根据数据库的日志文件及备份文件将异常数据进行替换,从而提高了业务运行的稳定性和工作效率。
基于前述实施例相同的技术构思,参见图4,其示出了本发明实施例提供的一种数据库的数据恢复设备40结构,该设备40应用于数据库中,具体地,该设备40可以是单独存在于数据库之外,也可以通过硬件和软件的方式耦合在数据库中,本发明实施例对此不作具体限定,如设备40中的各功能单元可由处理器、微处理器或专用集成电路配合存储介质(如硬盘、光盘、闪存等存储介质)实现;该设备40可以包括:侦测单元401、校验单元402、查找单元403和恢复单元404,其中,
所述侦测单元401,配置为侦测所述数据库在运行过程中出现数据异常,并当侦测到所述数据库出现数据异常时,触发所述校验单元402;
所述校验单元402,配置为当所述侦测单元401侦测到所述数据库出现数据异常时,将所述数据库索引中的数据与所述数据库文件中的数据进行校验,确定所述数据库中的异常数据,并将所述异常数据传输至所述查找单元403;
所述查找单元403,配置为根据所述校验单元402确定的所述异常数据查找所述数据库的日志文件及备份文件,获取与所述异常数据对应的待备份数据,并将所述待备份数据传输至所述恢复单元404;
所述恢复单元404,配置为利用所述查找单元403获取的所述待备份数据替换所述异常数据。
示例性地,所述侦测单元401,配置为当所述数据库在执行结构化查询语言SQL访问或更新数据时,侦测所述数据异常;或者,侦测所述数据库异常退出;或者,侦测所述数据库异常退出后启动。
示例性地,校验单元402还可以配置为获取数据异常时数据库正在操作的表;将该表的索引跟数据库文件中的数据进行一一进行比对,由此来 判断数据的准确性:若一致,则说明准确;若不一致,则说明不准确,该数据为异常数据。
示例性地,所述查找单元403,配置为根据所述异常数据查找所述日志文件,获取所述日志文件中与所述异常数据对应的待备份数据;以及,
当所述日志文件中没有找到与所述异常数据对应的待备份数据时,根据所述异常数据查找所述备份文件,获取所述备份文件中与所述异常数据对应的待备份数据;以及,
当所述备份文件中没有找到与所述异常数据对应的待备份数据时,清除所述异常数据。需要说明的是,当日志文件和备份文件中均没有与所述异常数据对应的待备份数据,那么说明所述异常数据的重要性级别较低,因此,可以将将不重要的异常数据直接删掉。
示例性地,所述恢复单元404,配置为清除所述数据库中的异常数据;并将所述待备份数据插入到所述数据库中。例如,在本实施例中,恢复单元404可以先将数据库中的异常数据清除掉,然后将待备份数据组成一条insert语句插入到数据库中。
需要说明的是,由于待备份数据是从日志文件和备份文件中获取,而日志文件是数据库在运行过程中进行记录的,因此,在本实施例中,参见图5,所述数据恢复设备40还包括备份单元405,配置为按照预设的备份策略对所述数据库中的数据进行备份,获得所述备份文件。
优选地,所述备份单元405,还配置为:按照预设的周期值和/或所述数据库的系统繁忙程度对所述数据库进行备份。
例如,备份单元405可以定期地对数据库进行备份,也可以在数据库运行状态空闲时,比如数据库的CPU占用比较低和数据库的磁盘IO读取空闲时进行备份,也可以将两者进行结合考虑进行备份的时间。
可以理解的,备份单元405对数据库进行备份所得到的备份文件,可 以是逻辑备份,例如load操作;也可以是物理备份,例如export操作。本实施例中优选首先进行逻辑备份,因为物理备份需要备份整个数据库的数据,因此通常在数据库出现严重异常的情况下使用。
优选地,所述备份单元405,还配置为:将所述数据库中满足预设的重要性级别的数据进行备份。
例如,备份单元405可以将数据库中的数据按照重要性程度进行级别划分,对于重要性级别较低的数据可以不进行备份,从而使得当这些重要性级别较低的数据出现数据异常时,直接进行删除处理就能够对数据库进行恢复。
优选地,所述备份单元405,还配置为:在按照所述预设的备份策略对所述数据库的中的数据进行备份之前,将所述数据库的日志文件进行清除,并指示所述数据库重新记录所述日志文件。
由于日志文件是由数据库进行记录,因此,当备份单元405进行备份的时候,备份时刻之前的数据已经保存在备份文件中,那么,日志文件中在备份时刻之前的那部分内容就没有必要进行保存,所以,本实施例优选地,备份单元405通过指示数据库将日志文件中在备份时刻之前的那部分内容进行删除,从而能够节省数据库的存储空间。可以理解地,当数据库出现数据异常时,日志文件中所保存的数据为备份时刻至数据异常时刻之间的数据;而备份时刻之前的数据保存在备份文件中。
本发明实施例提供了一种数据库的数据恢复设备40,通过在数据库异常时进行数据校验,并通过备份以及日志文件对异常数据进行恢复,从而提高了业务运行的稳定性和工作效率。
本领域内的技术人员应明白,本发明的实施例可提供为方法、系统、或计算机程序产品。因此,本发明可采用硬件实施例、软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其 中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器和光学存储器等)上实施的计算机程序产品的形式。
本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
以上所述,仅为本发明的较佳实施例而已,并非用于限定本发明的保护范围。

Claims (17)

  1. 一种数据库的数据恢复设备,所述数据恢复设备包括:侦测单元、校验单元、查找单元和恢复单元,其中,
    所述侦测单元,配置为侦测所述数据库在运行过程中出现数据异常,并当侦测到所述数据库出现数据异常时,触发所述校验单元;
    所述校验单元,配置为当所述侦测单元侦测到所述数据库出现数据异常时,将数据库索引中的数据与所述数据库文件中的数据进行校验,确定所述数据库中的异常数据,并将所述异常数据传输至所述查找单元;
    所述查找单元,配置为根据所述校验单元确定的所述异常数据查找所述数据库的日志文件及备份文件,获取与所述异常数据对应的待备份数据,并将所述待备份数据传输至所述恢复单元;
    所述恢复单元,配置为利用所述查找单元获取的所述待备份数据替换所述异常数据。
  2. 根据权利要求1所述的数据恢复设备,其中,所述侦测单元,配置为当所述数据库在执行结构化查询语言SQL访问或更新数据时,侦测所述数据异常;或者,侦测所述数据库异常退出;或者,侦测所述数据库异常退出后启动。
  3. 根据权利要求1所述的数据恢复设备,其中,所述查找单元,配置为根据所述异常数据查找所述日志文件,获取所述日志文件中与所述异常数据对应的待备份数据;以及,
    当所述日志文件中没有找到与所述异常数据对应的待备份数据时,根据所述异常数据查找所述备份文件,获取所述备份文件中与所述异常数据对应的待备份数据;以及,
    当所述备份文件中没有找到与所述异常数据对应的待备份数据时,清除所述异常数据。
  4. 根据权利要求1所述的数据恢复设备,其中,所述恢复单元,配置为清除所述数据库中的异常数据;并将所述待备份数据插入到所述数据库中。
  5. 根据权利要求1至4任一项所述的数据恢复设备,其中,所述数据恢复设备还包括备份单元,配置为按照预设的备份策略对所述数据库中的数据进行备份,获得所述备份文件。
  6. 根据权利要求5所述的数据恢复设备,其中,所述备份单元,还配置为:按照预设的周期值和/或所述数据库的系统繁忙程度对所述数据库进行备份。
  7. 根据权利要求5所述的数据恢复设备,其中,所述备份单元,还配置为:将所述数据库中满足预设的重要性级别的数据进行备份。
  8. 根据权利要求5所述的数据恢复设备,其中,所述备份单元,还配置为:在按照所述预设的备份策略对所述数据库的中的数据进行备份之前,将所述数据库的日志文件进行清除,并指示所述数据库重新记录所述日志文件。
  9. 一种数据库的数据恢复方法,所述方法包括:
    侦测所述数据库在运行过程中出现数据异常,将所述数据库索引中的数据与所述数据库文件中的数据进行校验,确定所述数据库中的异常数据;
    根据所述异常数据查找所述数据库的日志文件及备份文件,获取与所述异常数据对应的待备份数据;
    利用所述待备份数据替换所述异常数据。
  10. 根据权利要求9所述的方法,其中,所述侦测数据库在运行过程中出现数据异常,包括:当所述数据库在执行结构化查询语言SQL访问或更新数据时,所述数据异常;或者,所述数据库异常退出;或者,所述数据库异常退出后启动。
  11. 根据权利要求9所述的方法,其中,所述根据所述异常数据查找所述数据库的日志文件及备份文件,获取与所述异常数据对应的待备份数据,包括:
    根据所述异常数据查找所述日志文件,获取所述日志文件中与所述异常数据对应的待备份数据;
    当所述日志文件中没有找到与所述异常数据对应的待备份数据时,根据所述异常数据查找所述备份文件,获取所述备份文件中与所述异常数据对应的待备份数据;
    当所述备份文件中没有找到与所述异常数据对应的待备份数据时,清除所述异常数据。
  12. 根据权利要求9所述的方法,其中,所述利用所述待备份数据替换所述异常数据,包括:
    清除所述数据库中的异常数据;并将所述待备份数据插入到所述数据库中。
  13. 根据权利要求9至12任一项所述的方法,其中,所述方法还包括:按照预设的备份策略对所述数据库中的数据进行备份,获得所述备份文件。
  14. 根据权利要求13所述的方法,其中,所述按照预设的备份策略对所述数据库中的数据进行备份,包括:
    按照预设的周期值和/或所述数据库的系统繁忙程度对所述数据库进行备份。
  15. 根据权利要求13所述的方法,其中,所述按照预设的备份策略对所述数据库中的数据进行备份,包括:
    将所述数据库中满足预设的重要性级别的数据进行备份。
  16. 根据权利要求13所述的方法,其中,在按照所述预设的备份策略对所述数据库的中的数据进行备份之前,所述方法还包括:将所述数据库 的日志文件进行清除,并指示所述数据库重新记录所述日志文件。
  17. 一种计算机存储介质,所述计算机存储介质中存储有计算机可执行指令,所述计算机可执行指令配置为权利要求9至16任一项所述的数据库的数据恢复方法。
PCT/CN2015/074734 2014-10-15 2015-03-20 数据库的数据恢复方法、设备及计算机存储介质 WO2016058333A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410545761.5 2014-10-15
CN201410545761.5A CN105573859A (zh) 2014-10-15 2014-10-15 一种数据库的数据恢复方法和设备

Publications (1)

Publication Number Publication Date
WO2016058333A1 true WO2016058333A1 (zh) 2016-04-21

Family

ID=55746049

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/074734 WO2016058333A1 (zh) 2014-10-15 2015-03-20 数据库的数据恢复方法、设备及计算机存储介质

Country Status (2)

Country Link
CN (1) CN105573859A (zh)
WO (1) WO2016058333A1 (zh)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111625396A (zh) * 2019-02-27 2020-09-04 阿里巴巴集团控股有限公司 备份数据的校验方法、服务器及存储介质
CN112100143A (zh) * 2020-09-25 2020-12-18 平安科技(深圳)有限公司 一种文件压缩存储方法、装置、设备及存储介质
CN112363865A (zh) * 2020-10-19 2021-02-12 深圳云天励飞技术股份有限公司 数据库故障恢复方法、装置及人脸图像搜索系统
CN112749043A (zh) * 2021-01-15 2021-05-04 苏州浪潮智能科技有限公司 一种数据库灾备的方法、系统、设备及介质
CN114077599A (zh) * 2021-10-15 2022-02-22 国电南瑞科技股份有限公司 支持动态数据修补的变压器感知量数据库构建方法、装置及系统

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106095808B (zh) * 2016-05-30 2019-07-09 厦门市美亚柏科信息股份有限公司 一种mdb文件碎片恢复的方法和装置
CN107315655B (zh) * 2017-06-02 2020-05-19 北京潘达互娱科技有限公司 一种实时统计的排行榜数据恢复方法与装置
CN107766490A (zh) * 2017-10-17 2018-03-06 链家网(北京)科技有限公司 Sql文件的自动运行方法、系统、设备及存储介质
CN107885617B (zh) * 2017-10-19 2021-05-11 用友网络科技股份有限公司 导出业务数据的方法、系统、计算机设备及可读存储介质
CN108459925B (zh) * 2018-02-10 2022-05-31 深圳市先河系统技术有限公司 私有云设备及其数据库的修复方法、具有存储功能的装置
CN110737718A (zh) * 2018-07-18 2020-01-31 杭州海康威视系统技术有限公司 数据备份方法和装置
CN109062736A (zh) * 2018-08-20 2018-12-21 广州视源电子科技股份有限公司 一种数据备份方法、装置、设备及存储介质
CN111737056A (zh) * 2020-06-24 2020-10-02 中国银行股份有限公司 文件断点重入方法及装置
CN116737467A (zh) * 2023-08-15 2023-09-12 金篆信科有限责任公司 数据库自动检测和修复的方法、装置、系统及介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030191782A1 (en) * 2002-04-09 2003-10-09 International Business Machines Corporation Data recovery system
CN101118509A (zh) * 2007-09-12 2008-02-06 华为技术有限公司 内存数据库远程容灾的方法、装置和系统
CN101923573A (zh) * 2010-08-09 2010-12-22 哈尔滨工程大学 一种针对数据丢失的数据库数据快速恢复方法
WO2014120137A1 (en) * 2013-01-30 2014-08-07 Hewlett-Packard Development Company, L.P. Recovering pages of a database

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7650356B2 (en) * 2004-08-24 2010-01-19 Microsoft Corporation Generating an optimized restore plan
US7814057B2 (en) * 2005-04-05 2010-10-12 Microsoft Corporation Page recovery using volume snapshots and logs
CA2954888C (en) * 2005-06-24 2019-06-04 Catalogic Software, Inc. System and method for high performance enterprise data protection
CN102609337A (zh) * 2012-01-19 2012-07-25 北京神州数码思特奇信息技术股份有限公司 一种内存数据库快速数据恢复方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030191782A1 (en) * 2002-04-09 2003-10-09 International Business Machines Corporation Data recovery system
CN101118509A (zh) * 2007-09-12 2008-02-06 华为技术有限公司 内存数据库远程容灾的方法、装置和系统
CN101923573A (zh) * 2010-08-09 2010-12-22 哈尔滨工程大学 一种针对数据丢失的数据库数据快速恢复方法
WO2014120137A1 (en) * 2013-01-30 2014-08-07 Hewlett-Packard Development Company, L.P. Recovering pages of a database

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111625396A (zh) * 2019-02-27 2020-09-04 阿里巴巴集团控股有限公司 备份数据的校验方法、服务器及存储介质
CN111625396B (zh) * 2019-02-27 2023-05-26 阿里云计算有限公司 备份数据的校验方法、服务器及存储介质
CN112100143A (zh) * 2020-09-25 2020-12-18 平安科技(深圳)有限公司 一种文件压缩存储方法、装置、设备及存储介质
CN112100143B (zh) * 2020-09-25 2023-03-21 平安科技(深圳)有限公司 一种文件压缩存储方法、装置、设备及存储介质
CN112363865A (zh) * 2020-10-19 2021-02-12 深圳云天励飞技术股份有限公司 数据库故障恢复方法、装置及人脸图像搜索系统
CN112749043A (zh) * 2021-01-15 2021-05-04 苏州浪潮智能科技有限公司 一种数据库灾备的方法、系统、设备及介质
CN112749043B (zh) * 2021-01-15 2022-07-08 苏州浪潮智能科技有限公司 一种数据库灾备的方法、系统、设备及介质
CN114077599A (zh) * 2021-10-15 2022-02-22 国电南瑞科技股份有限公司 支持动态数据修补的变压器感知量数据库构建方法、装置及系统

Also Published As

Publication number Publication date
CN105573859A (zh) 2016-05-11

Similar Documents

Publication Publication Date Title
WO2016058333A1 (zh) 数据库的数据恢复方法、设备及计算机存储介质
US8315991B2 (en) Detecting inadvertent or malicious data corruption in storage subsystems and recovering data
US8015430B1 (en) Using asset dependencies to identify the recovery set and optionally automate and/or optimize the recovery
US8627026B2 (en) Storage apparatus and additional data writing method
US8504528B2 (en) Duplicate backup data identification and consolidation
CN102799500B (zh) 系统修复方法及装置
JP2013542513A5 (zh)
US11137930B2 (en) Data protection using change-based measurements in block-based backup
US20070185936A1 (en) Managing deletions in backup sets
US10204016B1 (en) Incrementally backing up file system hard links based on change logs
US20130198134A1 (en) Online verification of a standby database in log shipping physical replication environments
US11531594B2 (en) Data recovery method and apparatus, server, and computer-readable storage medium
WO2018006587A1 (zh) 一种文件存储方法、终端及存储介质
WO2015176433A1 (zh) 一种基于分区表的硬盘修复方法及装置
CN109491834B (zh) 一种应用于数据库的数据恢复方法及装置
JP2014142852A (ja) ストレージシステムおよび制御装置
US20070143591A1 (en) Method for non-destructive restoration of a corrupted operating system
JP2005141683A5 (zh)
US11099946B1 (en) Differential restore using block-based backups
US8261122B1 (en) Estimation of recovery time, validation of recoverability, and decision support using recovery metrics, targets, and objectives
TW201516655A (zh) 基於分散式文檔系統的資料備份還原系統及方法
CN105549985A (zh) 一种增强Linux应用系统可靠性的方法与系统
US8838545B2 (en) Incremental and prioritized restoration of blocks
WO2017067397A1 (zh) 一种数据恢复方法和装置
WO2021061146A1 (en) Lifecycle change cryptographic ledger

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15851108

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15851108

Country of ref document: EP

Kind code of ref document: A1