1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-06 06:46:26 +01:00
Files
openshift-docs/modules/virt-creating-vm-snapshot-cli.adoc
2024-09-04 17:28:16 +00:00

118 lines
4.3 KiB
Plaintext

// Module included in the following assemblies:
//
// * virt/backup_restore/virt-managing-vm-snapshots.adoc
:_mod-docs-content-type: PROCEDURE
[id="virt-creating-vm-snapshot-cli_{context}"]
= Creating a snapshot by using the command line
You can create a virtual machine (VM) snapshot for an offline or online VM by creating a `VirtualMachineSnapshot` object.
.Prerequisites
* 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`).
* Optional: Power down the VM for which you want to create a snapshot.
.Procedure
. Create a YAML file to define a `VirtualMachineSnapshot` object that specifies the name of the new `VirtualMachineSnapshot` and the name of the source VM as in the following example:
+
[source,yaml]
----
apiVersion: snapshot.kubevirt.io/v1beta1
kind: VirtualMachineSnapshot
metadata:
name: <snapshot_name>
spec:
source:
apiGroup: kubevirt.io
kind: VirtualMachine
name: <vm_name>
----
. Create the `VirtualMachineSnapshot` object:
+
[source,terminal]
----
$ oc create -f <snapshot_name>.yaml
----
+
The snapshot controller creates a `VirtualMachineSnapshotContent` object, binds it to the `VirtualMachineSnapshot`, and updates the `status` and `readyToUse` fields of the `VirtualMachineSnapshot` object.
. Optional: If you are taking an online snapshot, you can use the `wait` command and monitor the status of the snapshot:
.. Enter the following command:
+
[source,terminal]
----
$ oc wait <vm_name> <snapshot_name> --for condition=Ready
----
.. Verify the status of the snapshot:
* `InProgress` - The online snapshot operation is still in progress.
* `Succeeded` - The online snapshot operation completed successfully.
* `Failed` - The online snapshot operaton failed.
+
[NOTE]
====
Online snapshots have a default time deadline of five minutes (`5m`). If the snapshot does not complete successfully in five minutes, the status is set to `failed`. Afterwards, the file system will be thawed and the VM unfrozen but the status remains `failed` until you delete the failed snapshot image.
To change the default time deadline, add the `FailureDeadline` attribute to the VM snapshot spec with the time designated in minutes (`m`) or in seconds (`s`) that you want to specify before the snapshot operation times out.
To set no deadline, you can specify `0`, though this is generally not recommended, as it can result in an unresponsive VM.
If you do not specify a unit of time such as `m` or `s`, the default is seconds (`s`).
====
.Verification
. Verify that the `VirtualMachineSnapshot` object is created and bound with `VirtualMachineSnapshotContent` and that the `readyToUse` flag is set to `true`:
+
[source,terminal]
----
$ oc describe vmsnapshot <snapshot_name>
----
+
.Example output
[source,yaml]
----
apiVersion: snapshot.kubevirt.io/v1beta1
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/v1beta1/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.