Creating a volume snapshot
To preserve the data on a PersistentVolumeClaim (PVC) at a specific point in time, create a volume snapshot. By using a volume snapshot, you can restore the volume to its previous state or provision new volumes with the saved data.
To create a snapshot of a MicroShift storage volume, you must first configure RHEL for Edge and the node.
In the following example procedure, the pod that the source volume is mounted to is deleted. Deleting the pod prevents data from being written to it during snapshot creation. Ensuring that no data is being written during a snapshot is crucial to creating a viable snapshot.
-
User has root access to a MicroShift node.
-
MicroShift is running.
-
A device class defines an LVM thin-pool.
-
A
volumeSnapshotClassspecifiesdriver: topolvm.io. -
Any workload attached to the source PVC is paused or deleted. This helps avoid data corruption.
|
|
All writes to the volume must be halted while you are creating the snapshot. If you do not halt writes, your data might be corrupted. |
-
Prevent data from being written to the volume during snapshotting by using one of the two following steps:
-
Delete the pod to ensure that no data is written to the volume during snapshotting by running the following command:
$ oc delete my-pod -
Scale the replica count to zero on a pod that is managed with a replication controller. Setting the count to zero prevents the instant creation of a new pod when one is deleted.
-
-
After all writes to the volume are halted, run a command similar to the example that follows. Insert your own configuration details.
Example snapshot configuration# oc apply -f <<EOF apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshot metadata: name: <snapshot_name> spec: volumeSnapshotClassName: topolvm-snapclass source: persistentVolumeClaimName: test-claim-thin EOFwhere:
kind-
Specifies the type of
VolumeSnapshotobject to create. metadata.name-
Specifies the name that you specify for the snapshot.
volumeSnapshotClassName-
Specifies the desired name of the
VolumeSnapshotClassobject. persistentVolumeClaimName-
Specifies either
persistentVolumeClaimNameorvolumeSnapshotContentName. In this example, a snapshot is created from a PVC namedtest-claim-thin.
-
Wait for the storage driver to finish creating the snapshot by running the following command:
$ oc wait volumesnapshot/<snapshot_name> --for=jsonpath\='{.status.readyToUse}=true' -
When the
volumeSnapshotobject is in aReadyToUsestate, you can restore the state as a volume for future PVCs. Restart the pod or scale the replica count back up to the desired number. -
After you have created the volume snapshot, you can remount the source PVC to a new pod.
Volume snapshots are located on the same devices as the original data. To use the volume snapshots as backups, move the snapshots to a secure location.