Virtual machine backup method and device, computer equipment and storage medium

After performing full backup in the virtual machine, the redirect function is used to write incremental data to the virtual machine disk and backup disk at the same time, solving the problem of timely and affecting IO performance in the existing technology, real-time backup and efficient data security are achieved.

CN119806750APending Publication Date: 2025-04-11INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202412000348.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

There are two major problems in the backup of virtual machine data in the existing technology: one is that it is difficult to backup virtual machine data in a timely manner, resulting in the possibility of data loss when a failure occurs; the other is that the backup process requires frequent snapshots of the virtual machine, which affects the IO performance of the virtual machine.

Method used

A virtual machine backup method is adopted, which first performs full backup, and then uses the redirect function to write incremental data to the virtual machine disk and backup disk at the same time when the virtual machine receives data modification instructions to achieve real-time backup. This method avoids frequent snapshot operations and reduces the impact on virtual machine IO performance.

Benefits of technology

Real-time backup of virtual machine data is realized, data security is improved, and the impact on virtual machine IO performance during the backup process is avoided.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119806750A_ABST
    Figure CN119806750A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and discloses a virtual machine backup method and device, computer equipment and a storage medium, and the method comprises the following steps: obtaining total data of a virtual machine disk in a virtual machine to be backed up, and storing the total data to a backup disk; and starting a redirection function in the to-be-backed-up virtual machine, and writing incremental data corresponding to a data modification instruction into a virtual machine disk and a backup disk by utilizing the redirection function under the condition that the to-be-backed-up virtual machine receives the data modification instruction. The problems that data of the virtual machine is difficult to backup in time and the IO performance of the virtual machine is affected by backup when the virtual machine is backed up once at intervals are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a virtual machine backup method, device, computer equipment and storage medium. Background Art

[0002] Currently, in order to protect the data of the virtual machine, a backup of the virtual machine data is created, and the backup data is used to ensure the data security of the virtual machine. At present, there are two ways to back up the data of the virtual machine, namely: bitmap backup method and differential data backup method. The bitmap backup method is to back up the data by recording the range of data changes through a bitmap, and the bitmap will be initialized each time the backup is performed. When there is a data change, the bitmap will record the offset and length of the data change. When backing up, it is necessary to read the data from the snapshot of the virtual machine disk according to the offset and length and then back it up to the backup disk. The differential data backup method needs to retain the snapshot of the virtual machine at the time of the last backup. When backing up again, the snapshot of the virtual machine is recreated, and the data is backed up by determining the difference data between the two snapshots.

[0003] However, in the above two backup methods, the virtual machine is backed up once every certain period of time, which makes it difficult to back up the data of the virtual machine in time. If the virtual machine fails between two intervals, the data between the time of the failure and the time of the previous backup may be lost. In addition, the above two backup methods need to suspend the business of the virtual machine and perform snapshot operations on the virtual machine each time a backup is performed, which will affect the IO (Input / Output) performance of the virtual machine.

[0004] Therefore, the related art has the problem that the virtual machine is backed up once at a certain interval, it is difficult to back up the data of the virtual machine in time, and the backup will affect the IO performance of the virtual machine. Summary of the invention

[0005] In view of this, the present invention provides a virtual machine backup method, apparatus, computer equipment and storage medium to solve the problem that the virtual machine is backed up once at a certain interval, the data of the virtual machine is difficult to back up in time, and the backup will affect the IO performance of the virtual machine.

[0006] In a first aspect, the present invention provides a virtual machine backup method, the method comprising:

[0007] Obtain the full amount of data of the virtual machine disk in the virtual machine to be backed up, and store the full amount of data in the backup disk;

[0008] The redirection function is started in the virtual machine to be backed up. When the virtual machine to be backed up receives a data modification instruction, the redirection function is used to write the incremental data corresponding to the data modification instruction into the virtual machine disk and the backup disk.

[0009] The virtual machine backup method provided in this embodiment first performs a full backup of the virtual machine to be backed up, and stores the full data of the virtual machine disk in the virtual machine to be backed up to the backup disk. Then, the redirection function is used to perform an incremental backup of the virtual machine to be backed up. When there is incremental data, the redirection function is used to write the same incremental data to the virtual machine disk and the backup disk respectively, so as to realize the real-time backup of the virtual machine to be backed up. During the backup process, it is not necessary to frequently take snapshots of the virtual machine to be backed up, and the IO performance of the virtual machine will not be frequently reduced. The security of the virtual machine data will not be affected while the operation of the virtual machine business will be improved. The problem that it is difficult to back up the data of the virtual machine in time when backing up the virtual machine once at a certain interval and the backup will affect the IO performance of the virtual machine is solved.

[0010] In some optional implementations, using a redirection function to write incremental data corresponding to a data modification instruction to a virtual machine disk and a backup disk includes:

[0011] Use the redirection function to determine the incremental data according to the data modification instructions;

[0012] Call the data writing function to write the incremental data to the virtual machine disk;

[0013] Invoke the first thread, and use the first thread to write the incremental data into a preset buffer;

[0014] The second thread is called up, and the incremental data in the preset buffer is written to the backup disk using the second thread.

[0015] In this embodiment, the redirection function calls the data writing function to write the incremental data to the virtual machine disk, and at the same time, calls the first thread and the second thread to write the incremental data to the backup disk, so as to realize the incremental backup of the virtual machine to be backed up, and the backup process will not affect the IO performance of the virtual machine and will not suspend the service of the virtual machine. In addition, by setting a preset buffer in the memory, the IO performance of the virtual machine will not be reduced in the process of writing the incremental data to the backup disk.

[0016] In some optional implementations, using the first thread to write the incremental data into a preset buffer includes:

[0017] Using the first thread to obtain the data to be written, the data size of the data to be written, and the offset of the data to be written according to the incremental data;

[0018] According to the preset format, the data to be written, the data size and the offset are written into the preset buffer.

[0019] In some optional embodiments, the method further comprises:

[0020] Create a new disk according to a preset time interval and determine the creation time of the new disk;

[0021] The new disk is used as a new backup disk, and the identifier of the new backup disk is determined according to the creation time;

[0022] Replace the backup disk with a new one, and create a backup chain including the backup disk according to the identifier.

[0023] In this embodiment, a new disk is created as a new backup disk, an identifier of the new backup disk is determined according to the creation time, and a backup chain including the backup disk is created according to the identifier. Multiple backup disks in the backup chain are used to back up the virtual machine to be backed up, so that when the data is subsequently restored, there are multiple restoreable backup points, and the backup point for restoring the data can be determined by indicating the time.

[0024] In some optional implementations, after using the redirection function to write the incremental data corresponding to the data modification instruction to the virtual machine disk and the backup disk, the method further includes:

[0025] When receiving a data recovery instruction, determining a virtual machine to be recovered corresponding to the data recovery instruction;

[0026] According to the data recovery instruction, determining a first preset number of target backup disks in the backup chain, wherein the target backup disks contain the data to be recovered corresponding to the data recovery instruction;

[0027] The data to be restored in a first preset number of target backup disks are merged according to the identifier of the target backup disk, and the merged data is written into the virtual machine to be restored.

[0028] In this embodiment, after backing up the virtual machine to be backed up, a first preset number of target backup disks can be determined in the backup chain through a data recovery instruction, and the data to be recovered in the target backup disks can be merged and written to the virtual machine to be recovered to complete data recovery. This reduces the data loss when the virtual machine crashes and improves the data security of the virtual machine.

[0029] In some optional implementations, obtaining the full amount of data of the virtual machine disk in the virtual machine to be backed up includes:

[0030] Pause the virtual machine to be backed up;

[0031] Obtain file metadata of the virtual machine disk using a preset method, and create a snapshot corresponding to the virtual machine to be backed up based on the file metadata, wherein the snapshot includes full data;

[0032] Restore the VM to be backed up.

[0033] In some optional implementations, storing the full amount of data to a backup disk includes:

[0034] According to a preset command, in the file system of the virtual machine to be backed up, obtain the data type of the data in the second preset number of storage areas in the snapshot;

[0035] Determine a third preset number of target storage areas according to the data type, wherein the data type of the data in the target storage area is the target type, and the third preset number of target storage areas is included in the second preset number of storage areas;

[0036] The data in the third preset number of target storage areas are written into the backup disk, and the snapshots are deleted.

[0037] In this embodiment, a target storage area with a data type of the target type is determined, and the data in the target storage area is written to the backup disk to achieve a full backup of the virtual machine to be backed up. In addition, backup disk space is saved, unnecessary data is avoided from being written to the backup disk, and the efficiency of the full backup is improved.

[0038] In a second aspect, the present invention provides a virtual machine backup device, the device comprising:

[0039] The first backup module is used to obtain the full amount of data of the virtual machine disk in the virtual machine to be backed up, and store the full amount of data in the backup disk;

[0040] The second backup module is used to start the redirection function in the virtual machine to be backed up, and when the virtual machine to be backed up receives a data modification instruction, use the redirection function to write the incremental data corresponding to the data modification instruction into the virtual machine disk and the backup disk.

[0041] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor are communicatively connected to each other, computer instructions are stored in the memory, and the processor executes the virtual machine backup method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0042] In a fourth aspect, the present invention provides a computer non-volatile readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the virtual machine backup method of the first aspect or any corresponding embodiment thereof.

[0043] In a fifth aspect, the present invention provides a computer program product, including computer instructions, where the computer instructions are used to enable a computer to execute the virtual machine backup method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the related technologies, the drawings required for use in the specific embodiments or the related technical descriptions will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0045] Figure 1 is a flow chart of a virtual machine backup method according to an embodiment of the present invention;

[0046] Figure 2 is a schematic diagram of real-time backup of a virtual machine according to an embodiment of the present invention;

[0047] Figure 3 is a structural block diagram of a virtual machine backup device according to an embodiment of the present invention;

[0048] Figure 4 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0050] Currently, there are two ways to back up virtual machine data: bitmap backup and differential data backup. When backing up a virtual machine using either data backup method, you need to first perform a full backup, and then you can use either data backup method to perform incremental backup. However, both of the above backup methods require a backup after a certain period of time, and a snapshot operation of the virtual machine is required during the backup, which affects the efficiency of the virtual machine. At the same time, when the backup interval is long, the data cannot be backed up in time.

[0051] Currently, qemu-kvm is used to manage virtual machines. Among them, qemu (QuickEMUlator) is a general hardware simulator and virtualization platform, which can simulate a variety of hardware architectures and support full system simulation and simulation of the entire computer system. KVM is a module in the Linux kernel, which transforms the Linux kernel into a virtual machine monitor. KVM provides hardware-assisted full virtualization support. Qemu and KVM can be used in combination, with Qemu responsible for simulating hardware devices and KVM responsible for providing virtualization support for CPU (Central Processing Unit) and memory, which not only retains the flexibility of Qemu but also brings into play the high performance advantage of KVM.

[0052] Based on the above content, an embodiment of the present invention provides a virtual machine backup method, which only needs to take a snapshot of the virtual machine when performing a full backup of the virtual machine for the first time, and there is no need to take a snapshot operation for subsequent incremental backups of the virtual machine. Utilizing the IO redirection function, when the virtual machine has IO data generated, the IO redirection function will write the IO data to the virtual machine disk and buffer respectively, and then write the IO data from the buffer to the backup disk. This achieves the technical effect of real-time backup of the virtual machine without affecting the IO performance of the virtual machine, without suspending the virtual machine business, and without occupying the production storage pool space.

[0053] According to an embodiment of the present invention, a virtual machine backup embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer device with data processing capabilities, such as a computer, a server, etc., and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0054] In this embodiment, a virtual machine backup method is provided. Figure 1 is a flow chart of a virtual machine backup method according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0055] Step S101, obtaining the full data of the virtual machine disk in the virtual machine to be backed up, and storing the full data in the backup disk.

[0056] Specifically, in this embodiment, the full backup is used as the first backup of the virtual machine disk in the virtual machine to be backed up. At this time, all the data of the virtual machine disk, that is, the full data, is backed up.

[0057] Get the full data of the virtual machine disk in the virtual machine to be backed up. For example, you can create a snapshot of the virtual machine disk, which includes the full data. Store the full data in the backup disk.

[0058] Step S102, starting the redirection function in the virtual machine to be backed up, and when the virtual machine to be backed up receives a data modification instruction, using the redirection function to write the incremental data corresponding to the data modification instruction into the virtual machine disk and the backup disk.

[0059] Specifically, this embodiment is used to perform incremental backup of the virtual machine disk, which is a backup after the virtual machine disk is fully backed up. At this time, the data that is backed up is the data that has been modified between the two backup points, including added, deleted, and modified data. Therefore, data modification instructions are, for example: data write instructions, data deletion instructions, instructions for modifying data, etc. After the virtual machine to be backed up receives the data modification instruction, the virtual machine to be backed up will send the corresponding IO data, that is, the incremental data to qemu. The present invention designs an IO redirection function, that is, a redirection function, in qemu, and starts the redirection function in the virtual machine to be backed up. The redirection function can modify the direction in which the virtual machine sends the incremental data, redirecting a copy from the original virtual machine disk to the backup disk, that is, writing the same incremental data to the virtual machine disk and the backup disk at the same time.

[0060] QMP (qemu Machine Protocol) is a remote management interface provided by qemu, which allows users to interact with a running virtual machine through a command line or programming. In this embodiment, the command to start the IO redirection function is designed by QMP, for example: io-redirection-add, io-redirection represents the IO redirection function, and add represents adding and starting. The command to start the IO redirection function notifies qemu to start the IO redirection function through a unix socket (Unix domain socket), where Unix Socket is a mechanism for inter-process communication, specially designed for efficient data exchange between processes on the same computer.

[0061] After the full backup of the virtual machine disk is completed in step S101, the command to start the IO redirection function is used to instruct qemu to start the IO redirection function. When the virtual machine to be backed up receives a data modification instruction, the virtual machine to be backed up will send the corresponding incremental data to qemu, and use the redirection function of qemu to write the incremental data corresponding to the data modification instruction into the virtual machine disk and the backup disk.

[0062] The virtual machine backup method provided in this embodiment first performs a full backup of the virtual machine to be backed up, and stores the full data of the virtual machine disk in the virtual machine to be backed up to the backup disk. Then, the redirection function is used to perform an incremental backup of the virtual machine to be backed up. When there is incremental data, the redirection function is used to write the same incremental data to the virtual machine disk and the backup disk respectively, so as to realize the real-time backup of the virtual machine to be backed up. During the backup process, it is not necessary to frequently take snapshots of the virtual machine to be backed up, and the IO performance of the virtual machine will not be frequently reduced. The security of the virtual machine data will not be affected while the operation of the virtual machine business will be improved. The problem that it is difficult to back up the data of the virtual machine in time when backing up the virtual machine once at a certain interval and the backup will affect the IO performance of the virtual machine is solved.

[0063] In some optional implementations, using a redirection function to write incremental data corresponding to a data modification instruction to a virtual machine disk and a backup disk includes:

[0064] Use the redirection function to determine the incremental data according to the data modification instructions;

[0065] Call the data writing function to write the incremental data to the virtual machine disk;

[0066] Invoke the first thread, and use the first thread to write the incremental data into a preset buffer;

[0067] The second thread is called up, and the incremental data in the preset buffer is written to the backup disk using the second thread.

[0068] Specifically, the data modification instructions include: data write instructions, data delete instructions, instructions for modifying data, etc. After receiving the data modification instructions, the backup virtual machine will send the corresponding IO data, i.e., incremental data, to qemu-kvm. At this time, the redirection function in qemu is used to determine the incremental data according to the data modification instructions.

[0069] Data writing functions, for example: Write function. The redirection function will call the data writing function to write data to the virtual machine disk. At this time, the redirection function can intercept incremental data; when qemu-kvm sends data, qemu-kvm will select the corresponding driver function according to the device type of the virtual disk, but in the end, the data writing function is called to write the incremental data to the virtual machine disk. The data writing function requires three parameters, including: offset, length, and buffer, where offset represents the offset of data writing, length represents the length of data to be written, and buffer represents the data to be written.

[0070] At the same time, the redirection function calls up the first thread, and uses the first thread to write the incremental data into the preset buffer. For example, the first thread obtains three parameters, namely, offset, length, and buffer, and assembles these three parameters into the format of {offset, length, buffer} and stores them in the preset buffer. The preset buffer is a part of the memory that receives the IO data sent by the virtual machine. The preset buffer is needed because the read and write speed of the memory is much faster than the read and write speed of the disk. Adding the preset buffer will not reduce the IO performance of the virtual machine.

[0071] The second thread is called up, and the incremental data in the preset buffer is written into the backup disk by using the second thread.

[0072] It should be noted that when performing a full backup and performing the first backup operation, the IO redirection function is started for qemu. When there is data IO writing, the IO redirection function intercepts a copy and writes it to the buffer. In this embodiment, the IO redirection function is designed in qemu.

[0073] The above process is as follows Figure 2 As shown, the redirection function in qemu calls the Write function to write the incremental data to the virtual machine disk. The redirection function calls the first thread, uses the first thread to write the incremental data to the buffer, calls the second thread, and uses the second thread to write the incremental data in the buffer to the latest backup disk created in the backup chain. For example: there are backup disks 1 to backup disk Y in the backup chain, a total of Y backup disks, Y represents multiple, and there is no specific number limit here. Backup disk Y is the latest created backup disk, and the second thread writes the incremental data to backup disk Y.

[0074] In this embodiment, the redirection function calls the data writing function to write the incremental data to the virtual machine disk, and at the same time, calls the first thread and the second thread to write the incremental data to the backup disk, so as to realize the incremental backup of the virtual machine to be backed up, and the backup process will not affect the IO performance of the virtual machine and will not suspend the service of the virtual machine. In addition, by setting a preset buffer in the memory, the IO performance of the virtual machine will not be reduced in the process of writing the incremental data to the backup disk.

[0075] In some optional implementations, using the first thread to write the incremental data into a preset buffer includes:

[0076] Using the first thread to obtain the data to be written, the data size of the data to be written, and the offset of the data to be written according to the incremental data;

[0077] According to the preset format, the data to be written, the data size and the offset are written into the preset buffer.

[0078] Specifically, the first thread is used to obtain incremental data and determine the data to be written in the incremental data that needs to be written to the backup disk, for example, all incremental data can be used as the data to be written, and the data size (length) of the data to be written and the offset (offset) of the data to be written to the backup disk are determined.

[0079] The preset format is, for example: {offset, length, data}. According to the preset format, the data to be written, the data size, and the offset are written to the backup disk.

[0080] In some optional embodiments, the method further comprises:

[0081] Create a new disk according to a preset time interval and determine the creation time of the new disk;

[0082] The new disk is used as a new backup disk, and the identifier of the new backup disk is determined according to the creation time;

[0083] Replace the backup disk with a new one, and create a backup chain including the backup disk according to the identifier.

[0084] Specifically, the preset time interval is, for example, 1 hour. According to the preset time interval, a new disk is created, and the creation time corresponding to the new disk is determined, for example, the xth backup disk is created at time x, the x+1th backup disk is created at time x+1, and the new disk is a disk in qcow2 format, and the qcow2 format supports a chain structure.

[0085] The new disk is used as a new backup disk. The last backup disk is the backing file of the new backup disk. Each backup disk only records the data between two backup points. The backup point is the creation time of the backup disk. For example, the xth backup disk is created at time x, and the x+1th backup disk is created at time x+1. Then the x+1th backup disk is used to back up the data between time x and time x+1. The x+1th backup disk depends on the xth backup disk. Each backup disk is interdependent. The backup disk created later needs to depend on the snapshot disk created earlier.

[0086] The new disk is used as a new backup disk, and the ID of the new backup disk is determined according to the creation time. For example, the creation time of the backup disk is used as the backup disk ID. For example, the backup disk created at time x is ID x, and the backup disk created at time x+1 is ID x+1. Multiple backup disks can ensure that there are multiple recoverable backup points when restoring data.

[0087] Use a new backup disk to replace the backup disk, and create a backup chain containing the backup disk according to the identifier. As mentioned earlier, each backup disk depends on each other, and the later backup disk depends on the previous backup disk. When restoring, you also need to search for data in the previous disk that you depend on. The data in the backup disk created later + the data in the snapshot disk created earlier = all the backup data of the current virtual machine.

[0088] In this embodiment, a new disk is created as a new backup disk, an identifier of the new backup disk is determined according to the creation time, and a backup chain including the backup disk is created according to the identifier. Multiple backup disks in the backup chain are used to back up the virtual machine to be backed up, so that when the data is subsequently restored, there are multiple restoreable backup points, and the backup point for restoring the data can be determined by indicating the time.

[0089] In some optional implementations, after using the redirection function to write the incremental data corresponding to the data modification instruction to the virtual machine disk and the backup disk, the method further includes:

[0090] When receiving a data recovery instruction, determining a virtual machine to be recovered corresponding to the data recovery instruction;

[0091] According to the data recovery instruction, determining a first preset number of target backup disks in the backup chain, wherein the target backup disks contain the data to be recovered corresponding to the data recovery instruction;

[0092] The data to be restored in a first preset number of target backup disks are merged according to the identifier of the target backup disk, and the merged data is written into the virtual machine to be restored.

[0093] Specifically, when the user needs to restore virtual machine data, he will send a data recovery instruction to qemu. The instruction may include the backup disk that needs to be restored, the virtual machine to be restored, and the time or time range corresponding to the data to be restored. For example: data before n time needs to be restored, or data from the nth time to the mth time needs to be restored, where m>n.

[0094] When a data recovery instruction is received, the virtual machine to be recovered corresponding to the data recovery instruction is determined according to the data recovery instruction. For example, if the virtual machine to be recovered indicated by the data recovery instruction already exists, such as a previously failed virtual machine, data recovery is required after the repair is completed, and the virtual machine is used as the virtual machine to be recovered; if the virtual machine to be recovered indicated by the data recovery instruction does not exist, a virtual machine is created as the virtual machine to be recovered.

[0095] The bottom layer will determine the first preset number of target backup disks in the backup chain according to the data recovery instruction, and the corresponding relationship is saved in the database. For example, the preset time interval is 1 hour, and the identifier of each backup disk in the backup chain is determined, and the identifier is the creation time of the backup disk. If the data recovery instruction indicates to restore the data before n hours, the backup disk with a creation time less than or equal to n-1 will be used as the target backup disk; if the data recovery instruction indicates to restore the data from the nth time to the mth time, the backup disk with a creation time between n and m-1 will be used as the target backup disk. The target backup disk contains the data to be restored corresponding to the data recovery instruction.

[0096] Use the convert command provided by qemu-img to merge the data to be restored in the first preset number of target backup disks. During the merging process, the order of the target backup disks will be determined according to the identifiers of the target backup disks, and the data will be merged according to the order, and the merged data will be written to the disk of the virtual machine to be restored.

[0097] In this embodiment, after backing up the virtual machine to be backed up, a first preset number of target backup disks can be determined in the backup chain through a data recovery instruction, and the data to be recovered in the target backup disks can be merged and written to the virtual machine to be recovered to complete data recovery. This reduces the data loss when the virtual machine crashes and improves the data security of the virtual machine.

[0098] In some optional implementations, obtaining the full amount of data of the virtual machine disk in the virtual machine to be backed up includes:

[0099] Pause the virtual machine to be backed up;

[0100] Obtain file metadata of the virtual machine disk using a preset method, and create a snapshot corresponding to the virtual machine to be backed up based on the file metadata, wherein the snapshot includes full data;

[0101] Restore the VM to be backed up.

[0102] Specifically, a snapshot can be used to perform a full backup of the virtual machine to be backed up. A snapshot containing the full data of the virtual machine disk needs to be created first.

[0103] The preset method is, for example, the cp--reflink method, where cp--reflink is an option of the cp command in the Linux system, which uses the CoW (Copy-on-Write) function of the file system to efficiently copy files or create snapshots. First, pause the virtual machine to be backed up. Use the preset method to obtain the file metadata of the virtual machine disk, and create a snapshot containing the full data of the virtual machine disk based on the file metadata. Compared with the original virtual machine disk, this snapshot only copies the metadata of the files in the virtual machine disk, and the disk data of the virtual machine disk will only change when the data changes. The metadata only records the distribution range of the disk data and occupies less space. This snapshot only copies the metadata, and new storage space will only be allocated when the disk data changes, so it occupies less space.

[0104] After the snapshot is created, enable the redirection function of qemu and then restore the virtual machine.

[0105] In some optional implementations, storing the full amount of data to a backup disk includes:

[0106] According to a preset command, in the file system of the virtual machine to be backed up, obtain the data type of the data in the second preset number of storage areas in the snapshot;

[0107] Determine a third preset number of target storage areas according to the data type, wherein the data type of the data in the target storage area is the target type, and the third preset number of target storage areas is included in the second preset number of storage areas;

[0108] The data in the third preset number of target storage areas are written into the backup disk, and the snapshots are deleted.

[0109] Specifically, in computer storage, the basic unit of disk space is not bytes, but storage areas called clusters. For floppy disks, each cluster usually occupies one sector, while for hard disks, the number of sectors in a cluster depends on the capacity of the hard disk. For example, the number of sectors in a cluster is 4, 8, 16, 32, 64, etc. The file system of the virtual machine to be backed up will record which clusters in the virtual machine disk store real data and which clusters store empty data. Preset commands include, for example, the qemu-img map command, where qemu-imgmap is a command in the qemu toolset that is used to analyze and display the internal structure of a virtual disk image. It can help you understand the status of each data block in the image file, including which blocks are allocated, which blocks are unallocated, and which blocks are compressed or encrypted.

[0110] Examples of data types include real data and hole data, where real data refers to data related to the business of the virtual machine to be backed up, and examples of hole data include data to be cleaned up, damaged data, etc. Alternatively, hole data may also represent areas where data is not actually written. According to the above preset command, in the file system of the virtual machine to be backed up, the data type of the data in the second preset number of storage areas (clusters) in the snapshot is obtained to determine which clusters store real data and which clusters store hole data. The second preset number may be, for example, 10, 20, 30, etc., values ​​that meet actual needs, and the second preset number of clusters may be all clusters contained in the snapshot.

[0111] The target type is real data. Storage areas whose data type is the target type are extracted from the second preset number of storage areas to obtain a third preset number of target storage areas, where the third preset number is less than or equal to the second preset number.

[0112] The data in the third preset number of target storage areas are written to the backup disk, so that only the real data cluster is copied to the backup disk in the backup storage pool. After the copying is completed, the snapshot is deleted.

[0113] In this embodiment, a target storage area with a data type of the target type is determined, and the data in the target storage area is written to the backup disk to achieve a full backup of the virtual machine to be backed up. In addition, backup disk space is saved, unnecessary data is avoided from being written to the backup disk, and the efficiency of the full backup is improved.

[0114] In some optional implementations, another virtual machine data recovery method is provided, and the specific process may also include steps A1 to A4.

[0115] Step A1: obtaining a virtual machine recovery instruction sent by a user, and determining multiple target backup disks according to the virtual machine recovery instruction.

[0116] Specifically, if the virtual machine recovery instruction indicates to recover data from time n to time m, the backup disk with creation time between n and m-1 is used as the target backup disk. The target backup disk contains the data to be recovered corresponding to the virtual machine recovery instruction.

[0117] Step A2: creating an intermediate disk in the virtual machine to be restored selected by the user according to the virtual machine restoration instruction, and starting the virtual machine to be restored based on the intermediate disk.

[0118] Specifically, the virtual machine to be restored selected by the user is determined according to the virtual machine restoration instruction, an intermediate disk is established in the virtual machine to be restored, and the virtual machine to be restored is controlled to be started on the intermediate disk. At this time, the virtual machine to be restored has been started, and the IO data of the virtual machine to be restored is recorded on the intermediate disk. The virtual machine to be restored sends a request to merge backup data to the backup chain containing multiple target backup disks. The amount of data in the target backup disk is large, which may be tens of GB, resulting in a long time for data recovery. At this time, the virtual machine to be restored is started on the intermediate disk, so that the virtual machine to be restored can still process tasks during the recovery process.

[0119] Step A3: merge the data to be restored in the target backup disk to obtain a backup merge file for restoring the virtual machine.

[0120] Specifically, after receiving the request for merging backup data, the data to be restored in multiple target backup disks are merged to obtain a backup merge file, a management plane migration channel is established, and the backup merge file is copied to a specified path of the virtual machine to be restored.

[0121] Step A4, performing read and write redirection of the intermediate disk, so that after the backup merged file is moved to the designated path of the virtual machine to be restored, the backup merged file can be associated with the intermediate disk.

[0122] Specifically, the specific process of executing read and write redirection of the intermediate disk is to point the BackingFile of the intermediate disk to a new file, modify the file that the copied backup merged file originally depends on to the intermediate disk, so that the copied backup merged file is associated with the intermediate disk.

[0123] Step A5: copy the backup merged file to the virtual machine to be restored, and merge the copied backup merged file with the intermediate disk.

[0124] Specifically, after copying the backup merge file to the specified path of the virtual machine to be restored, the virtual machine IO is suspended, and then the action of redirecting the intermediate disk to read and write the source file is initiated, and the intermediate disk read and write source file modification is performed. After the modification is successful, the virtual machine IO is first unsuspended, and then the intermediate disk is merged with the copied backup merge file to complete the process of restoring the virtual machine.

[0125] During the entire recovery process, the virtual machine to be restored is in the running state, and the data generated by the virtual machine to be restored during this process is recorded in the intermediate disk. Therefore, after copying the backup merge file to the virtual machine to be restored, in order to achieve the effect that the virtual machine only runs on a new disk, it is necessary to delete the temporarily created intermediate disk, that is, migrate the intermediate disk and its data to the backup merge file of the virtual machine to be restored.

[0126] In this embodiment, by establishing an intermediate disk in the virtual machine to be restored, the virtual machine can be run on the intermediate disk, so that the virtual machine to be restored is in a running state during the entire data recovery process, and the business of the virtual machine will not be interrupted. After starting the virtual machine, the copied backup merge file is merged with the intermediate disk to complete the recovery of the virtual machine, ensuring the data integrity of the virtual machine, improving the recovery speed of the virtual machine, and reducing the time for restoring the virtual machine.

[0127] In this embodiment, a virtual machine backup device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0128] This embodiment provides a virtual machine backup device, such as Figure 3 As shown, including:

[0129] The first backup module 301 is used to obtain the full amount of data of the virtual machine disk in the virtual machine to be backed up, and store the full amount of data in the backup disk;

[0130] The second backup module 302 is used to start the redirection function in the virtual machine to be backed up, and when the virtual machine to be backed up receives a data modification instruction, use the redirection function to write the incremental data corresponding to the data modification instruction into the virtual machine disk and the backup disk.

[0131] In some optional implementations, the second backup module 302 includes:

[0132] A first determining unit, configured to determine incremental data according to the data modification instruction by using a redirection function;

[0133] A first writing unit, used for calling a data writing function to write incremental data into a virtual machine disk;

[0134] A second writing unit is used to call up the first thread and use the first thread to write the incremental data into a preset buffer;

[0135] The third writing unit is used to call up the second thread and use the second thread to write the incremental data in the preset buffer into the backup disk.

[0136] In some optional implementations, the third writing unit includes:

[0137] A determination submodule is used to obtain the data to be written, the data size of the data to be written, and the offset of the data to be written according to the incremental data using the first thread;

[0138] The writing submodule is used to write the data to be written, the data size and the offset into the preset buffer according to the preset format.

[0139] In some optional embodiments, the device further comprises:

[0140] A first determination module is used to create a new disk according to a preset time interval and determine a creation time corresponding to the new disk;

[0141] A second determination module is used to use the new disk as a new backup disk and determine the identifier of the new backup disk according to the creation time;

[0142] The creation module is used to replace the backup disk with a new backup disk and create a backup chain including the backup disk according to the identifier.

[0143] In some optional embodiments, the device further comprises:

[0144] A third determination module is used to determine the to-be-restored virtual machine corresponding to the data recovery instruction when the data recovery instruction is received;

[0145] A fourth determination module is used to determine a first preset number of target backup disks in the backup chain according to the data recovery instruction, wherein the target backup disks contain the data to be recovered corresponding to the data recovery instruction;

[0146] The data recovery module is used to merge the data to be recovered in a first preset number of target backup disks according to the identifier of the target backup disk, and write the merged data into the virtual machine to be recovered.

[0147] In some optional implementations, the first backup module 301 includes:

[0148] A setting unit, used for pausing the virtual machine to be backed up;

[0149] A snapshot creation unit is used to obtain file metadata of a virtual machine disk in a preset manner, and create a snapshot corresponding to the virtual machine to be backed up according to the file metadata, wherein the snapshot includes full data;

[0150] The recovery unit is used to recover the virtual machine to be backed up.

[0151] In some optional implementations, the first backup module 301 further includes:

[0152] An acquiring unit, configured to acquire data types of data in a second preset number of storage areas in the snapshot in a file system of the virtual machine to be backed up according to a preset command;

[0153] A second determining unit is used to determine a third preset number of target storage areas according to the data type, wherein the data type of the data in the target storage area is the target type, and the third preset number of target storage areas is included in the second preset number of storage areas;

[0154] The fourth writing unit is used to write the data in the third preset number of target storage areas into the backup disk and delete the snapshot.

[0155] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0156] The virtual machine backup device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0157] The embodiment of the present invention also provides a computer device having the above Figure 3 Virtual machine backup appliance shown.

[0158] See also Figure 4 , Figure 4 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 4 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 4 A processor 10 is taken as an example.

[0159] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include an integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable logic gate array, a general purpose array logic or any combination thereof.

[0160] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.

[0161] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device 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.

[0162] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0163] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.

[0164] The embodiment of the present invention also provides a computer non-volatile readable storage medium. The above method according to the embodiment of the present invention can be implemented in hardware, firmware, or implemented as a computer code that can be recorded in a storage medium, or downloaded through a network and originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor or hardware, the method shown in the above embodiment is implemented.

[0165] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of computer program instructions in computer-readable media includes, but is not limited to, source files, executable files, installation package files, etc., and accordingly, the way in which computer program instructions are executed by a computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable non-volatile storage medium or communication medium accessible to the computer.

[0166] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined in this application.

Claims

1. A virtual machine backup method, characterized in that: The method comprises: Obtaining full data of the virtual machine disk in the virtual machine to be backed up, and storing the full data in the backup disk; A redirection function is started in the virtual machine to be backed up, and when the virtual machine to be backed up receives a data modification instruction, the redirection function is used to write incremental data corresponding to the data modification instruction into the virtual machine disk and the backup disk.

2. The method according to claim 1, characterized in that: The step of using the redirection function to write the incremental data corresponding to the data modification instruction into the virtual machine disk and the backup disk includes: Determine the incremental data according to the data modification instruction by utilizing the redirection function; Calling a data writing function to write the incremental data into the virtual machine disk; Invoke a first thread, and use the first thread to write the incremental data into a preset buffer; A second thread is called up, and the incremental data in the preset buffer is written to the backup disk using the second thread.

3. The method according to claim 2, characterized in that The step of using the first thread to write the incremental data into a preset buffer includes: Using the first thread to obtain the data to be written, the data size of the data to be written, and the offset of the data to be written according to the incremental data; The data to be written, the data size and the offset are written into the preset buffer according to a preset format.

4. The method according to claim 1, characterized in that: The method further comprises: Creating a new disk according to a preset time interval, and determining a creation time corresponding to the new disk; Using the new disk as a new backup disk, and determining an identifier of the new backup disk according to the creation time; The backup disk is replaced by the new backup disk, and a backup chain including the backup disk is created according to the identifier.

5. The method according to claim 4, characterized in that After using the redirection function to write the incremental data corresponding to the data modification instruction into the virtual machine disk and the backup disk, the method further includes: When receiving a data recovery instruction, determining a virtual machine to be recovered corresponding to the data recovery instruction; According to the data recovery instruction, determining a first preset number of target backup disks in the backup chain, wherein the target backup disks contain the data to be recovered corresponding to the data recovery instruction; The data to be restored in a first preset number of the target backup disks are merged according to the identifier of the target backup disk, and the merged data is written into the virtual machine to be restored.

6. The method according to claim 1, characterized in that The step of obtaining the full amount of data of the virtual machine disk in the virtual machine to be backed up includes: Pause the virtual machine to be backed up; Obtaining file metadata of the virtual machine disk in a preset manner, and creating a snapshot corresponding to the virtual machine to be backed up according to the file metadata, wherein the snapshot includes the full amount of data; Restore the virtual machine to be backed up.

7. The method according to claim 6, characterized in that The storing the full amount of data to the backup disk comprises: Acquiring, in the file system of the virtual machine to be backed up, data types of data in a second preset number of storage areas in the snapshot according to a preset command; Determine a third preset number of target storage areas according to the data type, wherein the data type of the data in the target storage area is a target type, and the third preset number of target storage areas is included in the second preset number of storage areas; The data in a third preset number of the target storage areas are written into the backup disk, and the snapshot is deleted.

8. A virtual machine backup device, characterized in that: The device comprises: The first backup module is used to obtain the full amount of data of the virtual machine disk in the virtual machine to be backed up, and store the full amount of data in the backup disk; The second backup module is used to start the redirection function in the virtual machine to be backed up, and when the virtual machine to be backed up receives a data modification instruction, use the redirection function to write the incremental data corresponding to the data modification instruction into the virtual machine disk and the backup disk.

9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the virtual machine backup method according to any one of claims 1 to 7 by executing the computer instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the virtual machine backup method according to any one of claims 1 to 7.

Citation Information

Cited By

  • NFS virtual machine mounting system and method based on storage stacking architecture

    CN121597133A

  • Nfs virtual machine mounting system and method based on storage stacking architecture

    CN121597133B