Chapter 22. 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.

22.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. Back up the disks of the VM. To do so, use the virsh backup-begin utility.
  3. 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.

  4. Start the VM.

    # virsh start <vm-name>
    Copy to Clipboard Toggle word wrap
  5. 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

22.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
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2026 Red Hat
トップに戻る