apiVersion: snapshot.kubevirt.io/v1alpha1
kind: VirtualMachineSnapshot
metadata:
name: my-vmsnapshot (1)
spec:
source:
apiGroup: kubevirt.io
kind: VirtualMachine
name: my-vm (2)
You can create, restore, and delete virtual machine (VM) snapshots for VMs that are powered off (offline). OpenShift Virtualization supports offline VM snapshots on:
Red Hat OpenShift Container Storage
Any other storage provider with the Container Storage Interface (CSI) driver that supports the Kubernetes Volume Snapshot API
A snapshot represents the state and data of a virtual machine (VM) at a specific point in time. You can use a snapshot to restore an existing VM to a previous state (represented by the snapshot) for backup and disaster recovery or to rapidly roll back to a previous development version.
An offline VM snapshot is created from a VM that is powered off (Stopped state). The snapshot stores a copy of each Container Storage Interface (CSI) volume attached to the VM and a copy of the VM specification and metadata. Snapshots cannot be changed after creation.
With the offline VM snapshots feature, cluster administrators and application developers can:
Create a new snapshot
List all snapshots attached to a specific VM
Restore a VM from a snapshot
Delete an existing VM snapshot
The VM snapshot feature introduces three new API objects defined as CRDs for managing snapshots:
VirtualMachineSnapshot
: Represents a user request to create a snapshot. It contains information about the current state of the VM.
VirtualMachineSnapshotContent
: Represents a provisioned resource on the cluster (a snapshot). It is created by the VM snapshot controller and contains references to all resources required to restore the VM.
VirtualMachineRestore
: Represents a user request to restore a VM from a snapshot.
The VM snapshot controller binds a VirtualMachineSnapshotContent
object with the VirtualMachineSnapshot
object for which it was created, with a one-to-one mapping.
You can create a virtual machine (VM) snapshot by using the web console.
The VM snapshot only includes disks that meet the following requirements:
If your VM storage includes disks that do not support snapshots, you can either edit them or contact your cluster administrator. |
Click Workloads → Virtualization from the side menu.
Click the Virtual Machines tab.
Select a virtual machine to open the Virtual Machine Overview screen.
If the virtual machine is running, click Actions → Stop Virtual Machine to power it down.
Click the Snapshots tab and then click Take Snapshot.
Fill in the Snapshot Name and optional Description fields.
Expand Disks included in this Snapshot to see the storage volumes to be included in the snapshot.
If your VM has disks that cannot be included in the snapshot and you still wish to proceed, select the I am aware of this warning and wish to proceed checkbox.
Click Save.
You can create a virtual machine (VM) snapshot for an offline VM by creating a VirtualMachineSnapshot
object.
Ensure that the persistent volume claims (PVCs) are in a storage class that supports Container Storage Interface (CSI) volume snapshots.
Install the OpenShift CLI (oc
).
Power down the VM for which you want to create a snapshot.
Create a YAML file to define a VirtualMachineSnapshot
object that specifies the name of the new VirtualMachineSnapshot
and the name of the source VM.
For example:
apiVersion: snapshot.kubevirt.io/v1alpha1
kind: VirtualMachineSnapshot
metadata:
name: my-vmsnapshot (1)
spec:
source:
apiGroup: kubevirt.io
kind: VirtualMachine
name: my-vm (2)
1 | The name of the new VirtualMachineSnapshot object. |
2 | The name of the source VM. |
Create the VirtualMachineSnapshot
resource. The snapshot controller creates a VirtualMachineSnapshotContent
object, binds it to the VirtualMachineSnapshot
and updates the status
and readyToUse
fields
of the VirtualMachineSnapshot
object.
$ oc create -f <my-vmsnapshot>.yaml
Verify that the VirtualMachineSnapshot
object is created and bound with VirtualMachineSnapshotContent
. The readyToUse
flag must be set to true
.
$ oc describe vmsnapshot <my-vmsnapshot>
apiVersion: snapshot.kubevirt.io/v1alpha1
kind: VirtualMachineSnapshot
metadata:
creationTimestamp: "2020-09-30T14:41:51Z"
finalizers:
- snapshot.kubevirt.io/vmsnapshot-protection
generation: 5
name: mysnap
namespace: default
resourceVersion: "3897"
selfLink: /apis/snapshot.kubevirt.io/v1alpha1/namespaces/default/virtualmachinesnapshots/my-vmsnapshot
uid: 28eedf08-5d6a-42c1-969c-2eda58e2a78d
spec:
source:
apiGroup: kubevirt.io
kind: VirtualMachine
name: my-vm
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2020-09-30T14:42:03Z"
reason: Operation complete
status: "False" (1)
type: Progressing
- lastProbeTime: null
lastTransitionTime: "2020-09-30T14:42:03Z"
reason: Operation complete
status: "True" (2)
type: Ready
creationTime: "2020-09-30T14:42:03Z"
readyToUse: true (3)
sourceUID: 355897f3-73a0-4ec4-83d3-3c2df9486f4f
virtualMachineSnapshotContentName: vmsnapshot-content-28eedf08-5d6a-42c1-969c-2eda58e2a78d (4)
1 | The status field of the Progressing condition specifies if the snapshot is still being created. |
2 | The status field of the Ready condition specifies if the snapshot creation process is complete. |
3 | Specifies if the snapshot is ready to be used. |
4 | Specifies that the snapshot is bound to a VirtualMachineSnapshotContent object created by the snapshot controller. |
Check the spec:volumeBackups
property of the VirtualMachineSnapshotContent
resource to verify that the expected PVCs are included in the snapshot.
You can restore a virtual machine (VM) to a previous configuration represented by a snapshot in the web console.
Click Workloads → Virtualization from the side menu.
Click the Virtual Machines tab.
Select a virtual machine to open the Virtual Machine Overview screen.
If the virtual machine is running, click Actions → Stop Virtual Machine to power it down.
Click the Snapshots tab. The page displays a list of snapshots associated with the virtual machine.
Choose one of the following methods to restore a VM snapshot:
For the snapshot that you want to use as the source to restore the VM, click Restore.
Select a snapshot to open the Snapshot Details screen and click Actions → Restore Virtual Machine Snapshot.
In the confirmation pop-up window, click Restore to restore the VM to its previous configuration represented by the snapshot.
You can restore an existing virtual machine (VM) to a previous configuration by using a VM snapshot .
Install the OpenShift CLI (oc
).
Power down the VM you want to restore to a previous state.
Create a YAML file to define a VirtualMachineRestore
object that specifies the name of the VM you want to restore and the name of the snapshot to be used as the source.
For example:
apiVersion: snapshot.kubevirt.io/v1alpha1
kind: VirtualMachineRestore
metadata:
name: my-vmrestore (1)
spec:
target:
apiGroup: kubevirt.io
kind: VirtualMachine
name: my-vm (2)
virtualMachineSnapshotName: my-vmsnapshot (3)
1 | The name of the new VirtualMachineRestore object. |
2 | The name of the target VM you want to restore. |
3 | The name of the VirtualMachineSnapshot object to be used as the source. |
Create the VirtualMachineRestore
resource. The snapshot controller updates the status fields of the VirtualMachineRestore
object and replaces the existing VM configuration with the snapshot content.
$ oc create -f <my-vmrestore>.yaml
Verify that the VM is restored to the previous state represented by the snapshot. The complete
flag must be set to true
.
$ oc get vmrestore <my-vmrestore>
apiVersion: snapshot.kubevirt.io/v1alpha1
kind: VirtualMachineRestore
metadata:
creationTimestamp: "2020-09-30T14:46:27Z"
generation: 5
name: my-vmrestore
namespace: default
ownerReferences:
- apiVersion: kubevirt.io/v1alpha3
blockOwnerDeletion: true
controller: true
kind: VirtualMachine
name: my-vm
uid: 355897f3-73a0-4ec4-83d3-3c2df9486f4f
resourceVersion: "5512"
selfLink: /apis/snapshot.kubevirt.io/v1alpha1/namespaces/default/virtualmachinerestores/my-vmrestore
uid: 71c679a8-136e-46b0-b9b5-f57175a6a041
spec:
target:
apiGroup: kubevirt.io
kind: VirtualMachine
name: my-vm
virtualMachineSnapshotName: my-vmsnapshot
status:
complete: true (1)
conditions:
- lastProbeTime: null
lastTransitionTime: "2020-09-30T14:46:28Z"
reason: Operation complete
status: "False" (2)
type: Progressing
- lastProbeTime: null
lastTransitionTime: "2020-09-30T14:46:28Z"
reason: Operation complete
status: "True" (3)
type: Ready
deletedDataVolumes:
- test-dv1
restoreTime: "2020-09-30T14:46:28Z"
restores:
- dataVolumeName: restore-71c679a8-136e-46b0-b9b5-f57175a6a041-datavolumedisk1
persistentVolumeClaim: restore-71c679a8-136e-46b0-b9b5-f57175a6a041-datavolumedisk1
volumeName: datavolumedisk1
volumeSnapshotName: vmsnapshot-28eedf08-5d6a-42c1-969c-2eda58e2a78d-volume-datavolumedisk1
1 | Specifies if the process of restoring the VM to the state represented by the snapshot is complete. |
2 | The status field of the Progressing condition specifies if the VM is still being restored. |
3 | The status field of the Ready condition specifies if the VM restoration process is complete. |
You can delete an existing virtual machine snapshot by using the web console.
Click Workloads → Virtualization from the side menu.
Click the Virtual Machines tab.
Select a virtual machine to open the Virtual Machine Overview screen.
Click the Snapshots tab. The page displays a list of snapshots associated with the virtual machine.
Choose one of the following methods to delete a virtual machine snapshot:
Click the Options menu of the virtual machine snapshot that you want to delete and select Delete Virtual Machine Snapshot.
Select a snapshot to open the Snapshot Details screen and click Actions → Delete Virtual Machine Snapshot.
In the confirmation pop-up window, click Delete to delete the snapshot.
You can delete an existing virtual machine (VM) snapshot by deleting the appropriate VirtualMachineSnapshot
object.
Install the OpenShift CLI (oc
).
Delete the VirtualMachineSnapshot
object. The snapshot controller deletes the VirtualMachineSnapshot
along with the associated VirtualMachineSnapshotContent
object.
$ oc delete vmsnapshot <my-vmsnapshot>
Verify that the snapshot is deleted and no longer attached to this VM:
$ oc get vmsnapshot