이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 21. Backing up and recovering virtual machines


To ensure that you do not lose the setup and data of a virtual machine (VM) if your current host becomes unavailable or non-functional, back up the configuration and storage of the VM. Afterwards, for disaster recovery, you can create a new VM that uses the backed up configuration and storage.

Note

If you plan to create a backup to recover a VM while the host remains functional, it might be more efficient to use snapshots instead.

21.1. Backing up a virtual machine

To ensure that you do not lose the setup and data of a virtual machine (VM) if your current host becomes unavailable or non-functional, back up the configuration and disks of the VM. This allows you to later recover the backup on a functional host.

Procedure

  1. Save the XML configuration of the VM to a separate file. For example, to save the configration of the testguest1 VM to the /home/backup/testguest1-backup.xml file, use the following command:

    # virsh dumpxml testguest1 > /home/backup/testguest1-backup.xml
  2. Optional: Customize your backup settings. By default, libvirt creates copies of all disks in the VM in the same directory as the original disks. If you want to use a different configuration for your backup, create an XML file with your required settings. For example:

    <domainbackup>
      <disks>
        <disk name='vda' backup='yes'/>
        <disk name='vdb' type='file'>
          <target file='/home/backup/vdb.backup'/>
          <driver type='raw'/>
        </disk>
        <disk name='vdc' backup='no'/>
      </disks>
    </domainbackup>

    This example configuration ensures that the vda disk is backed up by using the libvirt defaults, the vdb disk is backed up in the raw format as /home/backup/vdb.backup, and that the vdc disk is not backed up.

  3. Start the VM.

    # virsh start <vm-name>
  4. Back up the disks of the VM by using the virsh backup-begin utility. The following command uses the default backup settings, which creates copies of all disks that the VM uses, and saves them in the same directory as the original disks

    # virsh backup-begin <vm-name>

    Optionally, to apply custom backup settings, you can specify the backup XML configuration that you created previously.

    # virsh backup-begin <vm-name> --backupxml <backup-XML-location>

Verification

  1. Ensure that the backup operation has completed.

    # virsh domjobinfo <vm-name> --completed

    Example successful output:

    Job type:         Completed
    Operation:        Backup
    Time elapsed:     20704 ms
    File processed:   40.000 GiB
    File remaining:   0.000 B
    File total:       40.000 GiB
  2. Check the target location of the backup disks. For example, if you used the default backup configuration and the VM disks are located in the default /var/lib/libvirt/images/ directory, use the following command:

    # ls -l /var/lib/libvirt/images

    Example successful output:

    -rw-------. 1 qemu qemu 42956488704 Oct 10 15:49 RHEL_10_beta.qcow2
    -rw-------. 1 root root 42956488704 Oct 29 16:12 RHEL_10_beta.qcow.21761750144
    -rw-------. 1 qemu qemu      196688 Oct 10 15:49 extra-storage.qcow2
    -rw-------. 1 root root 196688 Oct 29 16:12 extra-storage.qcow2.1761750144

21.2. Recovering a virtual machine

For disaster recovery of your virtual machines (VMs), you can create a new VM that uses the XML configuration and storage that you previously backed up.

Prerequisites

Procedure

  1. Inspect the backup XML configuration of the VM for the specific storage settings.

    # cat </path/to/backup.xml>

    Example output section:

    <disk type='file' device='disk'>
          <driver name='qemu' type='qcow2' discard='unmap'/>
          <source file='/var/lib/libvirt/images/vm-name.qcow2' index='3'/>
  2. Move the backup disks to the locations specified in the backup XML and ensure that their names correspond with the values in the XML.
  3. Define a new VM based on the backup XML.

    # virsh define --file </path/to/backup.xml>
  4. Optional: Modify the XML configuration of the newly created VM to adjust for settings that might be different from the original host, such as the network.

    # virsh edit <vm-name>

Verification

  • Start the VM and check that the guest operating system has been recovered correctly.

    # virsh start <vm-name>
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2026 Red Hat
맨 위로 이동