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¶
-
Create a namespace for the test:
-
Go to Virtualization -> VirtualMachines -> ensure you are in the
vm-backup-testproject -> click "Create VirtualMachine" - Select "From template" and choose "Red Hat Enterprise Linux 9"
- Name the VM
backup-test-vm - Click "Customize VirtualMachine"
Add a Data Disk¶
- Click on the "Disks" tab
- Click "Add disk"
- Configure the data disk:
- Name:
data-disk- Source: Blank - Size: 5 GiB - Type: Disk - StorageClass: your default StorageClass - Access Mode: ReadWriteMany (RWX) - Click Add
Start the VM¶
- Click "Create VirtualMachine"
- Wait for the VM status to show "Running"
Write Test Data¶
- Open the VM console from the WebUI:
- Virtualization -> VirtualMachines -> click
backup-test-vm-> Console tab - Login to the guest OS (default credentials from the template)
-
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.txtYou should see:
OADP backup test - original data -
Confirm the data is written:
Take a Backup¶
-
Create a Backup CR to capture the running VM and its disks:
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.
-
Apply the backup:
-
Watch the backup progress:
Wait for the
PHASEto showCompleted. -
Verify the backup contents:
Make a Destructive Change¶
-
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.txtYou should see:
THIS DATA HAS BEEN MODIFIED -
Stop the VM:
Delete the VM¶
-
Delete the VM and its PVCs to simulate a disaster:
-
Confirm the VM is gone:
Should return
NotFound.
Restore from Backup¶
-
Create a Restore CR pointing to the backup:
-
Watch the restore progress:
Wait for the
PHASEto showCompleted.
Verify the Restore¶
-
Confirm the VM exists again:
-
Start the restored VM:
Wait for it to be running:
-
Open the VM console and verify the original data is restored:
You should see: -
testfile.txtcontains:OADP backup test - original data(the original content) -extra.txtdoes 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¶
-
Delete the test resources: