Este conteúdo não está disponível no idioma selecionado.

Chapter 24. 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. For details, see Saving and restoring virtual machine state by using snapshots.

24.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
    Copy to Clipboard Toggle word wrap
  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>
    Copy to Clipboard Toggle word wrap

    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>
    Copy to Clipboard Toggle word wrap
  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>
    Copy to Clipboard Toggle word wrap

    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>
    Copy to Clipboard Toggle word wrap

Verification

  1. Ensure that the backup operation has completed.

    # virsh domjobinfo <vm-name> --completed
    Copy to Clipboard Toggle word wrap

    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
    Copy to Clipboard Toggle word wrap
  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
    Copy to Clipboard Toggle word wrap

    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
    Copy to Clipboard Toggle word wrap

24.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>
    Copy to Clipboard Toggle word wrap

    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'/>
    Copy to Clipboard Toggle word wrap
  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>
    Copy to Clipboard Toggle word wrap
  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>
    Copy to Clipboard Toggle word wrap

Verification

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

    # virsh start <vm-name>
    Copy to Clipboard Toggle word wrap
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2026 Red Hat