Search

CN-114546726-B - Database backup method and system in log-valued system

CN114546726BCN 114546726 BCN114546726 BCN 114546726BCN-114546726-B

Abstract

A method for backing up database in value logging system includes generating check point, obtaining LSN corresponding to current check point of value logging system, obtaining LSM tree snapshot, collecting each sub tree of LSM index tree, generating linked list of SSTable to be backed up, taking out one SSTable from SStable linked list to be backed up, backing up data of index file corresponding to SSTable, storing it to backup file, taking next SSTable backup by analogy until SSTable to be backed up is empty, obtaining value logging file of value logging system, copying from beginning position to LSN offset corresponding to check point and storing it to backup file. The invention can ensure the integrity of the user data and recover the user data by using the backup.

Inventors

  • WANG XUEHAI
  • FU XIN
  • JIANG JIUWEN
  • Xu Xiongling
  • ZHANG JINGXIU
  • ZHAO YUANFANG
  • SHEN CHEN

Assignees

  • 达梦数据技术(江苏)有限公司

Dates

Publication Date
20260505
Application Date
20220225

Claims (2)

  1. 1. A method for backing up a database in a value log system, comprising the steps of: (1) Generating a check point, and acquiring an LSN corresponding to the current check point of the value log system, wherein the LSN is an incremental log sequence number written into a log file of a database or an offset address at the tail of the value log file in the value log system; (2) Obtaining an LSM tree snapshot, firstly traversing an LSM index tree, collecting each subtree, and then generating a linked list of SSTable to be backed up, wherein each subtree of the LSM index tree comprises index files generated by all read-only SSTable frozen in a memory when a check point is executed and all index files existing in a disk before the check point is generated; (3) In the LSM index tree, one SSTable corresponds to one persistent index file, one SSTable is taken out from SStable linked lists to be backed up, the data of the index file corresponding to the SSTable is read, packed and stored in the backup file, and the next SSTable backup is analogically taken until the SSTable linked list to be backed up is empty; (4) And acquiring a value log file of the value log system, reading the value log file from the beginning position to the LSN offset corresponding to the check point, packaging the value log data, and storing the value log data into a backup file to finish the backup of the value log system.
  2. 2. A system corresponding to a database backup method in a log system according to claim 1 is characterized by comprising a backup device, a check point module, an SSTable subtree collecting module, an LSM subtree backup module and a log backup module, wherein the backup device receives a backup request and informs the check point module to generate check point operation and acquire corresponding LSNs, the backup device calls the SSTable subtree collecting module to generate an LSM tree snapshot, collects SSTable to be backed up and stores the SSTable to a linked list, the LSM subtree backup module takes one SSTable from the SSTable linked list to be backed up, reads data of an index file corresponding to the SSTable, packages and stores the data to a backup file, takes the next SSTable backup from the SSTable linked list to be backed up after the backup is completed until the SSTable linked list is empty, and the log backup module reads the data from a log file 0 offset, packages the backup file until the LSN corresponding offset of the log system is completed.

Description

Database backup method and system in log-valued system Technical Field The invention relates to the technical field of databases, in particular to a method and a system for backing up a database in a value log system. Background Backup of the database ensures that data is not lost or that data is minimally lost. Database backup is largely divided into cold standby and hot standby. Hot standby is the execution of a backup in the running of data without any impact on the running database operations. Cold standby refers to that the backup operation is simplest when the database is stopped, and only the related physical files of the database are copied. Currently, the system 7×24 is required to provide online service, and usually, backups are performed online, that is, most backups are hot backups, and the latter backups are hot backups. The traditional database system stores several types of data, user data and indexes of the user data, the indexes usually adopt storage organization forms such as B trees, skiplist or piles, the user data and the index data are put into data files, REDO logs for recording data changes are mainly used for abnormal recovery, consistency, persistence and the like, and UNDO logs related to transactions are used for rolling back essential data of the transactions, so that the consistency of the database data is ensured. The checkpointing function of the database is directed to a certain point in time of the database (generally corresponding to the log sequence number LSN of the database), and the checkpointing ensures that all data changes preceding the LSN value have been flushed. The traditional data backup comprises the steps of firstly executing a check point operation (flushing the updated data page in the buffer area) to obtain the LSN corresponding to the check point and recording the LSN as a start_LSN, secondly, backing up the user data files (including user data and index data) of the database, secondly, backing up the UNDO log files of the database, after the previous files are all backed up, making a check point again to obtain the LSN corresponding to the check point and recording the LSN as an end_LSN, and finally backing up REDO logs from the begin_LSN to the end_LSN from REDO logs. User data and index data are put together in a traditional database, and REDO logs and UNDO logs are introduced to ensure data consistency. When in backup, the check point needs to brush a large amount of updated data pages to disk, which needs to consume a long time, and can cause the user service to be blocked for a period of time according to different check points. Disclosure of Invention The technical problem to be solved by the invention is to provide a method and a system for backing up a database in a log-in-value system, which can ensure the integrity of user data and recover the user data by using the backup. In order to solve the technical problems, the invention provides a method for backing up a database in a value log system, which comprises the following steps: (1) Generating a check point, and acquiring LSN corresponding to the current check point of the value log system; (2) Acquiring an LSM tree snapshot, traversing an LSM index tree, collecting each subtree, and then generating a linked list of SSTable to be backed up; (3) In the LSM index tree, one SSTable corresponds to one persistent index file, one SSTable is taken out from SStable linked lists to be backed up, the data of the index file corresponding to the SSTable is read, packed and stored in the backup file, and the next SSTable backup is analogically taken until the SSTable linked list to be backed up is empty; (4) And acquiring a value log file of the value log system, reading the value log file from the beginning position to the LSN offset corresponding to the check point, packaging the value log data, and storing the value log data into a backup file to finish the backup of the value log system. Preferably, in step (1), the LSN is the log sequence number of the incremental write log file of the database, or the offset address of the tail of the value log file in the value log system, where the offset address plays the same role as the conventional database LSN. Preferably, in step (2), each subtree of the LSM index tree includes all index files generated by all read-only SSTable (Store String Table) frozen in the memory when the checkpoints are executed, and all index files already existing on the disk before the checkpoints are generated. The system comprises a backup device, a check point module, an SSTable subtree collecting module, an LSM subtree backup module and a value log backup module, wherein the value log system backup device receives a backup request and informs the check point module that the check point module generates check point operation and acquires corresponding LSN, the value log system backup device calls the SSTable subtree collecting module to generate an LSM tree snapshot, collects SS