A disk backup method, device, storage medium and electronic device

Through the virtual disk file and snapshot technology in QCOW2 format, the cumbersome disk backup and recovery process are solved, and efficient management and rapid recovery of full and incremental backups are achieved.

CN119938409BActive Publication Date: 2025-07-08DISJIE (BEIJING) DATA MANAGEMENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510412399.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-03
Publication Date
2025-07-08
Estimated Expiration
2045-04-03

AI Technical Summary

Technical Problem

When performing disk backup, especially for full and incremental backups of block devices, the recovery process is cumbersome, and the different file management of incremental backups is inconvenient, resulting in low recovery efficiency.

Method used

A virtual disk file in QCOW2 format determines the data block by generating snapshots, and creates a full backup data file during full backup, and updates the file during incremental backup, and combines snapshot information and summary file management differences data to realize iterative update of the full backup data file.

Benefits of technology

It realizes efficient management of full disk backup and incremental disk backup, simplifies the data recovery process, especially when restoring the latest version, without the need for different files, and improves recovery efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119938409B_ABST
    Figure CN119938409B_ABST
Patent Text Reader

Abstract

The present invention provides a disk backup method, apparatus, storage medium and electronic device. Among them, the method includes: generating a first snapshot when a full backup of a virtual disk file in QCOW2 format is required; determining full data blocks according to the first snapshot, and writing each data block into a full backup data file; generating a second snapshot when incremental backup is required; determining first data blocks that have changed after the previous backup according to the second snapshot and the previous snapshot generated by the previous backup; writing the backup data blocks corresponding to the positions of the first data blocks in the full backup data file into a differential file corresponding to the current version incremental backup, and then writing the first data blocks into the full backup data file to overwrite the backup data blocks. The backup method of the present invention does not require differential files for incremental backup during subsequent recovery of the latest version of data, the recovery process is fast, and the data recovery efficiency can be guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data backup, and in particular, to a disk backup method, device, storage medium and electronic device. Background Art

[0002] When performing disk backup for a block device, generally, a full - volume backup data file (such as a Dump file) is generated by traversing the entire disk to achieve full - volume disk backup; on this basis, incremental disk backup can be further performed as needed. During incremental backup, the Dump file is not updated, but a corresponding difference file is generated according to the difference in data transformation this time, and the difference file stores the data overwritten by the new incremental data.

[0003] Generally, a full - volume disk backup is performed once initially, and only incremental disk backups are performed regularly subsequently. During data recovery, it is necessary to perform recovery based on the Dump file, difference file, etc., and the recovery process is relatively cumbersome. Summary of the Invention

[0004] To solve the above problems, an object of the embodiments of the present invention is to provide a disk backup method, device, storage medium and electronic device.

[0005] In a first aspect, an embodiment of the present invention provides a disk backup method, including:

[0006] In the case where a full - volume backup of a virtual disk file in QCOW2 format is required, generating a first snapshot of the current virtual disk file;

[0007] Determining full - volume data blocks according to the first snapshot, and writing each data block into a full - volume backup data file;

[0008] After full - volume backup, in the case where an incremental backup of the current version of the virtual disk file is required, generating a second snapshot of the current virtual disk file;

[0009] Determining first data blocks that have changed after the previous backup according to the second snapshot and the previous snapshot generated by the previous backup;

[0010] Writing the backup data block corresponding to the position of the first data block in the full - volume backup data file into the difference file corresponding to the current - version incremental backup, and then writing the first data block into the full - volume backup data file to overwrite the backup data block;

[0011] Writing the block information of the first data block into the incremental summary file of the current - version incremental backup.

[0012] In some alternative embodiments, determining full - volume data blocks according to the first snapshot and writing each data block into a full - volume backup data file includes:

[0013] Read the file header of the virtual disk file, and save the read first file - header data into the full - volume summary file; the first file - header data includes the block size and the first snapshot - table offset;

[0014] Find the snapshot information of the first snapshot according to the first snapshot - table offset, and determine the first secondary table according to the snapshot information of the first snapshot; the snapshot information of the first snapshot includes the offset of the first - level table corresponding to the first snapshot, and the offset of the first - level table corresponding to the first snapshot is used to locate the first secondary table;

[0015] Write the data blocks corresponding to the entries of the first secondary table into the full - volume backup data file; the entry of the first secondary table corresponds to the offset of the corresponding data block.

[0016] In some alternative embodiments, determining the first data blocks that have changed after the previous backup according to the second snapshot and the previous snapshot generated by the previous backup includes:

[0017] Read the file header of the virtual disk file, and save the read second file - header data into the incremental summary file of the current - version incremental backup; the second file - header data includes the block size and the second snapshot - table offset;

[0018] Find the snapshot information of the second snapshot according to the second snapshot - table offset, and determine the second secondary table according to the snapshot information of the second snapshot; the snapshot information of the second snapshot includes the offset of the first - level table corresponding to the second snapshot, and the offset of the first - level table corresponding to the second snapshot is used to locate the second secondary table;

[0019] Compare the second secondary table with the previous secondary table corresponding to the previous snapshot generated by the previous backup item by item to determine the target entries that have changed; the target entries correspond to the offsets of the first data blocks;

[0020] Read the first data block of the block size according to the offset of the first data block corresponding to the target entry.

[0021] In some alternative embodiments, the method further includes:

[0022] After the current - version incremental backup, delete the previous snapshot generated by the previous backup.

[0023] In some alternative embodiments, the method further includes:

[0024] When performing an incremental backup of the current version of the virtual disk file, save the block attributes of each storage block to the bitmap file corresponding to the current version incremental backup.

[0025] In some alternative embodiments, the method further includes:

[0026] When performing data recovery, if the target version incremental backup to be recovered is the latest version incremental backup, determine the block information of the second data block to be recovered according to the incremental digest file of the latest version incremental backup;

[0027] Obtain the second data block from the full backup data file according to the block information of the second data block, and restore the second data block to the corresponding position of the virtual disk file.

[0028] In some alternative embodiments, the method further includes:

[0029] When performing data recovery, if the target version incremental backup to be recovered is not the latest version incremental backup, determine the block information of the third data block to be recovered according to all the incremental digest files between the latest version incremental backup and the target version incremental backup;

[0030] Obtain the third data block from the full backup data file or the differential file of other version incremental backups according to the block information of each third data block, and restore the third data block to the corresponding position of the virtual disk file.

[0031] In a second aspect, an embodiment of the present invention further provides a disk backup device, including:

[0032] A first snapshot module, configured to generate a first snapshot of the current virtual disk file when a full backup of the virtual disk file in QCOW2 format is required;

[0033] A full backup module, configured to determine full data blocks according to the first snapshot, and write each data block to a full backup data file;

[0034] A second snapshot module, configured to generate a second snapshot of the current virtual disk file when an incremental backup of the current version of the virtual disk file is required after the full backup;

[0035] A comparison module, configured to determine the first data blocks that have changed after the previous backup according to the second snapshot and the previous snapshot generated by the previous backup;

[0036] An incremental backup module, configured to write the backup data block corresponding to the position of the first data block in the full backup data file into a differential file corresponding to the current version of incremental backup, then write the first data block into the full backup data file and overwrite the backup data block; and write the block information of the first data block into an incremental summary file of the current version of incremental backup.

[0037] In a third aspect, an embodiment of the present invention further provides a computer storage medium storing computer-executable instructions for the disk backup method described in any one of the above.

[0038] In a fourth aspect, an embodiment of the present invention further provides an electronic device, including:

[0039] At least one processor; and,

[0040] A memory communicatively connected to the at least one processor; wherein,

[0041] The memory stores instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is enabled to execute the disk backup method described in any one of the above.

[0042] In the solution provided in the first aspect of the above embodiments of the present invention, based on the characteristics of the QCOW2 format file, full disk backup and incremental disk backup can be realized; a full backup data file is generated during full backup, and the full backup data file is iteratively updated during each incremental backup, so that the full backup data file can store all the data of the last backup. Subsequently, when performing data recovery, it is mainly based on the full backup data file for recovery. Especially when recovering the latest version of data, the differential file of incremental backup is not required, and the recovery process is fast, which can ensure the data recovery efficiency.

[0043] To make the above objects, features, and advantages of the present invention more obvious and understandable, the following specifically gives preferred embodiments and, in conjunction with the accompanying drawings, the detailed description is as follows. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for description in the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0045] Figure 1 Shows a flowchart of a disk backup method provided by an embodiment of the present invention;

[0046] Figure 2 shows a flowchart of another disk backup method provided by an embodiment of the present invention;

[0047] Figure 3 shows a schematic structural diagram of a disk backup device provided by an embodiment of the present invention;

[0048] Figure 4 shows a schematic structural diagram of an electronic device for executing the disk backup method provided by an embodiment of the present invention. Detailed implementation manners

[0049] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", "clockwise", "counterclockwise", etc. indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings. It is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and thus should not be construed as a limitation of the present invention.

[0050] In addition, the terms "first" and "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features. In the description of the present invention, "a plurality" means two or more unless otherwise specifically defined.

[0051] In the present invention, unless otherwise clearly defined and limited, the terms "install", "connect", "connection", "fix" and other terms should be understood in a broad sense. For example, it may be a fixed connection, a detachable connection, or an integral connection; it may be a mechanical connection or an electrical connection; it may be directly connected or indirectly connected through an intermediate medium, and it may be the communication inside two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific situations.

[0052] The QCOW2 (QEMU Copy-On-Write 2, the second-generation QEMU copy-on-write) format is a disk image file format supported by QEMU (Quick Emulator), and it supports features such as snapshots, compression, and encryption. Among them, the QCOW2 format file adopts the copy-on-write mechanism, that is, the modification of the file will not directly overwrite the original data, but write to a new location, and the original data is retained for subsequent recovery.

[0053] A disk backup method provided by an embodiment of the present invention is as follows. Refer to Figure 1 As shown, the method includes:

[0054] Step 101: When a full backup of the virtual disk file in QCOW2 format is required, generate the first snapshot of the current virtual disk file.

[0055] In this embodiment, when backing up the data of the virtual disk file in QCOW2 format, a full backup is first performed, and when subsequent data backup is required, one or more incremental backups are used. Among them, in each data backup (including full backup and incremental backup), a snapshot command needs to be executed on the virtual disk file to obtain the corresponding snapshot.

[0056] Specifically, when performing a full backup of the virtual disk file, the snapshot generated at this time is called the first snapshot. Subsequently, this first snapshot is represented by snapshot_1.

[0057] It should be noted that the first snapshot snapshot_1 is the snapshot generated during the current full backup. For the convenience of distinction, the moment at this time is called the t0 moment.

[0058] Step 102: Determine the full data blocks according to the first snapshot, and write each data block to the full backup data file.

[0059] In this embodiment, the first snapshot snapshot_1 contains information related to the data blocks in the virtual disk file. Based on this information, the full data blocks can be located, and then these data blocks are all backed up and written to the corresponding file, that is, the full backup data file.

[0060] Among them, the full backup data file is a Dump file, which is a file composed of data blocks and hole blocks and is used to save the full disk data. During the traditional full backup process, a full Dump file is generally also generated, but this Dump file is fixed and will not be updated during subsequent incremental updates; while in this embodiment, during each incremental update, the Dump file will also be synchronously updated, that is, the full backup data file will be synchronously updated, which will be described later.

[0061] Among them, the format of the full backup data file can be: disk id.dump; for example, the full backup data file corresponding to disk 0 is, for example, 0.dump. In this embodiment, a Dump file is generated during full backup, and there is no separate corresponding Dump file during each incremental backup.

[0062] Optionally, the QCOW2 file uses a two-level table structure to manage data blocks: The first-level table (L1 Table, i.e., L1 table): Each table entry points to a second-level table (L2 Table); The second-level table (L2 Table, i.e., L2 table): Each table entry points to the offset of a data block (cluster). Based on the above characteristics of the QCOW2 file, it is convenient to determine each data block of the virtual disk file.

[0063] Specifically, the above step 102 "determine the full data blocks according to the first snapshot and write each data block into the full backup data file" includes steps A1 to A3.

[0064] Step A1: Read the file header of the virtual disk file and save the read first file header data to the full summary file; the first file header data includes the block size and the first snapshot table offset.

[0065] Step A2: Search for the snapshot information of the first snapshot according to the first snapshot table offset, and determine the first second-level table according to the snapshot information of the first snapshot; the snapshot information of the first snapshot includes the first-level table offset corresponding to the first snapshot, and the first-level table offset corresponding to the first snapshot is used to locate the first second-level table.

[0066] Step A3: Write the data blocks corresponding to each table entry of the first second-level table into the full backup data file; the table entry of the first second-level table corresponds to the offset of the corresponding data block.

[0067] In this embodiment, when performing a full backup on a virtual disk file in QCOW2 format, by reading the file header part of the virtual disk file, the file header data at this time, that is, the first file header data, can be obtained. Among them, the first file header data includes the block size blockSize of the virtual disk file and the current snapshot table offset, that is, the first snapshot table offset. And, the read first file header data is backed up and saved to the summary file of the full backup, that is, during full backup, in addition to generating the full backup data file, a full summary file will also be generated.

[0068] For example, each backup corresponds to a folder. During a full backup, there is a "file1.digest" summary file in the "Full Backup" folder, which is the full backup summary file. After reading the first file header data of the virtual disk file, it is saved to the "file1.digest" summary file.

[0069] The first snapshot table offset is the address offset of the current snapshot table. Based on this first snapshot table offset, the current snapshot information table can be located. Among them, the snapshot information table is a structure in the QCOW2 file used to store all snapshot metadata. Each snapshot occupies one item in the snapshot information table, that is, the first snapshot is a snapshot in the snapshot information table.

[0070] Specifically, the snapshot information table records the snapshot information of each snapshot. This snapshot information includes the snapshot ID and the L1 table offset (i.e., the first-level table offset). Based on the snapshot ID, the snapshot information belonging to the first snapshot snapshot_1 can be determined, and the first-level table offset of the first snapshot snapshot_1 can be determined. This first-level table offset points to the position of the first-level table (L1 Table) corresponding to the first snapshot snapshot_1, so that the first-level table corresponding to the first snapshot snapshot_1 can be determined.

[0071] After determining the first-level table corresponding to the first snapshot snapshot_1, traverse this first-level table to find the second-level table (L2 Table) corresponding to the first snapshot snapshot_1, that is, the first second-level table. It can be understood that the first second-level table contains multiple table entries, and each table entry points to the offset of a data block.

[0072] For ease of description, use L2Table_1 to represent this first second-level table. It can be understood that each table entry in the first second-level table L2Table_1 records the offset of the data block in the QCOW2 file, and the data block pointed to by this offset is the actual data corresponding to the first snapshot snapshot_1.

[0073] In this embodiment, after determining the first second-level table L2Table_1, the data blocks corresponding to the respective table entries of the first second-level table L2Table_1 can be written into the full backup data file (Dump file).

[0074] Specifically, according to the offsets of the respective table entries in the first second-level table L2Table_1, read item by item according to the block size blockSize. The data read is the corresponding data block, and these data blocks are written in sequence to the corresponding positions in the full backup data file (Dump file).

[0075] For example, each data block corresponds to the subscript of the corresponding entry in the first and second - level table L2Table_1. The data block found from the offset corresponding to the first entry of the first and second - level table L2Table_1 should be written into the interval with a length of blockSize starting from the beginning of the full - volume backup data file (Dump file). The same applies to the remaining data blocks.

[0076] Moreover, for the data blocks read based on the first and second - level table L2Table_1, they can also be compressed according to requirements to achieve the effect of saving backup storage space. The saved full - volume backup data file (Dump file, whose name can be file1.dump for example) is a sparse file, and the disk space it occupies is only the sum of the sizes of all the written data blocks.

[0077] In addition, in the "file1.digest" summary file (i.e., the full - volume summary file) in the "full - volume backup" folder, append the block information of each data block and hole block, that is, write the block information of each data block and hole block in the full - volume backup data file to the full - volume summary file; this block information can include, for example, the size, position, etc. of the data block and hole block.

[0078] The above steps are a complete full - volume backup. At this time, the full - volume backup data file (such as file1.dump) stores all the data blocks of the virtual disk file at time t0, and it is the full - volume Dump file at time t0. The full - volume summary file (such as file1.digest) stores the file - header data of the virtual disk file at time t0, the block information of each block, etc.

[0079] Step 103: After the full - volume backup, in the case where an incremental backup of the current version of the virtual disk file is required, generate the second snapshot of the current virtual disk file.

[0080] In this embodiment, after the above - mentioned full - volume backup, if it is necessary to back up the virtual disk file again, an incremental backup can be performed. Specifically, at time t1 after time t0, if it is necessary to back up the virtual disk file, an incremental backup can be performed. Among them, this embodiment allows multiple incremental backups, and each corresponds to a unique version. For the convenience of description, the incremental backup at time t1 is called the current - version incremental backup.

[0081] Specifically, after a period of time, the time goes from time t0 to time t1. At this time, data backup is required. Then, similar to step 101 above, a snapshot command is executed on the virtual disk file in QCOW2 format that needs to be backed up to generate the second snapshot snapshot_2. It can be understood that since there is generally data update from the last backup (e.g., time t0) to time t1, the virtual disk files at this time and at time t0 may have different partial data.

[0082] Step 104: Determine the first data block that has changed after the previous backup according to the second snapshot and the previous snapshot generated by the previous backup.

[0083] Specifically, before the current version incremental backup this time, there was also a previous backup, which is the last data backup before the current version incremental backup (i.e., before time t1). For example, if after a full backup, the first incremental backup is performed, then the previous backup of this current version incremental backup is the full backup at time t0; if one or more incremental backups have been performed, then the previous backup of this current version incremental backup is the incremental backup of the previous version.

[0084] Moreover, in this embodiment, a corresponding snapshot needs to be generated for each backup. Therefore, a snapshot will also be generated during the previous backup, that is, the previous snapshot. For example, the previous snapshot is the first snapshot snapshot_1.

[0085] This incremental backup only needs to focus on the changed data. As shown in step 102 above, the corresponding data blocks can be determined based on the snapshot. Therefore, based on the second snapshot, the respective data blocks at time t1 can be determined, and based on the previous snapshot, the corresponding data blocks at the corresponding time can also be determined.

[0086] Therefore, by comparing the relevant information of the second snapshot and the previous snapshot, it can be determined which data blocks have changed from the previous backup to the current time t1. These changed data blocks are called the first data blocks.

[0087] Optionally, step 104 above, "Determine the first data block that has changed after the previous backup according to the second snapshot and the previous snapshot generated by the previous backup" includes steps B1 to B4.

[0088] Step B1, read the file header of the virtual disk file, and save the read second file header data to the incremental summary file of the current version incremental backup; the second file header data includes the block size and the second snapshot table offset.

[0089] Step B2: Search for the snapshot information of the second snapshot based on the second snapshot table offset, and determine the second secondary table according to the snapshot information of the second snapshot. The snapshot information of the second snapshot includes the offset of the first-level table corresponding to the second snapshot, and the offset of the first-level table corresponding to the second snapshot is used to locate the second secondary table.

[0090] Similar to the above Steps A1 to A2, based on the file header of the virtual disk file at the current moment, the second snapshot table offset can also be determined, and then the corresponding secondary table, that is, the second secondary table L2Table_2, can be determined. Similarly, based on the previous snapshot generated by the previous backup, the corresponding secondary table, that is, the previous secondary table, can also be determined. For example, if the previous backup is a full backup, then the previous secondary table is the first secondary table L2Table_1.

[0091] As described above, a corresponding digest file is generated for each data backup. When performing an incremental backup of the current version, the generated digest file is an incremental digest file, and the second file header data read from the file header is saved to the incremental digest file of the current version incremental backup. Therefore, when performing subsequent backups, the previous secondary table can be determined based on the digest file of the previous backup.

[0092] Step B3: Compare the second secondary table item by item with the previous secondary table corresponding to the previous snapshot generated by the previous backup to determine the target table item that has changed. The target table item corresponds to the offset of the first data block.

[0093] Step B4: Read the first data block of the block size according to the offset of the first data block corresponding to the target table item.

[0094] In this embodiment, each item of the second secondary table and the previous secondary table represents the offset of the corresponding data block. Since the QCOW2 format file adopts the copy-on-write method, if a certain table item has changed, it can be determined that the corresponding data block has changed. Therefore, by determining the target table item that has changed, the changed data block, that is, the first data block, can be located.

[0095] Step 105: Write the backup data block corresponding to the position of the first data block in the full backup data file to the differential file corresponding to the current version incremental backup, and then write the first data block to the full backup data file to overwrite the backup data block.

[0096] In this embodiment, after determining the first data block, the data block corresponding to the position of the first data block in the full backup data file (Dump file), that is, the backup data block, can be determined, and the backup data block is written to the differential file corresponding to the current version incremental backup. Then, the first data block is written to the full backup data file to overwrite the original backup data block, realizing the update of the full backup data file.

[0097] Among them, the above-mentioned step 105, "writing the backup data block corresponding to the position of the first data block in the full backup data file into the differential file corresponding to the current version incremental backup", may specifically include: locating the backup data block at the corresponding position in the full backup data file according to the position of the target entry in the second secondary table; writing the backup data block into the differential file corresponding to the current version incremental backup.

[0098] Step 106: Write the block information of the first data block into the incremental summary file of the current version incremental backup.

[0099] In this embodiment, the block information of the first data block is also determined. The block information may represent the position, size, etc. of the first data block. Writing the block information of the first data block into the incremental summary file of the current version incremental backup is convenient for subsequent data recovery.

[0100] Optionally, the method further includes: when performing an incremental backup of the virtual disk file for the current version, saving the block attributes of each storage block to the bitmap file corresponding to the current version incremental backup.

[0101] In this embodiment, the summary file is used to save information such as the file header of the QCOW2 file, and its format may be: disk id.digest, for example: 0.digest; a corresponding summary file can be generated for each backup, and one incremental backup corresponds to one version of the incremental summary file. The differential file is used to save the data overwritten by the new incremental data, and the format may be, for example: disk id.diff.backward, such as 0.diff.backward. One incremental backup corresponds to one version of the differential file.

[0102] In addition, when performing an incremental backup, a corresponding bitmap file is also generated, which is used to calculate the position of the data blocks in the Dump file, and the format may be: disk id.bmp, for example 0.bmp. One incremental backup corresponds to one version of the bitmap file, which contains the data block information of the entire disk.

[0103] Specifically, during incremental backup, the block attributes of each storage block (including data blocks and hole blocks) are saved to the bitmap file corresponding to the current version incremental backup. Among them, the block attribute may specifically indicate whether the storage block is a data block or a hole block, and may also indicate the compression information of the data block, etc.

[0104] Moreover, in the bitmap file (such as file1.bmp) of the current version incremental backup, the attributes of the blocks (whether the blocks are data blocks or hole blocks) are marked, and other information can also be saved.

[0105] Taking the previous backup as a full backup as an example, that is, the upper first and second-level tables are the first and second-level tables L2Table_1 of the full backup. Compare the first and second-level table L2Table_1 with the second and second-level table L2Table_2 item by item according to the corresponding table items. If the value of a certain table item in the second and second-level table L2Table_2 changes, then this table item is the target table item.

[0106] Based on the target table item in the second and second-level table L2Table_2, find the corresponding offset position and read the data of the block size blockSize. The read data is the first data block. Write the data to the corresponding position in the full backup data file (such as file1.dump) for overwriting according to the offset table item subscript corresponding to the first data block in the second and second-level table L2Table_2; among them, before overwriting, read the backup data block at the overwriting position and write it to the differential file (such as file1.diff.backward) in the current incremental version folder, and append the information that this data block has changed to the incremental summary file of the current version incremental backup to ensure that the backup data at all backup time points can be restored.

[0107] For example, compare the first and second-level table L2Table_1 with the second and second-level table L2Table_2 item by item according to the corresponding table items. If the Kth difference appears in the Nth item of the second and second-level table L2Table_2, then the Nth item of the second and second-level table L2Table_2 is a target table item. According to the offset corresponding to the Nth item of the second and second-level table L2Table_2, the data block can be found and read, denoted as incBlockK, which is a first data block. And, read the data in the Nth data block (i.e., the backup data block) of the full backup data file (such as file1.dump) in advance and write it to the Kth block of the differential file (such as file1.diff.backward) in the folder of the current version incremental backup. And, overwrite the data in the first data block incBlockK to the Nth data block of the full backup data file (such as file1.dump), and mark the Nth block in the full backup data file as a data block in the bitmap file (such as file1.bmp) in the folder of the current version incremental backup.

[0108] Optionally, the method further includes: after the current version incremental backup, delete the previous snapshot generated by the previous backup. By deleting the useless snapshots, the storage space of the host where the virtual machine is located can be saved.

[0109] It can be understood that the above steps 103 to 106 are the process of an incremental backup. If an incremental backup needs to be performed again, just repeat steps 103 to 106.

[0110] A disk backup method provided by an embodiment of the present invention can achieve full - volume disk backup and incremental disk backup based on the characteristics of QCOW2 - format files. During full - volume backup, a full - volume backup data file is generated, and the full - volume backup data file is iteratively updated during each incremental backup, so that the full - volume backup data file can store all the data of the last backup. Subsequently, when performing data recovery, it is mainly based on the full - volume backup data file for recovery. Especially when recovering the latest version of data, the differential files of incremental backup are not required, and the recovery process is fast, which can ensure the data recovery efficiency.

[0111] Another disk backup method provided by an embodiment of the present invention is as follows. Refer to Figure 2 As shown, this method includes:

[0112] Step 201: When a full - volume backup of the QCOW2 - format virtual disk file is required, generate the current first snapshot of the virtual disk file.

[0113] Step 202: Determine the full - volume data blocks according to the first snapshot, and write each data block into the full - volume backup data file.

[0114] Step 203: After the full - volume backup, when an incremental backup of the current version of the virtual disk file is required, generate the current second snapshot of the virtual disk file.

[0115] Step 204: Determine the first data blocks that have changed after the previous backup according to the second snapshot and the previous snapshot generated by the previous backup.

[0116] Step 205: Write the backup data blocks corresponding to the positions of the first data blocks in the full - volume backup data file into the differential file corresponding to the current - version incremental backup, then write the first data blocks into the full - volume backup data file and overwrite the backup data blocks.

[0117] Step 206: Write the block information of the first data blocks into the incremental summary file of the current - version incremental backup.

[0118] Among them, the above steps 201 to 206 illustrate the processes of full - volume backup and incremental backup. For specific details, refer to the relevant descriptions of the embodiments shown in Figure 1 which will not be elaborated here.

[0119] Step 207: When performing data recovery, if the target - version incremental backup to be recovered is the latest - version incremental backup, determine the block information of the second data blocks to be recovered according to the incremental summary file of the latest - version incremental backup.

[0120] Step 208: Obtain the second data blocks from the full - volume backup data file according to the block information of the second data blocks, and restore the second data blocks to the corresponding positions in the virtual disk file.

[0121] In this embodiment, when performing data recovery, it is necessary to determine the backup corresponding to which version to be restored, that is, it is necessary to determine the target version incremental backup. If the target version incremental backup is the latest version incremental backup, since the full backup data file stores all the data of the last backup (i.e., the latest version incremental backup), the block information of the corresponding data blocks is extracted from the incremental digest file of the latest version incremental backup. For ease of description, this data block is referred to as the second data block. Based on the block information of these second data blocks, the data corresponding to the second data blocks can be read from the full backup data file, and then these second data blocks can be restored to the corresponding positions in the virtual disk file, thus completing the data recovery of the latest version.

[0122] For example, if the folder of the current latest version incremental file is "Incremental Version X", then the incremental digest file in "Incremental Version X" can be used to read the corresponding file header information and write the file header information into the file header of the virtual disk file to be restored; then, according to the incremental digest file and bitmap file in "Incremental Version X", determine the positions in the full backup data file (such as file1.dump) where the third data blocks need to be written to the virtual disk file, whether decompression is required, etc. Completing the supplementary head information also depends on the above-mentioned incremental digest file and bitmap file.

[0123] Optionally, after the above step 206, the method may further include step C1 to step C2.

[0124] Step C1: When performing data recovery, if the target version incremental backup to be restored is not the latest version incremental backup, determine the block information of the third data blocks to be restored according to all the incremental digest files between the latest version incremental backup and the target version incremental backup.

[0125] Step C2: Obtain the third data blocks from the full backup data file or the differential files of other version incremental backups according to the block information of each third data block, and restore the third data blocks to the corresponding positions in the virtual disk file.

[0126] In this embodiment, if the target version incremental backup to be restored is not the latest version incremental backup, that is, an older version needs to be restored. For example, currently there are "Full Version", "Incremental Version 1", and "Incremental Version 2", and "Incremental Version 2" is the latest version; if you want to restore the disk corresponding to "Incremental Version 1", you need to use the relevant information of all versions between the latest version incremental backup and the target version incremental backup.

[0127] Specifically, if it is necessary to restore the disk corresponding to the "incremental version 1" moment, the four files including the incremental digest file and the bitmap file in the "incremental version 1" and the "incremental version 2" are required to determine whether the data required at the "incremental version 1" moment is stored in the full backup data file or in the differential file under the "incremental version 2" folder, and to determine the position where the data block should be written to the disk file to be restored and whether decompression is required. Moreover, supplementing the header information also depends on all the above-mentioned incremental digest files and bitmap files.

[0128] A disk backup method provided by an embodiment of the present invention updates the Dump file corresponding to the full backup during each incremental backup. When restoring the latest version, no differential file is required, there is no excessive calculation, and the restoration process is relatively fast. When restoring an older version, all the incremental digest files and bitmap files in all versions from the latest version to the target version are used for calculation to determine whether the required data block is in the full backup data file or in the differential file of a certain version, so as to realize the restoration of the data of the older version.

[0129] The above has introduced the disk backup method process in detail. This method can also be implemented by a corresponding device. The following details the structure and functions of the device.

[0130] Based on the same inventive concept, an embodiment of the present invention also provides a disk backup device. As shown in Figure 3 the device includes:

[0131] A first snapshot module 301, configured to generate a first snapshot of the current virtual disk file in the case of a full backup of the virtual disk file in QCOW2 format;

[0132] A full backup module 302, configured to determine full data blocks according to the first snapshot and write each data block into a full backup data file;

[0133] A second snapshot module 303, configured to generate a second snapshot of the current virtual disk file in the case of an incremental backup of the current version of the virtual disk file after the full backup;

[0134] A comparison module 304, configured to determine first data blocks that have changed after the previous backup according to the second snapshot and the previous snapshot generated by the previous backup;

[0135] The incremental backup module 305 is used to write the backup data block corresponding to the first data block position in the full backup data file to the differential file corresponding to the current version incremental backup, and then write the first data block to the full backup data file to overwrite the backup data block; and write the block information of the first data block to the incremental summary file of the current version incremental backup.

[0136] In some alternative embodiments, the full backup module 302 determines the full data blocks according to the first snapshot and writes each data block to the full backup data file, including:

[0137] Read the file header of the virtual disk file and save the read first file header data to the full summary file; the first file header data includes the block size and the first snapshot table offset;

[0138] Find the snapshot information of the first snapshot according to the first snapshot table offset, and determine the first secondary table according to the snapshot information of the first snapshot; the snapshot information of the first snapshot includes the offset of the first-level table corresponding to the first snapshot, and the offset of the first-level table corresponding to the first snapshot is used to locate the first secondary table;

[0139] Write the data blocks corresponding to the entries of the first secondary table to the full backup data file; the entries of the first secondary table correspond to the offsets of the corresponding data blocks.

[0140] In some alternative embodiments, the comparison module 304 determines the first data blocks that have changed after the previous backup according to the second snapshot and the previous snapshot generated by the previous backup, including:

[0141] Read the file header of the virtual disk file and save the read second file header data to the incremental summary file of the current version incremental backup; the second file header data includes the block size and the second snapshot table offset;

[0142] Find the snapshot information of the second snapshot according to the second snapshot table offset, and determine the second secondary table according to the snapshot information of the second snapshot; the snapshot information of the second snapshot includes the offset of the first-level table corresponding to the second snapshot, and the offset of the first-level table corresponding to the second snapshot is used to locate the second secondary table;

[0143] Compare each entry of the second secondary table with the previous secondary table corresponding to the previous snapshot generated by the previous backup to determine the target entry that has changed; the target entry corresponds to the offset of the first data block;

[0144] Read the first data block of the block size according to the offset of the first data block corresponding to the target entry.

[0145] In some alternative embodiments, the incremental backup module 305 is further configured to: after the current version incremental backup, delete the previous snapshot generated by the previous backup.

[0146] In some alternative embodiments, the incremental backup module 305 is further configured to: when performing an incremental backup of the current version of the virtual disk file, save the block attributes of each storage block to the bitmap file corresponding to the current version incremental backup.

[0147] In some alternative embodiments, the apparatus further includes a data recovery module, configured to:

[0148] When performing data recovery, if the target version incremental backup to be recovered is the latest version incremental backup, determine the block information of the second data block to be recovered according to the incremental summary file of the latest version incremental backup;

[0149] Obtain the second data block from the full backup data file according to the block information of the second data block, and restore the second data block to the corresponding position of the virtual disk file.

[0150] In some alternative embodiments, the apparatus further includes a data recovery module, configured to:

[0151] When performing data recovery, if the target version incremental backup to be recovered is not the latest version incremental backup, determine the block information of the third data block to be recovered according to all the incremental summary files between the latest version incremental backup and the target version incremental backup;

[0152] Obtain the third data block from the full backup data file or the differential file of other version incremental backups according to the block information of each third data block, and restore the third data block to the corresponding position of the virtual disk file.

[0153] An embodiment of the present invention further provides a computer storage medium, which stores computer-executable instructions including a program for executing the above disk backup method, and the computer-executable instructions can execute the method in any of the above method embodiments.

[0154] Wherein, the computer storage medium can be any available medium or data storage device accessible by a computer, including but not limited to magnetic memories (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical memories (such as CDs, DVDs, BDs, HVDs, etc.), and semiconductor memories (such as ROM, EPROM, EEPROM, non-volatile memories (NANDFLASH), solid state drives (SSD)), etc.

[0155] Figure 4A structural block diagram of an electronic device showing another embodiment of the present invention is presented. The electronic device 1100 can be a host server with computing capabilities, a personal computer PC, or a portable computer or terminal, etc. The specific embodiments of the present invention do not limit the specific implementation of the electronic device.

[0156] The electronic device 1100 includes at least one processor 1110, a communications interface 1120, a memory array 1130, and a bus 1140. Among them, the processor 1110, the communications interface 1120, and the memory 1130 communicate with each other through the bus 1140.

[0157] The communications interface 1120 is used to communicate with network elements, where the network elements include, for example, a virtual machine management center, shared storage, etc.

[0158] The processor 1110 is used to execute programs. The processor 1110 may be a central processing unit CPU, or an application specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention.

[0159] The memory 1130 is used for executable instructions. The memory 1130 may include high-speed RAM memory and may also include non-volatile memory, such as at least one disk memory. The memory 1130 can also be a memory array. The memory 1130 may also be partitioned, and the blocks can be combined into virtual volumes according to certain rules. The instructions stored in the memory 1130 can be executed by the processor 1110, enabling the processor 1110 to execute the disk backup method in any of the above method embodiments.

[0160] As described above, the above are only the specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of changes or substitutions, which should all be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.

Claims

1. A disk backup method, characterized in that, including: When a full backup of a virtual disk file in QCOW2 format is required, generating a first snapshot of the current virtual disk file; Determining full data blocks according to the first snapshot, and writing each data block to a full backup data file; After the full backup, when an incremental backup of the current version of the virtual disk file is required, generating a second snapshot of the current virtual disk file; According to the second snapshot and the previous snapshot generated by the previous backup, by comparing the relevant information for locating data blocks in the second snapshot and the previous snapshot, determining first data blocks that have changed after the previous backup; Writing the backup data blocks corresponding to the positions of the first data blocks in the full backup data file to a differential file corresponding to the current version incremental backup, then writing the first data blocks to the full backup data file and overwriting the backup data blocks; Writing the block information of the first data blocks to an incremental summary file of the current version incremental backup.

2. The method according to claim 1, wherein The determining full data blocks according to the first snapshot and writing each data block to a full backup data file includes: Reading the file header of the virtual disk file, and saving the read first file header data to a full summary file; the first file header data includes a block size and a first snapshot table offset; Searching for snapshot information of the first snapshot according to the first snapshot table offset, and determining a first secondary table according to the snapshot information of the first snapshot; the snapshot information of the first snapshot includes a first-level table offset corresponding to the first snapshot, and the first-level table offset corresponding to the first snapshot is used to locate the first secondary table; Writing the data blocks corresponding to each entry of the first secondary table to a full backup data file; the entry of the first secondary table corresponds to the offset of the corresponding data block.

3. The method according to claim 1 or 2, characterized in that, The determining first data blocks that have changed after the previous backup according to the second snapshot and the previous snapshot generated by the previous backup includes: Reading the file header of the virtual disk file, and saving the read second file header data to an incremental summary file of the current version incremental backup; the second file header data includes a block size and a second snapshot table offset; Searching for snapshot information of the second snapshot according to the second snapshot table offset, and determining a second secondary table according to the snapshot information of the second snapshot; the snapshot information of the second snapshot includes a first-level table offset corresponding to the second snapshot, and the first-level table offset corresponding to the second snapshot is used to locate the second secondary table; Comparing each entry of the second secondary table with the previous secondary table corresponding to the previous snapshot generated by the previous backup to determine a target entry; the target entry corresponds to the offset of the first data block; Reading the first data block of the block size according to the offset of the first data block corresponding to the target entry.

4. The method according to claim 1, wherein It also includes: After the current version incremental backup, deleting the previous snapshot generated by the previous backup.

5. The method according to claim 1, wherein It also includes: In the case of performing an incremental backup of the current version of the virtual disk file, save the block attributes of each storage block to the bitmap file corresponding to the current version incremental backup.

6. The method according to claim 1, characterized in that It further includes: When performing data recovery, if the target version incremental backup to be recovered is the latest version incremental backup, determine the block information of the second data block to be recovered according to the incremental digest file of the latest version incremental backup; Obtain the second data block from the full backup data file according to the block information of the second data block, and restore the second data block to the corresponding position of the virtual disk file.

7. The method according to claim 1, wherein It further includes: When performing data recovery, if the target version incremental backup to be recovered is not the latest version incremental backup, determine the block information of the third data block to be recovered according to all the incremental digest files between the latest version incremental backup and the target version incremental backup; Obtain the third data block from the full backup data file or the differential file of other version incremental backups according to the block information of each third data block, and restore the third data block to the corresponding position of the virtual disk file.

8. A disk backup device, characterized in that, It includes: A first snapshot module, configured to generate a first snapshot of the current virtual disk file when a full backup of the virtual disk file in QCOW2 format is required; A full backup module, configured to determine full data blocks according to the first snapshot, and write each data block to a full backup data file; A second snapshot module, configured to generate a second snapshot of the current virtual disk file when an incremental backup of the current version of the virtual disk file is required after the full backup; A comparison module, configured to determine the first data blocks that have changed after the previous backup by comparing the relevant information for locating data blocks in the second snapshot and the previous snapshot generated by the previous backup; An incremental backup module, configured to write the backup data block corresponding to the position of the first data block in the full backup data file to the differential file corresponding to the current version incremental backup, and then write the first data block to the full backup data file to overwrite the backup data block; Write the block information of the first data block to the incremental digest file of the current version incremental backup.

9. A computer storage medium, characterized in that, The computer storage medium stores computer-executable instructions for executing the disk backup method according to any one of claims 1 to 7.

10. An electronic device, characterized in that, It includes: At least one processor; And, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the disk backup method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Virtual machine disk backup method and apparatus

    CN107544871A

  • Data backup recovery method and device based on data merging

    CN119292828A