Skip to content

VM Backup and Restore

This guide demonstrates using OADP to back up a virtual machine, make a destructive change, and then restore the VM to its previous state. This assumes OADP is installed and configured with the kubevirt plugin and a valid BackupStorageLocation.

Prerequisites

  • OADP operator installed with BackupStorageLocation showing Available
  • OpenShift Virtualization installed
  • RWX-capable StorageClass available

Create a Test Virtual Machine

  1. Create a namespace for the test:

    oc new-project vm-backup-test
    
  2. Go to Virtualization -> VirtualMachines -> ensure you are in the vm-backup-test project -> click "Create VirtualMachine"

  3. Select "From template" and choose "Red Hat Enterprise Linux 9"
  4. Name the VM backup-test-vm
  5. Click "Customize VirtualMachine"

Add a Data Disk

  1. Click on the "Disks" tab
  2. Click "Add disk"
  3. Configure the data disk: - Name: data-disk - Source: Blank - Size: 5 GiB - Type: Disk - StorageClass: your default StorageClass - Access Mode: ReadWriteMany (RWX)
  4. Click Add

Start the VM

  1. Click "Create VirtualMachine"
  2. Wait for the VM status to show "Running"

Write Test Data

  1. Open the VM console from the WebUI: - Virtualization -> VirtualMachines -> click backup-test-vm -> Console tab
  2. Login to the guest OS (default credentials from the template)
  3. Format and mount the data disk, then write test data:

    sudo mkfs.xfs /dev/vdb
    sudo mkdir -p /mnt/data
    sudo mount /dev/vdb /mnt/data
    echo "OADP backup test - original data" | sudo tee /mnt/data/testfile.txt
    cat /mnt/data/testfile.txt
    

    You should see: OADP backup test - original data

  4. Confirm the data is written:

    ls -la /mnt/data/
    

Take a Backup

  1. Create a Backup CR to capture the running VM and its disks:

    apiVersion: velero.io/v1
    kind: Backup
    metadata:
      name: backup-test-vm-backup-1
      namespace: openshift-adp
    spec:
      includedNamespaces:
        - vm-backup-test
      storageLocation: dpa-1
      ttl: 720h0m0s
    

Note

This backs up all resources in the vm-backup-test namespace. Namespace-scoped backup ensures the VirtualMachine, its DataVolumes, PVCs, and associated secrets are all captured together.

Crash-Consistent Backups

OADP with the kubevirt and csi plugins can back up running VMs using CSI volume snapshots. The resulting backup is crash-consistent — equivalent to an unexpected power loss. This is sufficient for most workloads. If you need application-consistent backups (e.g., databases), either stop the VM first or use the QEMU guest agent for filesystem freeze/thaw.

  1. Apply the backup:

    oc apply -f backup.yaml
    
  2. Watch the backup progress:

    oc get backup backup-test-vm-backup-1 -n openshift-adp -w
    

    Wait for the PHASE to show Completed.

  3. Verify the backup contents:

    oc get backup backup-test-vm-backup-1 -n openshift-adp -o jsonpath='{.status.phase}'
    

Make a Destructive Change

  1. Open the VM console and modify the data:

    sudo mount /dev/vdb /mnt/data
    echo "THIS DATA HAS BEEN MODIFIED" | sudo tee /mnt/data/testfile.txt
    echo "extra-file-that-shouldnt-exist" | sudo tee /mnt/data/extra.txt
    cat /mnt/data/testfile.txt
    

    You should see: THIS DATA HAS BEEN MODIFIED

  2. Stop the VM:

    virtctl stop backup-test-vm -n vm-backup-test
    

Delete the VM

  1. Delete the VM and its PVCs to simulate a disaster:

    oc delete vm backup-test-vm -n vm-backup-test
    oc delete pvc -l app=backup-test-vm -n vm-backup-test
    
  2. Confirm the VM is gone:

    oc get vm backup-test-vm -n vm-backup-test
    

    Should return NotFound.

Restore from Backup

  1. Create a Restore CR pointing to the backup:

    apiVersion: velero.io/v1
    kind: Restore
    metadata:
      name: backup-test-vm-restore-1
      namespace: openshift-adp
    spec:
      backupName: backup-test-vm-backup-1
      includedNamespaces:
        - vm-backup-test
      restorePVs: true
    
    oc apply -f restore.yaml
    
  2. Watch the restore progress:

    oc get restore backup-test-vm-restore-1 -n openshift-adp -w
    

    Wait for the PHASE to show Completed.

Verify the Restore

  1. Confirm the VM exists again:

    oc get vm backup-test-vm -n vm-backup-test
    
  2. Start the restored VM:

    virtctl start backup-test-vm -n vm-backup-test
    

    Wait for it to be running:

    oc get vmi backup-test-vm -n vm-backup-test -w
    
  3. Open the VM console and verify the original data is restored:

    sudo mount /dev/vdb /mnt/data
    cat /mnt/data/testfile.txt
    ls /mnt/data/
    

    You should see: - testfile.txt contains: OADP backup test - original data (the original content) - extra.txt does not exist (the modification is gone)

    The VM has been fully restored to the state captured in the backup.

Summary

Step What Happened
Create VM RHEL 9 VM with a data disk, test data written
Backup OADP captured the VM definition, disks, and PVC data
Destructive change Modified data and added files to prove the change
Delete VM Simulated a disaster by removing the VM entirely
Restore OADP recreated the VM and restored disk contents
Verify Original data is back, modifications are gone

Cleanup

  1. Delete the test resources:

    oc delete vm backup-test-vm -n vm-backup-test
    oc delete pvc -l app=backup-test-vm -n vm-backup-test
    oc delete backup backup-test-vm-backup-1 -n openshift-adp
    oc delete restore backup-test-vm-restore-1 -n openshift-adp
    oc delete project vm-backup-test