Virtual machine backup methods, apparatus, computer equipment, and readable storage media

By identifying the snapshot type of virtualization software and dynamically selecting backup strategies, the compatibility issues of traditional virtual machine backup methods are resolved, achieving cross-version backup consistency and stability, and improving the security and backup efficiency of virtual machine data.

CN120994460BActive Publication Date: 2026-07-03广州鼎甲计算机科技有限公司

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
广州鼎甲计算机科技有限公司
Filing Date
2025-07-10
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

Traditional virtual machine backup methods rely on a single snapshot mechanism, resulting in poor compatibility and difficulty in achieving unified backup management in multi-version heterogeneous environments.

Method used

By identifying the snapshot type of the virtualization software, dynamically selecting external or internal snapshot methods, and combining a merging mechanism to generate backup files, the system adapts to the differences between different virtualization software versions.

Benefits of technology

It improves the compatibility and stability of virtual machine backups, reduces backup chain risks, enhances data reliability, expands support for older QEMU versions, and improves backup efficiency and security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120994460B_ABST
    Figure CN120994460B_ABST
Patent Text Reader

Abstract

This application relates to a virtual machine backup method, apparatus, computer device, and readable storage medium. The method includes: obtaining the snapshot type of the virtualization software; copying a target copy file matching the snapshot type to a backup server according to the snapshot type, to generate a backup file on the backup server; wherein, when the snapshot type is an external snapshot, the target copy file is determined based on the virtual machine's original disk file or a read-only disk file; when the snapshot type is an internal snapshot, the target copy file is the complete virtual machine disk file. This method can improve the compatibility of virtual machine backup functions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of virtual machine technology, and in particular to a virtual machine backup method, apparatus, computer device, and readable storage medium. Background Technology

[0002] In cloud computing environments, virtual machines (VMs) serve as an important means of resource abstraction and isolation, carrying a large number of computing and storage tasks. This makes the reliability and security of virtual machine data in the cloud a research focus that has always been of great concern to both academia and industry.

[0003] Traditional virtual machine backup methods rely on a single snapshot mechanism, which leads to poor compatibility issues. Summary of the Invention

[0004] Therefore, it is necessary to provide a virtual machine backup method, apparatus, computer device, and readable storage medium that can improve the compatibility of virtual machine backups, addressing the aforementioned technical problems.

[0005] Firstly, in one example, this application provides a virtual machine backup method, the method comprising:

[0006] Obtain the snapshot type of the virtualization software;

[0007] Based on the snapshot type, copy the target file that matches the snapshot type to the backup server to generate the backup file on the backup server;

[0008] Specifically, when the snapshot type is an external snapshot, the target copy file is determined based on the original disk file or the read-only disk file of the virtual machine; when the snapshot type is an internal snapshot, the target copy file is the complete virtual machine disk file.

[0009] In one embodiment, the backup file includes a base backup file; based on the snapshot type, a target copy file matching the snapshot type is copied to the backup server to generate a backup file on the backup server, including:

[0010] If the snapshot type is an external snapshot and it is determined that there is no base backup file in the current backup server, then the first disk file of the virtual machine is determined to be the target copy file; the first disk file is the original disk file of the virtual machine configured as a read-only disk.

[0011] Copy the target file to the backup server to generate the base backup file on the backup server.

[0012] In one embodiment, the backup file further includes an incremental backup file; the method also includes:

[0013] If the snapshot type is an external snapshot and it is determined that a base backup file exists in the current backup server, then a third disk file that depends on the second disk file, which is currently the active disk of the virtual machine, is created.

[0014] Change the second disk file from active to read-only, and configure the third disk file as the new active disk for the virtual machine;

[0015] The second disk file is identified as the target copy file, and the target copy file is copied to the backup server to generate an incremental backup file on the backup server.

[0016] In one embodiment, after copying the target file to the backup server, the method further includes:

[0017] The second disk file in the virtual machine is merged with the read-only disk file that the second disk file depends on to obtain the fourth disk file;

[0018] Configure the fourth disk file as a new read-only disk for the virtual machine, and configure the third disk file as an active disk for the virtual machine that depends on the fourth disk file.

[0019] In one embodiment, the method further includes:

[0020] In response to receiving a disk recovery command and the snapshot type being external snapshot, the backup file is retrieved from the backup server;

[0021] If the backup file only includes the base backup file, then the base backup file is determined to be the base disk file;

[0022] If the backup file includes a basic backup file and an incremental backup file, then the basic backup file and the incremental backup file are merged to obtain the basic disk file;

[0023] Create a new virtual machine based on the base disk file.

[0024] In one embodiment, based on the snapshot type, a target copy file matching the snapshot type is copied to a backup server to generate a backup file on the backup server, including:

[0025] If the snapshot type is internal snapshot, it indicates that an internal snapshot point will be generated for the current virtual machine disk file;

[0026] The target copy file is the complete virtual machine disk file of the current virtual machine. The target copy file is copied to the backup server, and the virtual machine disk file is rolled back to the internal snapshot point.

[0027] In one embodiment, the method further includes:

[0028] In response to receiving a disk recovery command and the snapshot type is internal snapshot, retrieve the backup file of the specified internal snapshot point from the backup server;

[0029] Create a new virtual machine based on the backup file.

[0030] Secondly, in one example, this application provides a virtual machine disk backup and restore device, the device comprising:

[0031] The snapshot type acquisition module is used to obtain the snapshot type of the virtualization software;

[0032] The backup module is used to copy target files that match the snapshot type to the backup server, so as to generate backup files on the backup server;

[0033] Specifically, when the snapshot type is an external snapshot, the target copy file is determined based on the original disk file or the read-only disk file of the virtual machine; when the snapshot type is an internal snapshot, the target copy file is the complete virtual machine disk file.

[0034] Thirdly, in one example, this application provides a computer device including a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps in the above-described method embodiments.

[0035] Fourthly, in one example, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the above-described method embodiments.

[0036] The aforementioned virtual machine backup method, apparatus, computer device, and readable storage medium obtain the snapshot type of the virtualization software and copy a target copy file matching the snapshot type to a backup server to generate a backup file on the backup server. Through the above method, this application can execute corresponding backup strategies based on different snapshot types, thereby effectively improving the compatibility of the virtual machine backup function. Attached Figure Description

[0037] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0038] Figure 1 This is an application environment diagram of a virtual machine backup method in one embodiment;

[0039] Figure 2 This is a flowchart illustrating a virtual machine backup method in one embodiment;

[0040] Figure 3 This is a schematic diagram illustrating the determination of the snapshot type corresponding to the virtualization software in one embodiment;

[0041] Figure 4 This is a backup scheme corresponding to the snapshot type being external snapshot in one embodiment;

[0042] Figure 5 This is the disk dependency structure corresponding to the snapshot type being external snapshot in one embodiment;

[0043] Figure 6 This is the backup scheme corresponding to the snapshot type being external snapshot in another embodiment;

[0044] Figure 7 This is a virtual machine recovery process corresponding to an external snapshot type in one embodiment;

[0045] Figure 8 This is a backup scheme corresponding to an internal snapshot type in one embodiment;

[0046] Figure 9 This is a structural block diagram of a virtual machine backup device in one embodiment;

[0047] Figure 10 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0048] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0049] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.

[0050] With the rapid development and widespread application of cloud computing technology, virtual machines have gradually evolved into one of the core infrastructures in modern information technology architecture. In the cloud computing environment, virtual machines (VMs) serve as an important means of resource abstraction and isolation, undertaking a large number of computing and storage tasks. Therefore, the reliability and security of virtual machine data in the cloud have become a research focus of great concern to both academia and industry.

[0051] Kernel-based Virtual Machine (KVM) is a kernel-based virtualization solution. Combined with QEMU (Quick Emulator), it enables efficient hardware emulation and I / O virtualization. Due to its open-source nature, stability, and high customizability, it has become one of the most widely adopted virtualization technology frameworks in mainstream cloud computing platforms. In the KVM architecture, QEMU plays a crucial role in simulating the hardware environment and handling I / O requests; therefore, data backup functionality for KVM virtual machines is typically implemented through QEMU mechanisms.

[0052] To improve the efficiency of virtual resource management, the open-source virtualization management framework Libvirt is widely used for unified scheduling and control of KVM virtualization platforms. Libvirt provides standardized APIs by encapsulating the interfaces between KVM and QEMU to support operations such as virtual machine lifecycle management, storage configuration, and backup task scheduling. In actual deployments, backup operations are typically initiated by Libvirt, which uses the underlying QEMU interfaces to snapshot the virtual machine state and persist data.

[0053] Most current mainstream backup methods rely on the external snapshot interface provided by QEMU. However, this functionality is only fully implemented and optimized in newer versions of QEMU. For virtual machines deployed in older versions of QEMU (such as 2.x or earlier), this interface cannot be used directly to perform hot backup operations. This version dependency limits the applicability of traditional backup solutions and makes it difficult to manage unified backups for large-scale, multi-version heterogeneous environments.

[0054] To address the aforementioned issues, this application provides virtual machine backup methods as described in the following embodiments.

[0055] The virtual machine backup method provided in this application embodiment can be applied to, for example, Figure 1In the application environment shown, host machine 102 communicates with server 104 via a network. A data storage system can store the data that server 104 needs to process. The data storage system can be integrated onto server 104, or it can be located on a cloud or other network server. Host machine 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, etc. Server 104 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.

[0056] In one exemplary embodiment, such as Figure 2 As shown, a virtual machine backup method is provided, which can be applied to... Figure 1 Taking host machine 102 as an example, the explanation includes the following steps S202 to S206. Wherein:

[0057] Step S202: Obtain the snapshot type of the virtualization software.

[0058] The virtualization software provides device emulation and disk imaging capabilities for virtual machines, and is a core component for implementing the snapshot function. Optionally, the virtualization software can be QEMU, an open-source virtualization software that supports both system-level and user-level emulation.

[0059] In some examples, the snapshot type of the virtualization software can include both external and internal snapshots. For instance, if the virtualization software on the host machine is QEMU, the snapshot type can be determined by detecting the QEMU version number.

[0060] Specifically, the host machine can obtain the snapshot type corresponding to the virtualization software by identifying the version number of the virtualization software.

[0061] For example, such as Figure 3 As shown, during the initialization phase, the command `qemu-system-x86_64 --version` can be executed to obtain the QEMU version information of the current system, and different snapshot strategies can be selected based on the version information: when the QEMU version number is higher than or equal to 2.0, QEMU is in a high version, and the corresponding snapshot type is an external snapshot, requiring the virtual machine to be backed up using an external snapshot scheme; when the QEMU version number is lower than 2.0, QEMU is in a low version, and the corresponding snapshot type is an internal snapshot, requiring the virtual machine to be backed up using an internal snapshot scheme.

[0062] Step S204: Based on the snapshot type, copy the target copy file that matches the snapshot type to the backup server to generate a backup file on the backup server;

[0063] Specifically, when the snapshot type is an external snapshot, the target copy file is determined based on the virtual machine's original disk file or a read-only disk file; when the snapshot type is an internal snapshot, the target copy file is the complete virtual machine disk file. Optionally, the virtual machine includes a KVM virtual machine.

[0064] For example, the aforementioned read-only disk file can be a disk file in the virtual machine that has been converted from an active state to a read-only state. Specifically, the disk file representing the active state can serve as the active disk of the virtual machine, and the disk file representing the read-only state can serve as the read-only disk of the virtual machine.

[0065] In practical applications, the backup server can be another independent physical server device or another virtual machine. This application does not limit the implementation method of the backup server.

[0066] Specifically, the host machine copies the target copy file that matches the snapshot type of the current virtualization software to the backup server, so as to generate the corresponding backup file in the backup server.

[0067] For example, when the snapshot type corresponding to the virtualization software is an external snapshot, the host machine can determine whether the target copy file is the original disk file in the current virtual machine or a disk file in a read-only state, based on the current disk status of the virtual machine and the backup status of the backup server. Optionally, the backup status of the backup server can be the storage status of backup files on the backup server, such as whether the backup files stored on the backup server only include the basic backup file.

[0068] In some examples, when the virtualization software's snapshot type is an external snapshot, the host machine can determine the current virtual machine's complete virtual machine disk file as the target copy file and copy the target copy file to the backup server to generate a backup file corresponding to the current virtual machine's complete virtual machine disk file on the backup server.

[0069] The aforementioned virtual machine backup method obtains the snapshot type of the virtualization software and copies a target file matching the snapshot type to the backup server to generate a backup file. Through this method, this application can dynamically select between external and internal snapshots for backup, effectively solving the compatibility issues caused by differences in snapshot mechanisms between different virtualization software versions and ensuring consistent operation of the backup function in various cloud environments.

[0070] In one embodiment, such as Figure 4As shown, the backup file includes a base backup file; according to the snapshot type, a target copy file matching the snapshot type is copied to the backup server to generate a backup file on the backup server, including the following steps S302 to S304. Wherein:

[0071] Step S302: If the snapshot type is external snapshot and it is determined that there is no base backup file in the current backup server, then the first disk file of the virtual machine is determined to be the target copy file.

[0072] The first disk file is the original disk file configured as a read-only disk for the virtual machine. Furthermore, the base backup file can be configured to back up the original disk file of the virtual machine. It can be understood that if the base backup file does not exist on the current backup server, it means that the current backup server has not yet backed up the original disk file of the virtual machine.

[0073] For example, such as Figure 5 As shown, when in external snapshot mode, the virtual machine's disk can include a read-only disk and an active disk. The virtual machine's active disk can perform write operations based on user instructions. The virtual machine's active disk depends on the virtual machine's read-only disk to enable the function of reading the required read-only data from the read-only disk.

[0074] Specifically, if the snapshot type corresponding to the virtualization software is an external snapshot, and the base backup file does not exist in the current backup server, the host machine can specify the first disk file of the virtual machine (i.e., the original disk file) as the target copy file.

[0075] Step S304: Copy the target file to the backup server to generate the base backup file on the backup server.

[0076] Specifically, the host machine can copy the specified target file to the backup server, thereby enabling the backup server to generate a base backup file corresponding to the original disk file of the virtual machine.

[0077] In practical applications, the Libvirt API (Application Programming Interface) can be used, such as `virsh snapshot-create-as`, to create corresponding external snapshots for the virtual machine. Assuming the original virtual machine disk file is `base.qcow2`, the external snapshot created based on this original disk file is `active1.qcow2`, with the following image dependency structure: `base.qcow2 <-- active1.qcow2`. In this case, `base.qcow2` will be configured as the virtual machine's current read-only disk as the historical baseline for data, while `active1.qcow2` will be configured as the active disk. During backup, the host machine can specify the original disk file `base.qcow2` as the target copy file and copy this target copy file to the backup server to generate the corresponding base backup file.

[0078] In one embodiment, such as Figure 6 The backup file also includes an incremental backup file; the method further includes steps S402 to S406. Wherein:

[0079] Step S402: If the snapshot type is an external snapshot and it is determined that a basic backup file exists in the current backup server, then a third disk file that depends on the second disk file, which is currently the active disk of the virtual machine, is created.

[0080] It is understandable that when a basic backup file exists on the backup server, it means that the backup server has already backed up the original disk files of the virtual machine.

[0081] In one possible implementation, when the second disk file serves as the active disk of the virtual machine, it may only depend on the first disk file (i.e., the original disk file) as described in the above embodiment. The second disk file can read read-only data from the first disk file. It can be understood that the mirror dependency structure between the first and second disk files is as follows: base.qcow2 (first disk file / original disk file) <-- active1.qcow2 (second disk file).

[0082] In another possible implementation, when the second disk file acts as the active disk of the virtual machine, it may rely on a read-only snapshot chain. This snapshot chain can consist of the original disk file and other incremental disk files in a read-only state with dependencies. The second disk file can then read read-only data from this read-only snapshot chain as the active disk of the virtual machine. It is understood that in this case, the backup server will contain multiple base backup files corresponding to this read-only snapshot chain, as well as one or more incremental backup files.

[0083] Specifically, if a base backup file exists on the backup server, the host machine creates a third disk file that depends on the second disk file, which is currently the active disk of the virtual machine. For example, if the second disk file depends only on the original disk file, the image dependencies of the disk files in the virtual machine are as follows: base.qcow2 (original disk file / first disk file) <-- active1.qcow2 (second disk file) <-- active2.qcow2 (third disk file).

[0084] Step S404: Change the second disk file from active to read-only, and configure the third disk file as the new active disk for the virtual machine.

[0085] Specifically, after creating a third disk file that depends on the second disk file, the host machine configures the second disk file, which was originally the active disk of the virtual machine, to a read-only state, so that the second disk file and the disk files in the read-only disk that the second disk file originally depended on together constitute the new read-only disk (also called the read-only layer) of the virtual machine; at the same time, the created third disk file is configured as a new active disk that depends on the above-mentioned read-only disk.

[0086] Step S406: Determine the second disk file as the target copy file, and copy the target copy file to the backup server to generate an incremental backup file on the backup server.

[0087] Specifically, the host machine designates the second disk file, which is currently in a read-only state, as the target copy file, copies the target copy file to the backup server, and generates an incremental backup file corresponding to the second disk file on the backup server.

[0088] In one embodiment, after copying the target file to the backup server, the method further includes steps S502 to S504. Wherein:

[0089] Step S502: Merge the second disk file in the virtual machine with the read-only disk file that the second disk file depends on to obtain the fourth disk file.

[0090] For example, taking QEMU virtualization software as an example, the `qemu-img commit` command can be used to merge the second disk file in the virtual machine with the read-only disk file that the second disk file depends on, forming a new dependency relationship. For instance, merging the following image dependency structure `base.qcow2 <-- active1.qcow2 <--active2.qcow2` will result in a new image dependency structure `base.qcow2* <--active2.qcow2`, where `base.qcow2*` is the read-only disk file resulting from the merger of `base.qcow2` and `active1.qcow2`. The `qemu-img commit` command can merge upper-level snapshot data into lower-level images, thereby shortening the snapshot chain, optimizing the disk structure, and improving system performance and data consistency.

[0091] Specifically, the host machine can use a merge command to merge the second disk file in the virtual machine with the read-only disk file that the second disk file depends on, thereby obtaining the corresponding fourth disk file.

[0092] Step S504: Configure the fourth disk file as a new read-only disk for the virtual machine, and configure the third disk file as an active disk for the virtual machine that depends on the fourth disk file.

[0093] Specifically, after the above merging process is completed, the host machine configures the fourth disk file as the new read-only disk of the virtual machine and configures the third disk file as the active disk of the virtual machine that depends on the fourth disk file.

[0094] It is understandable that traditional virtual machine backup schemes, which rely on incremental backup strategies, lead to an ever-lengthening backup chain within the virtual machine. This can easily cause consistency risks and recovery reliability issues, especially when an intermediate node in the backup chain fails, potentially rendering the entire chain unrecoverable and increasing the complexity and uncertainty of data recovery after system failures. However, this application's embodiment utilizes the aforementioned backup merging mechanism to effectively control the length of the incremental snapshot chain, avoiding recovery failures or performance degradation caused by excessively long backup chains within the virtual machine, thereby improving the stability and security of virtual machine backups.

[0095] In one embodiment, such as Figure 7 As shown, the method further includes steps S502 to S508. Wherein:

[0096] Step S502: In response to receiving a disk recovery command and the snapshot type being an external snapshot, obtain the backup file from the backup server.

[0097] Backup files can include basic backup files and incremental backup files.

[0098] Specifically, in response to receiving a disk recovery command from the user, the host machine copies the corresponding backup file from the backup server back to the host machine, provided that the snapshot type corresponding to the current virtual machine software is an external snapshot.

[0099] Step S504: If the backup file only includes the basic backup file, then determine that the basic backup file is the basic disk file.

[0100] The base disk file can be used as the file basis for the host to create new virtual machines.

[0101] Specifically, when it is determined that the backup file copied back to the host machine only includes the base backup file, the host machine specifies that the base backup file is the base disk file.

[0102] Step S506: If the backup file includes a basic backup file and an incremental backup file, then the basic backup file and the incremental backup file are merged to obtain a basic disk file.

[0103] Specifically, when it is determined that the backup files currently copied back to the host machine include a base backup file and one or more incremental backup files, the host machine will merge the aforementioned backup files and one or more incremental backup files, and designate the merged disk file as the base disk file.

[0104] Step S508: Create a new virtual machine based on the base disk file.

[0105] The new virtual machine can specify its base disk file as its original disk file.

[0106] Specifically, based on the base disk file obtained in the above steps, the host machine can create a new virtual machine that specifies the base disk file as its original disk file, thereby realizing the virtual machine recovery function.

[0107] For example, taking QEMU as the virtualization software, and the backup files on the backup server including basic backup files and incremental backup files, an exemplary virtual machine recovery process is as follows:

[0108] First, the host machine copies the base backup file `base.qcow2` and the incremental backup file `active.qcow2` from the backup server back to the host machine. Second, the `qemu-img rebase` command is used to specify the backing file of the incremental backup file `active.qcow2` as the base backup file `base.qcow2`. Then, the `qemu-imgcommit` command is used to merge the contents of the incremental backup file `active.qcow2` into the base backup file `base.qcow2`. Next, the incremental backup file `active.qcow2` copied back to the host machine is deleted, leaving only the merged base backup file `base.qcow2`, which becomes the required base disk file. Then, the virtual machine XML configuration file is set so that the disk device of the new virtual machine points to this base disk file. Finally, the host machine creates a new virtual machine based on the virtual machine XML configuration file and cleans up temporary resources generated during the recovery process to complete the virtual machine recovery process. Optionally, the above backup files may include one or more incremental backup files; this embodiment does not specifically limit the number of incremental backup files.

[0109] In one embodiment, such as Figure 8 As shown, based on the snapshot type, the target copy file matching the snapshot type is copied to the backup server to generate a backup file on the backup server, including the following steps S602 to S604. Wherein:

[0110] Step S602: If the snapshot type is an internal snapshot, then instruct the current virtual machine disk file to generate an internal snapshot point.

[0111] It is understandable that some virtualization software (such as older versions of QEMU) does not support external snapshot mechanisms and can only use internal snapshot solutions.

[0112] Specifically, when the snapshot type corresponding to the current virtualization software is an internal snapshot, the host machine instructs the virtual machine to create an internal snapshot point for the current virtual machine disk file.

[0113] Step S604: Determine the complete virtual machine disk file of the current virtual machine as the target copy file, copy the target copy file to the backup server, and roll back the virtual machine disk file to the internal snapshot point.

[0114] Specifically, after creating the internal snapshot point, the host machine specifies the complete virtual machine disk file of the current virtual machine as the target copy file and copies this target copy file to the backup server. At this time, the backup file generated on the backup server includes the complete virtual machine disk file corresponding to the aforementioned internal snapshot point. Then, the host machine rolls back the current virtual machine disk file of the virtual machine to the aforementioned internal snapshot point to ensure backup consistency.

[0115] For example, taking a low-version (version number < 2.0) QEMU virtualization software on the host machine as an example, the host machine can create an internal snapshot point snap1 for the current virtual machine disk file using the `virsh snapshot-create` command. Then, the current virtual machine disk file vm.qcow2 is completely copied to the backup server, and the virtual machine disk file vm.qcow2 in the virtual machine is rolled back to snapshot point snap1 using the `virsh snapshot-revert` command to ensure backup consistency. This embodiment of the application achieves complete coverage of the backup function in a low-version QEMU environment, thereby avoiding the problem of incompatibility with external snapshots and effectively improving the compatibility of the backup function.

[0116] In one embodiment, the method further includes steps S702 to S704. Wherein:

[0117] Step S702: In response to receiving a disk recovery command and the snapshot type being internal snapshot, obtain the backup file of the specified internal snapshot point from the backup server.

[0118] Specifically, in response to receiving a disk recovery command from the user, if the snapshot type corresponding to the current virtualization software is an internal snapshot, the host machine copies the backup file of the specified internal snapshot point back to the host machine from the backup server.

[0119] Step S704: Create a new virtual machine based on the backup file.

[0120] Specifically, the host machine sets the virtual machine XML configuration file to point the disk device to the backup file of the specified internal snapshot point. Then, based on the virtual machine XML configuration file and the backup file, a new virtual machine is created, and temporary resources generated during the recovery process are cleaned up, thereby completing the virtual machine recovery process.

[0121] The virtual machine backup methods described in the above embodiments have at least the following beneficial technical effects:

[0122] 1. Improve system compatibility and adaptability: By automatically identifying the snapshot type corresponding to the virtual machine software and dynamically selecting external or internal snapshot methods, the compatibility issues caused by differences in snapshot mechanisms are resolved, ensuring the consistent operation of the backup function in various cloud environments.

[0123] 2. Reduce backup chain risks and enhance data reliability: External snapshots combined with the commit merging mechanism effectively control the length of incremental snapshot chains, avoid recovery failures or performance degradation caused by excessively long backup chains, and improve the stability and security of backups.

[0124] 3. Enhance the availability of older QEMU versions: By adopting an internal snapshot + full disk copy + snapshot rollback approach, earlier versions of QEMU can still achieve highly complete virtual machine backup and recovery even without external snapshot support, thus extending the system's lifespan and compatibility.

[0125] 4. Supports continuous incremental backups, saving storage resources: For higher versions of QEMU, the system can continuously generate incremental snapshots, copying only changed data, effectively reducing storage overhead and improving backup efficiency.

[0126] In summary, the virtual machine backup method provided in this application, which is highly compatible, loosely coupled, adaptable to older QEMU versions, and stable and maintainable for KVM virtual machines, has significant technical value and practical significance for ensuring the data security of virtual machines in cloud environments and improving the availability of cloud platforms.

[0127] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.

[0128] Based on the same inventive concept, this application also provides a virtual machine backup apparatus for implementing the virtual machine backup method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more virtual machine backup apparatus embodiments provided below can be found in the limitations of the virtual machine backup method described above, and will not be repeated here.

[0129] In one exemplary embodiment, such as Figure 9 As shown, this application provides a virtual machine disk backup and restore device 900, the device 900 including:

[0130] The snapshot type acquisition module 902 is used to acquire the snapshot type of the virtualization software;

[0131] Backup module 904 is used to copy target copy files matching the snapshot type to the backup server, so as to generate backup files on the backup server;

[0132] Specifically, when the snapshot type is an external snapshot, the target copy file is determined based on the original disk file or the read-only disk file of the virtual machine; when the snapshot type is an internal snapshot, the target copy file is the complete virtual machine disk file.

[0133] In one embodiment, the backup file includes a base backup file; the backup module 904 is further configured to:

[0134] If the snapshot type is an external snapshot and it is determined that there is no base backup file in the current backup server, then the first disk file of the virtual machine is determined to be the target copy file; the first disk file is the original disk file of the virtual machine configured as a read-only disk.

[0135] Copy the target file to the backup server to generate the base backup file on the backup server.

[0136] In one embodiment, the backup file further includes an incremental backup file; the device 900 also includes:

[0137] The third disk file creation module is used to create a third disk file that depends on the second disk file, which is currently the active disk of the virtual machine, if the snapshot type is an external snapshot and it is determined that there is a base backup file in the current backup server.

[0138] The first state transition module is used to change the second disk file from an active state to a read-only state, and to configure the third disk file as the new active disk of the virtual machine;

[0139] The first copy module is used to determine the second disk file as the target copy file and copy the target copy file to the backup server to generate an incremental backup file on the backup server.

[0140] In one embodiment, the device 900 further includes:

[0141] The first merging module is used to merge the second disk file in the virtual machine with the read-only disk file that the second disk file depends on, to obtain the fourth disk file;

[0142] The second state transition module is used to configure the fourth disk file as a new read-only disk for the virtual machine and to configure the third disk file as an active disk for the virtual machine that depends on the fourth disk file.

[0143] In one embodiment, the device 900 further includes:

[0144] The first backup file acquisition module is used to acquire backup files from the backup server in response to receiving a disk recovery command and the snapshot type is external snapshot;

[0145] The base disk file determination module is used to determine the base backup file as the base disk file if the backup file only includes the base backup file.

[0146] The second merging module is used to merge the basic backup file and the incremental backup file if the backup file includes a basic backup file and an incremental backup file, to obtain a basic disk file.

[0147] The first virtual machine generation module is used to create new virtual machines based on the base disk file.

[0148] In one embodiment, the backup module 904 is further configured to:

[0149] If the snapshot type is internal snapshot, it indicates that an internal snapshot point will be generated for the current virtual machine disk file;

[0150] The target copy file is the complete virtual machine disk file of the current virtual machine. The target copy file is copied to the backup server, and the virtual machine disk file is rolled back to the internal snapshot point.

[0151] In one embodiment, the device 900 further includes:

[0152] The second backup file acquisition module is used to acquire the backup file of the specified internal snapshot point from the backup server in response to receiving a disk recovery command and the snapshot type is internal snapshot;

[0153] The second virtual machine generation module is used to create new virtual machines based on backup files.

[0154] The modules in the aforementioned virtual machine backup device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0155] In one exemplary embodiment, a computer device is provided, which may be a host machine, and its internal structure diagram may be as follows: Figure 10 As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with an external host machine; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When the computer program is executed by the processor, it implements a virtual machine backup method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.

[0156] Those skilled in the art will understand that Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0157] In one exemplary embodiment, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:

[0158] Step A: Obtain the snapshot type of the virtualization software;

[0159] Step B: Based on the snapshot type, copy the target copy file that matches the snapshot type to the backup server to generate a backup file on the backup server;

[0160] Specifically, when the snapshot type is an external snapshot, the target copy file is determined based on the original disk file or the read-only disk file of the virtual machine; when the snapshot type is an internal snapshot, the target copy file is the complete virtual machine disk file.

[0161] In one embodiment, the processor further performs the following steps when executing the computer program:

[0162] If the snapshot type is an external snapshot and it is determined that there is no base backup file in the current backup server, then the first disk file of the virtual machine is determined as the target copy file; the first disk file is the original disk file of the read-only disk configured as the virtual machine; the target copy file is copied to the backup server to generate the base backup file in the backup server.

[0163] In one embodiment, the processor further performs the following steps when executing the computer program:

[0164] If the snapshot type is an external snapshot and it is determined that a base backup file exists in the current backup server, then based on the second disk file which is currently the active disk of the virtual machine, a third disk file that depends on the second disk file is created; the second disk file is changed from an active state to a read-only state, and the third disk file is configured as the new active disk of the virtual machine; the second disk file is determined as the target copy file, and the target copy file is copied to the backup server to generate an incremental backup file in the backup server.

[0165] In one embodiment, the processor further performs the following steps when executing the computer program:

[0166] The second disk file in the virtual machine is merged with the read-only disk file that the second disk file depends on to obtain the fourth disk file; the fourth disk file is configured as the new read-only disk of the virtual machine, and the third disk file is configured as the active disk of the virtual machine that depends on the fourth disk file.

[0167] In one embodiment, the processor further performs the following steps when executing the computer program:

[0168] In response to receiving a disk recovery command and the snapshot type being external snapshot, the system retrieves backup files from the backup server. If the backup files only include a basic backup file, the system determines that the basic backup file is the basic disk file. If the backup files include both a basic backup file and an incremental backup file, the system merges the basic backup file and the incremental backup file to obtain the basic disk file.

[0169] Create a new virtual machine based on the base disk file.

[0170] In one embodiment, the processor further performs the following steps when executing the computer program:

[0171] If the snapshot type is internal snapshot, then instruct the current virtual machine disk file to generate an internal snapshot point; determine the complete virtual machine disk file of the current virtual machine as the target copy file, copy the target copy file to the backup server, and roll back the virtual machine disk file to the internal snapshot point.

[0172] In one embodiment, the processor further performs the following steps when executing the computer program:

[0173] In response to receiving a disk recovery command and the snapshot type is internal snapshot, retrieve the backup file of the specified internal snapshot point from the backup server; based on the backup file, create a new virtual machine.

[0174] In one embodiment, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the above-described method embodiments.

[0175] In one embodiment, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps in the above-described method embodiments.

[0176] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.

[0177] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0178] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A virtual machine backup method, characterized in that, The method includes: Obtain the snapshot type of the virtualization software; the snapshot type is determined based on the version number of the virtualization software; when the version number represents a higher version, the snapshot type of the virtualization software is an external snapshot, and when the version number represents a lower version, the snapshot type of the virtualization software is an internal snapshot; According to the snapshot type, the target copy file matching the snapshot type is copied to the backup server to generate a backup file in the backup server; Wherein, when the snapshot type is an external snapshot, the target copy file is determined based on the original disk file or read-only disk file of the virtual machine; when the snapshot type is an internal snapshot, the target copy file is the complete virtual machine disk file of the virtual machine.

2. The virtual machine backup method according to claim 1, characterized in that, The backup file includes a base backup file; the step of copying a target copy file matching the snapshot type to the backup server to generate a backup file on the backup server includes: If the snapshot type is an external snapshot and it is determined that the base backup file does not exist in the current backup server, then the first disk file of the virtual machine is determined to be the target copy file; the first disk file is the original disk file configured as a read-only disk of the virtual machine. The target copy file is copied to the backup server to generate the base backup file on the backup server.

3. The virtual machine backup method according to claim 2, characterized in that, The backup file also includes an incremental backup file; the method further includes: If the snapshot type is the external snapshot, and it is determined that the basic backup file exists in the current backup server, then a third disk file dependent on the second disk file, which is currently the active disk of the virtual machine, is created. Change the second disk file from an active state to a read-only state, and configure the third disk file as the new active disk of the virtual machine; The second disk file is identified as the target copy file, and the target copy file is copied to the backup server to generate the incremental backup file on the backup server.

4. The virtual machine backup method according to claim 3, characterized in that, After copying the target file to the backup server, the process further includes: The second disk file in the virtual machine is merged with the read-only disk file that the second disk file depends on to obtain the fourth disk file; Configure the fourth disk file as a new read-only disk for the virtual machine, and configure the third disk file as an active disk for the virtual machine that depends on the fourth disk file.

5. The virtual machine backup method according to claim 3, characterized in that, The method further includes: In response to receiving a disk recovery command, and the snapshot type being the external snapshot, the backup file is retrieved from the backup server; If the backup file only includes the base backup file, then the base backup file is determined to be the base disk file; If the backup file includes the basic backup file and the incremental backup file, then the basic backup file and the incremental backup file are merged to obtain the basic disk file; A second virtual machine is created based on the aforementioned base disk file.

6. The virtual machine backup method according to claim 1, characterized in that, The step of copying the target copy file matching the snapshot type to the backup server to generate a backup file on the backup server includes: If the snapshot type is an internal snapshot, then instruct the current virtual machine disk file to generate an internal snapshot point; The complete virtual machine disk file of the current virtual machine is identified as the target copy file. The target copy file is copied to the backup server, and the virtual machine disk file is rolled back to the internal snapshot point.

7. The virtual machine backup method according to claim 1, characterized in that, The method further includes: In response to receiving a disk recovery instruction and the snapshot type being the internal snapshot, the backup file for the specified internal snapshot point is retrieved from the backup server; Based on the backup file, a third virtual machine is created.

8. A virtual machine disk backup and restore device, characterized in that, The device includes: A snapshot type acquisition module is used to acquire the snapshot type of the virtualization software; the snapshot type is determined based on the version number of the virtualization software; when the version number represents a higher version, the snapshot type corresponding to the virtualization software is an external snapshot, and when the version number represents a lower version, the snapshot type corresponding to the virtualization software is an internal snapshot. The backup module is used to copy a target copy file matching the snapshot type to the backup server according to the snapshot type, so as to generate a backup file in the backup server; Wherein, when the snapshot type is an external snapshot, the target copy file is determined based on the original disk file or read-only disk file of the virtual machine; when the snapshot type is an internal snapshot, the target copy file is the complete virtual machine disk file of the virtual machine.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.