CN-121764732-B - Database backup method, device, electronic equipment and storage medium
Abstract
The embodiment of the application provides a database backup method, a device, electronic equipment and a storage medium, wherein the method comprises the steps of triggering a database to refresh a data page in a shared cache area to a disk under the condition that a preset time node is reached, and locking the database to switch the file operation of a pre-written log; after basic snapshot data of a database is created and stored, unlocking file operation, monitoring a plurality of pre-written logs output by the database after file operation is recovered, generating incremental log data based on the plurality of pre-written logs and storing the incremental log data, determining a starting file identifier corresponding to the pre-written log with the earliest time in the incremental log data, marking other pre-written logs in the incremental log data in sequence based on the starting file identifier, and creating metadata information corresponding to the basic snapshot data. The scheme realizes the uninterrupted backup of the database, ensures the consistency and the integrity of the data, reduces the backup data quantity and improves the backup efficiency.
Inventors
- YANG XINWEN
- JIN FENG
Assignees
- 深圳市领德创科技有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260303
Claims (8)
- 1. A method for backing up a database, the method comprising: Under the condition that a preset time node is reached, triggering a database to refresh a data page in a shared buffer area to a disk, and locking the file operation of the database switching pre-write log, wherein the shared buffer area is a buffer area which is arranged in a memory and is used for temporarily storing high-frequency access data pages, and the file operation of the database switching pre-write log is locked by implanting a self-grinding hook function or a self-defined expansion plug-in unit in a kernel layer, so that the file operation of the database switching pre-write log is temporarily in a frozen state, but the adding, deleting and modifying operation generated by a service can still be normally written into the current pre-write log; After basic snapshot data of the database are created and stored, unlocking the file operation, monitoring a plurality of pre-written logs output by the database after the file operation is recovered, generating incremental log data based on the plurality of pre-written logs and storing the incremental log data, wherein the basic snapshot data are complete data mirror images at the time point of locking the pre-written log switching, and comprise all data files, configuration files, system tables and data pages of the database; Determining an initial file identifier corresponding to the pre-written log with the earliest time in the incremental log data, and marking other pre-written logs in the incremental log data in sequence based on the initial file identifier, wherein the incremental log data is structured and directly used for recovering incremental backup data formed after the original pre-written log acquired through monitoring is subjected to lightweight processing, and the processing comprises lightweight compression, repeated detection and breakpoint continuous transmission marking; Creating metadata information corresponding to the basic snapshot data to complete data backup of the database, wherein the metadata information comprises the initial file identification; Wherein after the data backup of the database is completed, the method further comprises: Under the condition of triggering a first recovery operation of the database, stopping running a target database instance corresponding to the database; Acquiring first basic snapshot data selected by the first recovery operation, and restoring data corresponding to the target database instance to a recovery time point appointed by the first recovery operation based on the first basic snapshot data and associated first incremental log data; rerun the target database instance; The restoring the data corresponding to the target database instance to the recovery time point specified by the first recovery operation based on the first basic snapshot data and the associated first incremental log data includes: determining a target data directory corresponding to the target database instance; Restoring the data file in the first basic snapshot data to the target data directory, and determining associated first increment log data according to metadata information corresponding to the first basic snapshot data; And re-executing the write operation recorded in the first increment log data according to the generation sequence of the first increment log data until reaching the recovery time point designated by the first recovery operation.
- 2. The database backup method of claim 1, further comprising, after completing the data backup of the database: Under the condition of triggering a second recovery operation of the database, stopping running a target database instance corresponding to the database, and determining a target data directory corresponding to the target database instance; Acquiring second basic snapshot data selected by the second recovery operation, and recovering a data file in the second basic snapshot data to the target data directory; and rerun the target database instance.
- 3. The database backup method of claim 1, further comprising, after completing the data backup of the database: acquiring third basic snapshot data and third incremental log data generated by a target time node; checking whether the target structure and meta information of the third basic snapshot data are complete, and checking whether the third incremental log data are continuous and resolvable; Under the condition that the target structure and the meta information are complete and the third incremental log data are continuous and resolvable, starting a target database instance corresponding to the database, and backing the target database instance to a designated time node based on the third basic snapshot data and the third incremental log data; and marking the third basic snapshot data and the third increment log data as recoverable states under the condition that the rollback of the target database instance is successful.
- 4. The database backup method of claim 1, further comprising, after completing the data backup of the database: the basic snapshot data and the incremental log data are respectively subjected to block verification and comparison with historical backup data of external storage equipment to obtain incremental data blocks; And transmitting the incremental data block to the external storage device so that the external storage device can reconstruct data based on the incremental data block to obtain the basic snapshot data and the incremental log data.
- 5. The database backup method of claim 1, further comprising, after completing the data backup of the database: Screening target basic snapshot data with storage time exceeding preset retention time from the stored basic snapshot data; determining associated target increment log data according to metadata information corresponding to the target basic snapshot data; and deleting the target basic snapshot data and the target increment log data.
- 6. A database backup apparatus, comprising: The initial processing module is configured to trigger the database to refresh the data page in the shared buffer area to the disk and lock the file operation of the database switching pre-written log when the preset time node is reached, wherein the shared buffer area is a buffer area which is arranged in a memory and is used for temporarily storing high-frequency access data pages, the file operation of the database switching pre-written log is locked by implanting a self-grinding hook function or a self-defined expansion plug-in unit into a kernel layer, so that the file operation of the database switching pre-written log is temporarily in a frozen state, but the adding, deleting and modifying operation generated by a service is still kept, and the current pre-written log can be normally written; The data generation module is configured to create basic snapshot data of the database, store the basic snapshot data, unlock the file operation, monitor a plurality of pre-written logs output by the database after the file operation is recovered, generate incremental log data based on the plurality of pre-written logs, and store the incremental log data, wherein the basic snapshot data is a complete data mirror image at a time point when the pre-written logs are locked and switched, and comprises all data files, configuration files, system tables and data pages of the database; The data marking module is configured to determine an initial file identifier corresponding to the pre-written log with the earliest time in the incremental log data, and mark other pre-written logs in the incremental log data in sequence based on the initial file identifier, wherein the incremental log data is structured and directly used for recovering incremental backup data formed by carrying out lightweight processing on the original pre-written log acquired through monitoring, and the processing includes lightweight compression, repeated detection and breakpoint continuous transmission marking; the data association module is configured to create metadata information corresponding to the basic snapshot data so as to complete data backup of the database, wherein the metadata information comprises the initial file identification; The system comprises a first recovery module, a second recovery module, a target database instance, a second recovery module, a first incremental log data and a second incremental log data, wherein the first recovery module is configured to stop running the target database instance corresponding to the database under the condition of triggering a first recovery operation of the database; The first recovery module is specifically configured to determine a target data directory corresponding to a target database instance, recover a data file in the first basic snapshot data to the target data directory, determine associated first incremental log data according to metadata information corresponding to the first basic snapshot data, and re-execute write operations recorded in the first incremental log data according to a generation sequence of the first incremental log data until a recovery time point specified by a first recovery operation is reached.
- 7. An electronic device comprising one or more processors and a memory configured to store one or more programs that, when executed by the one or more processors, cause the one or more processors to implement the database backup method of any of claims 1-5.
- 8. A non-transitory storage medium storing computer executable instructions which, when executed by a computer processor, are configured to perform the database backup method of any of claims 1-5.
Description
Database backup method, device, electronic equipment and storage medium Technical Field The embodiment of the application relates to the technical field of computers, in particular to a database backup method, a database backup device, electronic equipment and a storage medium. Background At present, more and more network additional storage devices integrate object relational databases, become core supports for transformation from simple file storage to intelligent storage, and are widely applied to multiple scenes such as household offices, small and medium-sized enterprises, small machine rooms and the like. The integrated object relational database is mainly used for storing various key structured data, including application configuration (such as backup strategy, sharing rule and equipment operation parameter) of the network additional storage equipment, user data index, multimedia data information (such as photo shooting metadata, video format parameter and file classification label), rights system records (such as user account passwords, shared folder access rights and operation audit logs) and the like. The data directly determine the normal operation and use experience of the network additional storage device, and once the database is damaged, data is lost or disordered, the core functions of intelligent retrieval, authority management and the like of the network additional storage device are disabled, so that a user cannot normally access and manage stored data. In order to avoid the potential risks of hardware faults, software crashes, virus attacks, misoperation and the like faced by the network additional storage equipment, so as to avoid the occurrence of database crashes or data loss, the related technology can stop database services at fixed time and backup in a way of completely copying the database catalogue, can cause interruption of user access, influence service continuity, and has low backup efficiency and needs improvement. Disclosure of Invention The embodiment of the application provides a database backup method, a device, electronic equipment and a storage medium, which solve the problems that in the related art, data block backup can cause user access interruption, business continuity is affected and backup efficiency is low, can realize uninterrupted backup of a database, ensure data consistency and integrity, reduce backup data volume and improve backup efficiency. In a first aspect, an embodiment of the present application provides a database backup method, where the method includes: Triggering a database to refresh data pages in a shared buffer area to a disk under the condition that a preset time node is reached, and locking the database to switch file operation of a pre-written log; After basic snapshot data of the database are created and stored, unlocking the file operation, monitoring a plurality of pre-written logs output by the database after the file operation is recovered, generating incremental log data based on the plurality of pre-written logs, and storing the incremental log data; determining a start file identifier corresponding to the pre-written log with the earliest time in the incremental log data, and marking other pre-written logs in the incremental log data in sequence based on the start file identifier; And creating metadata information corresponding to the basic snapshot data to complete data backup of the database, wherein the metadata information comprises the initial file identification. In a second aspect, an embodiment of the present application further provides a database backup apparatus, including: The initial processing module is configured to trigger the database to refresh the data pages in the shared buffer area to the disk under the condition that the preset time node is reached, and lock the database to switch the file operation of the pre-written log; The data generation module is configured to unlock the file operation after basic snapshot data of the database are created and stored, monitor a plurality of pre-written logs output by the database after the file operation is recovered, generate incremental log data based on the plurality of pre-written logs and store the incremental log data; the data marking module is configured to determine a start file identifier corresponding to the pre-written log with the earliest time in the incremental log data, and mark other pre-written logs in the incremental log data in sequence based on the start file identifier; and the data association module is configured to create metadata information corresponding to the basic snapshot data so as to complete data backup of the database, wherein the metadata information comprises the initial file identification. In a third aspect, an embodiment of the present application further provides an electronic device, including: One or more processors; a storage device configured to store one or more programs, When the one or more programs are executed by the one or