Data recovery method and device, storage medium, and electronic device

By switching to the standby database for data processing and recovery when the database is abnormal, the problem of low data processing efficiency when the database is damaged is solved, and the synchronization of data processing and recovery is achieved, ensuring data integrity and continuity.

CN114721870BActive Publication Date: 2025-08-15ZHEJIANG DAHUA TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210327301.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-30
Publication Date
2025-08-15
Estimated Expiration
2042-03-30

AI Technical Summary

Technical Problem

In the prior art, when the database is corrupted, the data processing efficiency during the data recovery process is low, which affects the continuity and integrity of the data processing.

Method used

When an abnormality occurs in the main database of the motherboard device, switch to the backup database of the backup device for data processing, and restore the damaged data of the main database in the backup device to achieve uninterrupted data processing of the motherboard device.

Benefits of technology

The synchronization of data processing and recovery is achieved, the data processing efficiency is improved, the integrity and continuity of data is ensured, and data loss is avoided.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114721870B_ABST
    Figure CN114721870B_ABST
Patent Text Reader

Abstract

Embodiments of the present invention provide a data recovery method and apparatus, a storage medium, and an electronic device. The method includes: upon determining that an abnormality has occurred in the startup of a first database, starting a second database according to a first startup process of the first database; upon normal startup of the second database, switching the database currently used by a mainboard device to the second database, thereby instructing the mainboard device to process pending data using the second database; and switching the database currently used by a backup device to the first database, and loading data from the mainboard device into the backup device, thereby restoring damaged data in the first database in the backup device. This invention solves the data recovery problem in related technologies for databases, achieving the effect of accurately and completely recovering lost data in a database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of data, and in particular, to a data recovery method and device, a storage medium, and an electronic device. Background Art

[0002] A database tablespace refers to the physical files that store data and indexes. When a database tablespace becomes corrupted, the database often becomes unbootable, requiring a database administrator (DBA) or developer to recover the data. Common database recovery methods include rewriting the database, using built-in tools to recover data, restoring data from logs, and performing scheduled data backups. However, during this recovery process, the database cannot process data normally, impacting data processing efficiency. Summary of the Invention

[0003] Embodiments of the present invention provide a data recovery method and device, a storage medium, and an electronic device to at least solve the problem of low data processing efficiency during the process of recovering data in a database in the related art.

[0004] According to one embodiment of the present invention, a data recovery method is provided, comprising: when it is determined that an abnormality occurs in the startup of a first database, starting a second database according to the first startup process of the above-mentioned first database, wherein the above-mentioned first database is a main database in a main board device, and the above-mentioned second database is a standby database in a standby board device, the above-mentioned main board device is used to process data to be processed using the above-mentioned main database, and the above-mentioned standby board device is used to back up the data in the above-mentioned main database using the above-mentioned standby database; when the above-mentioned second database is started normally, switching the database currently used by the above-mentioned main board device to the above-mentioned second database to instruct the above-mentioned main board device to process the data to be processed using the above-mentioned second database; switching the database currently used by the above-mentioned standby board device to the above-mentioned first database, and loading the data in the above-mentioned main board device to the above-mentioned standby board device, so as to recover the damaged data in the above-mentioned first database in the above-mentioned standby board device.

[0005] According to another embodiment of the present invention, a data recovery device is provided, characterized in that it includes: a first startup module, which is used to start the second database according to the first startup process of the above-mentioned first database when it is determined that an abnormality occurs in the startup of the first database, wherein the above-mentioned first database is the main database in the main board device, and the above-mentioned second database is the standby database in the standby board device, the above-mentioned main board device is used to use the above-mentioned main database to process the data to be processed, and the above-mentioned standby board device is used to use the above-mentioned standby database to back up the data in the above-mentioned main database; a first switching module, which is used to switch the database currently used by the above-mentioned main board device to the above-mentioned second database when the above-mentioned second database is started normally, so as to instruct the above-mentioned main board device to use the above-mentioned second database to process the above-mentioned data to be processed; a second switching module, which is used to switch the database currently used by the above-mentioned standby board device to the above-mentioned first database, and load the data in the above-mentioned main board device to the above-mentioned standby board device, so as to recover the damaged data in the above-mentioned first database in the above-mentioned standby board device.

[0006] In an exemplary instance, the above-mentioned device also includes: a first trigger module, which is used to trigger the startup of the above-mentioned second database before starting the second database according to the first startup process of the above-mentioned first database when it is determined that an abnormality occurs in the startup of the first database, and when the above-mentioned first database is started normally, to instruct the above-mentioned backup board device to use the above-mentioned second database to back up the data in the above-mentioned first database.

[0007] In an exemplary instance, the above-mentioned device also includes: a first determination module, which is used to trigger the startup of the above-mentioned second database when the above-mentioned first database is started normally, and when it is determined that the startup of the above-mentioned second database is abnormal, determine whether the table space in the above-mentioned second database is damaged; a first recovery module, which is used to recover the damaged data in the table space in the above-mentioned second database in the above-mentioned backup board device when the table space in the above-mentioned second database is damaged.

[0008] In an exemplary instance, the above-mentioned first recovery module includes one of the following: a first loading unit, used to load all the data in the above-mentioned first database currently used by the above-mentioned main board device into the above-mentioned second database in the above-mentioned spare board device, so as to recover the damaged data in the table space in the above-mentioned second database; a first determination unit, used to determine the first difference data between the normal data in the above-mentioned second database and the data in the above-mentioned first database, and load the above-mentioned first difference data into the above-mentioned spare board device, so as to use the above-mentioned first difference data in the above-mentioned spare board device to recover the damaged data in the table space in the above-mentioned second database.

[0009] In an exemplary instance, the above-mentioned device also includes: a first startup module, used to switch the database currently used by the above-mentioned backup board device to the above-mentioned first database, and load the data in the above-mentioned main board device to the above-mentioned backup board device, so as to start the above-mentioned first database according to the second startup process of the above-mentioned second database before restoring the damaged data in the above-mentioned first database in the above-mentioned backup board device; a first indication module, used to instruct the above-mentioned main board device to use the above-mentioned first database to process the above-mentioned data to be processed when the above-mentioned first database is started normally.

[0010] In an exemplary instance, the above-mentioned device also includes at least one of the following: a first detection module, which is used to detect whether a data recovery log of the above-mentioned first database is generated after starting the second database according to the first startup process of the above-mentioned first database when it is determined that an abnormality occurs in the startup of the first database, so as to determine whether the table space in the above-mentioned first database is damaged; a second detection module, which is used to detect whether the data recovery log generated for the above-mentioned first database includes damage information of the above-mentioned table space, so as to determine whether the table space in the above-mentioned first database is damaged.

[0011] In an exemplary embodiment, the apparatus further includes: a second determination module for determining that data in the first database is damaged when it is determined that the table space in the first database is damaged; and a first deletion module for deleting data in the first database.

[0012] In an exemplary instance, the second switching module includes one of the following: a second loading unit for loading all the data in the second database currently used in the main board device into the spare board device, so as to restore the damaged data in the table space in the first database in the spare board device; a second determination unit for determining the second difference data between the data in the second database and the normal data in the first database, and loading the second difference data into the spare board device, so as to restore the damaged data in the table space in the first database in the spare board device using the second difference data.

[0013] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when run.

[0014] According to another embodiment of the present invention, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any one of the above method embodiments.

[0015] With the present invention, if the primary first database currently in use by the mainboard device becomes corrupted, the backup second database in the backup board device is switched to process data. The backup board's currently used database is then switched to the first database, and the damaged data in the first database is restored in the backup board. This ensures uninterrupted data processing by the mainboard device and timely recovery of damaged data, achieving the goal of simultaneous data processing and data recovery. This solves the problem of low data processing efficiency during database data recovery in related technologies, thereby improving data processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 This is a hardware structure block diagram of a mobile terminal for a data recovery method according to an embodiment of the present invention;

[0017] Figure 2 is a flow chart of a data recovery method according to an embodiment of the present invention;

[0018] Figure 3 is a structural block diagram of a dual-control device according to an embodiment of the present invention;

[0019] Figure 4 is a flowchart of interaction between dual-control devices according to an embodiment of the present invention;

[0020] Figure 5 is a structural block diagram of a data recovery device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0021] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with embodiments.

[0022] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0023] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 FIG. 1 is a hardware structure diagram of a mobile terminal of a data recovery method according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.

[0024] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the data recovery method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0025] The transmission device 106 is used to receive or send data via a network. A specific example of the aforementioned network may include a wireless network provided by the mobile terminal's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In one embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0026] In this embodiment, a data recovery method is provided. Figure 2 FIG. 1 is a flow chart of a data recovery method according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:

[0027] Step S202: If it is determined that an abnormality occurs in the startup of the first database, the second database is started according to the first startup process of the first database, wherein the first database is a primary database in the main board device, and the second database is a backup database in the backup board device. The main board device is used to process the data to be processed using the primary database, and the backup board device is used to back up the data in the primary database using the backup database.

[0028] In this embodiment, the main board device and the backup board device form a dual-control device, such as Figure 3 As shown, the mainboard device is used for data processing, such as querying, storing, and deleting data.

[0029] The backup device backs up data processed by the main device and, if an exception occurs in the main device's database, switches the database in the backup device to the main device for data processing. For example, if the main device's service program crashes, the main device loses power, or the main device loses network connectivity, causing the first database to start abnormally, the backup device triggers the second database to take over data processing, instructing the main device to use the second database for data processing.

[0030] In this embodiment, the main database in the main board device and the standby database in the standby board device can together form a database cluster. It should be noted that the number of standby databases can be one or more to ensure the stability of the system. Figure 3 As shown in the figure, the primary database in the main board device and the standby database in the standby board device form a Galera For Maria DB database cluster, which can achieve data synchronization after database switchover and continuity of historical data, so that the data in the primary database and the standby database can be kept synchronized.

[0031] Step S204: If the second database is started normally, the database currently used by the mainboard device is switched to the second database to instruct the mainboard device to process the data to be processed using the second database;

[0032] In this embodiment, the database currently used by the mainboard device includes but is not limited to the first database. For example, if an abnormality occurs when starting the first database and a normal startup of the second database occurs, the mainboard device switches the first database to the second database.

[0033] Step S206: Switch the database currently used by the standby device to the first database, and load the data in the main device to the standby device to restore the damaged data in the first database in the standby device.

[0034] In this embodiment, the database currently used by the standby device may be the second database or the first database. For example, if the second database switches to the main device for data processing, the database used by the standby device will switch from the second database to the first database. After the database switch, the standby device can further recover the damaged data in the first database, thereby achieving the purpose of automatically recovering the failed database.

[0035] The execution subject of the above steps may be a terminal, a server, a specific processor provided in the terminal or server, or a processor or processing device provided relatively independently from the terminal or server, etc., but is not limited thereto.

[0036] Through the above steps, if the primary first database currently used by the mainboard device becomes corrupted, the backup second database in the backup board device is switched to process the data. The database currently used by the backup board is then switched to the first database, and the damaged data in the first database is restored in the backup board. This ensures uninterrupted data processing by the mainboard device and timely restoration of damaged data, achieving the goal of simultaneous data processing and data restoration. This solves the problem of low data processing efficiency during database data restoration in related technologies, thereby improving data processing efficiency.

[0037] In an exemplary embodiment, when it is determined that an abnormality occurs in the startup of the first database, before starting the second database according to the first startup process of the first database, the method further includes:

[0038] S11 triggers the startup of the second database when the first database is started normally, so as to instruct the standby board device to use the second database to back up the data in the first database.

[0039] In this embodiment, when the first database starts normally, the standby device is notified to start the second database. When the second database starts successfully, the standby device uses the second database to back up the data processed in the first database.

[0040] Through this embodiment, the main board device uses the first database to process data while the backup board device uses the second database to back up the processed data. By backing up the data, data loss can be avoided and the overall stability of the system can be guaranteed.

[0041] In an exemplary embodiment, when the first database is started normally, after triggering the startup of the second database, the method further includes:

[0042] S21, when it is determined that an abnormality occurs in starting the second database, determining whether a table space in the second database is damaged;

[0043] S22: When the table space in the second database is damaged, the damaged data in the table space in the second database is restored in the standby board device.

[0044] In this embodiment, the reasons for the abnormal startup of the second database include but are not limited to a crash of a service program of the standby device, a power failure of the standby device, a network disconnection of the standby device, and the like.

[0045] In this embodiment, the tablespace refers to the physical file in which the second database stores data and indexes. Tablespace corruption occurs when the data in the tablespace becomes invalid due to some abnormal reason. Abnormal reasons include, but are not limited to, the following: 1) The backup device suddenly loses power while the second database is writing data, causing data file corruption; 2) The backup device is forced to shut down while the second database is writing data, failing to properly shut down the second database; 3) The service process of the second database is destroyed (killed) during the data writing process; 4) The service process of the second database encounters an abnormality due to a bug during the data writing process; 5) The physical disk in the backup device is damaged. When the tablespace is corrupted, the database often fails to start.

[0046] Through this embodiment, when an abnormality occurs in the second database, the damaged data in the table space of the second database is restored in the standby device. This does not affect the main device's use of the currently used first database to process data, thus ensuring data processing efficiency and avoiding data loss.

[0047] In an exemplary embodiment, when a table space in the second database is damaged, recovering the damaged data in the table space in the second database on a standby device includes one of the following:

[0048] S221, in the standby device, all the data in the first database currently used by the main device is loaded into the second database to restore the damaged data in the table space in the second database;

[0049] In this embodiment, loading all the data in the first database currently used by the mainboard device into the second database includes, but is not limited to, synchronizing the data in the first database to the tablespace in the second database. For example, all data originally stored in the tablespace in the second database may be deleted, and then all newly added data and original data in the first database may be synchronized to the tablespace in the second database.

[0050] S222, determining first difference data between normal data in the second database and data in the first database, and loading the first difference data into a spare board device, so as to use the first difference data in the spare board device to restore damaged data in the table space of the second database.

[0051] In this embodiment, the normal data in the second database is compared with the original data and newly added data in the first database. Data that differs from the normal data in the second database is identified as first difference data. Synchronizing this first difference data with the second database allows recovery of damaged data in the tablespace. Furthermore, the first difference data in this embodiment also includes data newly written to the first database during the synchronization process.

[0052] Through this embodiment, by using the data in the mainboard device to recover the damaged data in the table space, no matter how damaged the table space is, the data can be completely recovered, ensuring that the data is not lost.

[0053] In an exemplary embodiment, before switching the database currently used by the standby device to the first database and loading the data in the main device to the standby device to restore the damaged data in the first database in the standby device, the method further includes:

[0054] S31, starting the first database according to the second startup process of the second database;

[0055] S32: When the first database is started normally, instruct the mainboard device to process the data to be processed using the first database.

[0056] In this embodiment, if the first database currently used by the main board fails to start, the first database is restarted periodically according to the startup method of the database in the backup board. If the first database restarts successfully, the database currently used by the main board is switched to the successfully restarted first database. The main board then resumes data processing using the first database.

[0057] Through this embodiment, by retrying to start the first database, it is possible to ensure that normal devices take over the task of real-time data processing with the first priority, for example, the storage of real-time video data can ensure the continuity of real-time video data.

[0058] In an exemplary embodiment, when it is determined that an abnormality occurs in the startup of the first database, after starting the second database according to the first startup process of the first database, the method further includes at least one of the following:

[0059] S41, detecting whether a data recovery log of the first database is generated to determine whether a table space in the first database is damaged;

[0060] S42: Detect whether the generated data recovery log of the first database includes damage information of the table space to determine whether the table space in the first database is damaged.

[0061] In this embodiment, the role of the table space in the first database and the cause of table space damage are the same as those of the table space in the second database and the cause of table space damage, which will not be repeated here.

[0062] In this embodiment, when an exception occurs in the first database, a data recovery log can be generated based on the cause of the exception in the first database. For example, when the main control device is writing data using the first database, the mainboard device suddenly loses power, causing the data files in the first database to be damaged. After the mainboard device is powered on again, a data recovery log is generated (for example, the data recovery log is represented as wsrep_recovery.fai). Based on the data recovery log, it can be determined that the table space in the first database is damaged. Alternatively, if the service process of the second database encounters an exception due to its own bug during the data writing process, the generated data recovery log includes information about the table space being damaged (for example, the data recovery log is represented as corruption in the InnoDB tablespace), and it can be clearly determined that the table space in the first database is damaged.

[0063] Through this embodiment, by detecting the content in the database recovery log, it is possible to clearly determine whether the table space is damaged, thereby improving the accuracy of determining whether the table space is damaged.

[0064] In an exemplary embodiment, the method further includes:

[0065] S51, when it is determined that the table space in the first database is damaged, determining that data in the first database is damaged;

[0066] S52: Delete the data in the first database.

[0067] In this embodiment, the purpose of deleting the data in the first database is to proactively clear abnormal data in the database, thereby triggering full or incremental synchronization of normal data from the normal database, thereby ensuring the integrity of data recovery.

[0068] In an exemplary embodiment, switching the database currently used by the standby device to the first database and loading the data in the main device to the standby device includes one of the following:

[0069] S61, loading all the data in the second database currently used in the main board device into the standby board device, so as to restore the damaged data in the table space in the first database in the standby board device;

[0070] S62, determining second difference data between the data in the second database and the normal data in the first database, and loading the second difference data into the standby board device, so as to use the second difference data in the standby board device to restore the damaged data in the table space of the first database.

[0071] In this embodiment, the normal data in the first database is compared with the original data and newly added data in the second database. Data that differs from the normal data in the first database is identified as second differential data. This second differential data is synchronized with the first database, enabling recovery of damaged data in the tablespace. Furthermore, the second differential data in this embodiment also includes data newly written to the second database during the synchronization process.

[0072] Through this embodiment, damaged data in the table space is recovered by using the data in the spare board device, so that no matter how damaged the table space is, the data can be completely recovered, thereby avoiding data loss.

[0073] The present invention will be described below in conjunction with specific embodiments:

[0074] This embodiment takes the interactive control of dual-control devices (including a main board device and a backup board device) as an example to illustrate. Figure 4 As shown, the process of interactive control of dual-control devices includes the following steps:

[0075] S401, start dual-control equipment;

[0076] S402: Determine the primary and backup devices in the dual-controller device according to a preset election strategy (e.g., data processing capability) to determine the primary and backup relationships of the devices.

[0077] S403, the mainboard device starts the service program in a master mode (e.g., a mode capable of processing data);

[0078] S404: The standby board device starts the service program in a standby mode (for example, a mode capable of backing up data).

[0079] S405, starting the main database (for example, the first database) in the mainboard device;

[0080] S406, the standby database (e.g., the second database) in the standby board device waits for a message indicating that the primary database of the main board device has been successfully started;

[0081] S407, determine whether the primary database is successfully started, if successful, go to S408, otherwise, go to S409;

[0082] S408, notify the standby database to start, and go to S412 to determine whether the standby board device library is started successfully. If the standby database is started successfully, the process ends, otherwise go to S411;

[0083] S409, the startup of the primary database fails, triggering a switchover of the primary and standby databases; specifically, the switchover includes: switching the standby database to the primary database mode and starting it in the same way as the primary database; switching the primary database to the standby database and starting the primary database in the same way as the standby database;

[0084] S410, determining whether the restart is successful. If the active database is successfully restarted, the active device resumes data processing services using the active database and notifies the standby device to start the standby database. If the active database fails to restart, a scheduled retry is performed (the standby database continues to wait for the active database to start). If the standby database fails to start, the process goes to S411.

[0085] S411, enter the table space damage detection process;

[0086] S413, determining whether the table space of the primary database and the table space of the standby database are damaged. If not, proceed to S414; otherwise, proceed to S415;

[0087] S414, restart;

[0088] S415, detecting whether a database recovery log (wsrep_recovery.fai) is generated; or detecting whether the database recovery log includes table space corruption information, such as "corruption in the Inno DB table space";

[0089] If the tablespace is confirmed to be damaged, the database automatic recovery process is triggered. The database recovery process includes:

[0090] 1) Deleting the tablespace damages the database;

[0091] 2) Trigger full synchronization of database data from the mainboard device;

[0092] 3) Trigger incremental synchronization from the mainboard device to retrieve data newly written to the database during the full synchronization process;

[0093] S416, end.

[0094] In summary, this embodiment utilizes dual-control devices to recover damaged data in the scenario where the database table space is damaged. At the same time, during the database recovery process, the mainboard device continues to process data (for example, performing video storage, data retrieval, etc.), and data processing is not interrupted due to database abnormalities. In addition, during the database table space recovery process, there is no need for developer intervention, no need to use third-party tools or other tedious operations; data is automatically synchronized from the mainboard device, and regardless of the degree of damage to the table space, data can be completely restored, ensuring that data is not lost. Moreover, in the event of an abnormality in the database, the logical relationship between the primary and standby databases is switched, and the first priority ensures that the mainboard device processes data in real time, ensuring data continuity; switching the database recovery to the standby device improves the utilization and reliability of the dual-control device.

[0095] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0096] In this embodiment, a data recovery device is also provided, which is used to implement the above-mentioned embodiments and preferred embodiments. Details that have already been described will not be repeated here. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.

[0097] Figure 5 is a structural block diagram of a data recovery device according to an embodiment of the present invention. Figure 5 As shown, the device includes:

[0098] A first startup module 52 is configured to, upon determining that an abnormality occurs in the startup of the first database, start the second database according to the first startup process of the first database, wherein the first database is a primary database in the main board device, and the second database is a backup database in the backup board device, the main board device is configured to process data to be processed using the primary database, and the backup board device is configured to back up data in the primary database using the backup database;

[0099] A first switching module 54 is configured to switch the database currently used by the mainboard device to the second database when the second database is started normally, so as to instruct the mainboard device to process the data to be processed using the second database;

[0100] The second switching module 56 is used to switch the database currently used by the above-mentioned standby device to the above-mentioned first database, and load the data in the above-mentioned main device to the above-mentioned standby device to restore the damaged data in the above-mentioned first database in the above-mentioned standby device.

[0101] In an exemplary embodiment, the apparatus further comprises:

[0102] The first trigger module is used to trigger the startup of the above-mentioned second database before starting the second database according to the first startup process of the above-mentioned first database when it is determined that an abnormality occurs in the startup of the first database, and when the above-mentioned first database is started normally, to instruct the above-mentioned backup board device to use the above-mentioned second database to back up the data in the above-mentioned first database.

[0103] In an exemplary embodiment, the apparatus further includes: a first determining module configured to, after triggering startup of the second database when the first database is started normally, determine whether a tablespace in the second database is damaged if it is determined that startup of the second database is abnormal;

[0104] The first recovery module is used to recover the damaged data in the table space in the second database in the standby board device when the table space in the second database is damaged.

[0105] In an exemplary embodiment, the first recovery module includes one of the following:

[0106] A first loading unit is configured to load, in the standby device, all the data in the first database currently used by the main device into the second database, so as to recover the damaged data in the table space in the second database;

[0107] The first determination unit is used to determine the first difference data between the normal data in the above-mentioned second database and the data in the above-mentioned first database, and load the above-mentioned first difference data into the above-mentioned spare board device, so as to use the above-mentioned first difference data in the above-mentioned spare board device to restore the damaged data in the table space of the above-mentioned second database.

[0108] In an exemplary embodiment, the apparatus further comprises:

[0109] a first startup module, configured to switch the database currently used by the standby device to the first database, and load the data in the main device to the standby device, so as to start the first database according to the second startup process of the second database before restoring the damaged data in the first database in the standby device;

[0110] The first instruction module is used to instruct the mainboard device to process the data to be processed by using the first database when the first database is started normally.

[0111] In an exemplary embodiment, the apparatus further comprises at least one of the following:

[0112] a first detection module configured to, upon determining that an abnormality occurs in the startup of the first database, detect whether a data recovery log of the first database is generated after the second database is started according to the first startup process of the first database, so as to determine whether a table space in the first database is damaged;

[0113] The second detection module is used to detect whether the generated data recovery log of the first database includes damage information of the table space, so as to determine whether the table space in the first database is damaged.

[0114] In an exemplary embodiment, the apparatus further comprises:

[0115] a second determining module, configured to determine that data in the first database is damaged if it is determined that the tablespace in the first database is damaged;

[0116] The first deletion module is used to delete the data in the first database.

[0117] In an exemplary embodiment, the second switching module includes one of the following:

[0118] A second loading unit is configured to load all the data in the second database currently used in the main board device into the standby board device, so as to restore the damaged data in the table space in the first database in the standby board device;

[0119] The second determination unit is used to determine the second difference data between the data in the above-mentioned second database and the normal data in the above-mentioned first database, and load the above-mentioned second difference data into the above-mentioned spare board device, so as to use the above-mentioned second difference data in the above-mentioned spare board device to restore the damaged data in the table space of the above-mentioned first database.

[0120] It should be noted that the above modules can be implemented through software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0121] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when running.

[0122] In this embodiment, the computer-readable storage medium may be configured to store a computer program for executing the above steps.

[0123] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.

[0124] An embodiment of the present invention further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0125] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0126] In an exemplary embodiment, the processor may be configured to execute the above steps through a computer program.

[0127] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail here.

[0128] Obviously, those skilled in the art will appreciate that the various modules or steps of the present invention described above can be implemented using a general-purpose computing device, can be centralized on a single computing device, or can be distributed across a network of multiple computing devices. They can be implemented using program code executable by the computing device, and thus, can be stored in a storage device and executed by the computing device. In some cases, the steps shown or described herein can be performed in a different order than that shown, or can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.

[0129] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the principles of the present invention are intended to be within the scope of protection of the present invention.

Claims

1. A data recovery method, characterized in that: include: When it is determined that an abnormality occurs in the startup of the first database, starting the second database according to the first startup process of the first database, wherein the first database is a primary database in the main board device, and the second database is a standby database in the standby board device, the main board device is used to process the data to be processed by using the primary database, and the standby board device is used to back up the data in the primary database by using the standby database; When the second database is started normally, switching the database currently used by the mainboard device to the second database to instruct the mainboard device to process the data to be processed using the second database; Switching the database currently used by the standby device to the first database, and loading the data in the main device to the standby device, so as to restore the damaged data in the first database in the standby device; Before switching the database currently used by the standby device to the first database and loading the data in the main device to the standby device to restore the damaged data in the first database in the standby device, the method further includes: starting the first database according to a second starting process of the second database; When the first database is started normally, the mainboard device is instructed to process the data to be processed using the first database.

2. The method according to claim 1, characterized in that When it is determined that an abnormality occurs in the startup of the first database, before starting the second database according to the first startup process of the first database, the method further includes: When the first database is started normally, the startup of the second database is triggered to instruct the standby board device to use the second database to back up the data in the first database.

3. The method according to claim 2, characterized in that When the first database is started normally, after triggering the startup of the second database, the method further includes: In the case where it is determined that an abnormality occurs in starting the second database, determining whether a table space in the second database is damaged; In the case where the table space in the second database is damaged, the damaged data in the table space in the second database is restored in the standby board device.

4. The method according to claim 3, characterized in that When the table space in the second database is damaged, restoring the damaged data in the table space in the second database on the standby device includes one of the following: In the standby device, all the data in the first database currently used by the main board device is loaded into the second database to restore the damaged data in the table space in the second database; Determine first difference data between normal data in the second database and data in the first database, load the first difference data into the standby device, and use the first difference data in the standby device to restore damaged data in the table space of the second database.

5. The method according to claim 1, wherein When it is determined that an abnormality occurs in the startup of the first database, after starting the second database according to the first startup process of the first database, the method further includes at least one of the following: detecting whether a data recovery log of the first database is generated to determine whether a table space in the first database is damaged; Check whether the generated data recovery log of the first database includes damage information of the table space to determine whether the table space in the first database is damaged.

6. The method according to claim 5, characterized in that The method further comprises: In a case where it is determined that a table space in the first database is damaged, determining that data in the first database is damaged; Delete the data in the first database.

7. The method according to claim 1, characterized in that Switching the database currently used by the standby device to the first database and loading the data in the main device to the standby device includes one of the following: Loading all the data in the second database currently used in the main board device into the standby board device, so as to restore the damaged data in the table space in the first database in the standby board device; Determine second difference data between the data in the second database and the normal data in the first database, load the second difference data into the spare board device, and use the second difference data in the spare board device to restore the damaged data in the table space of the first database.

8. A data recovery device, characterized in that: include: A first startup module is configured to, when determining that an abnormality occurs in the startup of the first database, start the second database according to the first startup process of the first database, wherein the first database is a primary database in a main board device, and the second database is a standby database in a standby board device, the main board device is configured to use the primary database to process data to be processed, and the standby board device is configured to use the standby database to back up data in the primary database; a first switching module, configured to switch the database currently used by the mainboard device to the second database when the second database is started normally, so as to instruct the mainboard device to process the data to be processed using the second database; A second switching module is used to switch the database currently used by the standby device to the first database, and load the data in the main device to the standby device to restore the damaged data in the first database in the standby device; The device is also used to switch the database currently used by the backup device to the first database, and load the data in the main board device to the backup device, so as to start the first database according to the second startup process of the second database before restoring the damaged data in the first database in the backup device; when the first database is started normally, instruct the main board device to use the first database to process the data to be processed.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method and device for restoring data in embedded database

    CN101894137A

  • DB2 disaster recovery high-availability improving method based on Itanium platform

    CN104660386A

  • Automatic recovery method for databases

    CN106021019A