// Module included in the following assemblies:
//
// * storage/container_storage_interface/persistent-storage-csi-group-snapshots.adoc

:_mod-docs-content-type: PROCEDURE
[id="persistent-storage-csi-group-snapshots-create_{context}"]
= Creating a volume group snapshot

[role="_abstract"]
Create a VolumeGroupSnapshot object to capture point-in-time copies of multiple persistent volume claims (PVCs). Label the PVCs, specify the `VolumeGroupSnapshotClass`, and individual `VolumeSnapshot` objects are created automatically.

When you create a `VolumeGroupSnapshot` object, {product-title} creates a volume group snapshot.

.Prerequisites
* Logged in to a running {product-title} cluster.
* Enabled this feature using feature gates. For information about how to use feature gates, see "Enabling features sets by using feature gates".
* The persistent volume claims (PVCs) that you want to group for the snapshot have been created using a CSI driver that supports `VolumeGroupSnapshot` objects.
* A storage class to provision the storage back end.
* Administrator has created the `VolumeGroupSnapshotClass` object.

.Procedure
. Locate (or create) the PVCs that you want to include in the volume group snapshot by running the following command:
+
[source,terminal]
----
$ oc get pvc
----
+
.Example
[source,terminal]
----
NAME        STATUS    VOLUME                                     CAPACITY   ACCESSMODES   AGE
pvc-0       Bound     pvc-a42d7ea2-e3df-11ed-b5ea-0242ac120002   1Gi        RWO           48s
pvc-1       Bound     pvc-a42d81b8-e3df-11ed-b5ea-0242ac120002   1Gi        RWO           48S
----
+
This example uses two PVCs

. Label the PVCs to belong to a snapshot group:
.. Label PVC pvc-0 by running the following command:
+
[source,terminal]
----
$ oc label pvc pvc-0 group=myGroup
----
+
.Example output
[source,terminal]
----
persistentvolumeclaim/pvc-0 labeled
----
.. Label PVC pvc-1 by running the following command:
+
.Example output
[source,terminal]
----
$ oc label pvc pvc-1 group=myGroup
----
+
.Example output
[source,terminal]
----
persistentvolumeclaim/pvc-1 labeled
----
+
In this example, you are labeling PVC "pvc-0" and "pvc-1" to belong to group "myGroup".

. Create a `VolumeGroupSnapshot` object to specify your volume group snapshot:
.. Create a `VolumeGroupSnapshot` object YAML file with the following example file:
+
.Example VolumeGroupSnapshot YAML file
[source,yaml]
----
apiVersion: groupsnapshot.storage.k8s.io/v1beta2
kind: VolumeGroupSnapshot
metadata:
  name: <volume-group-snapshot-name>
  namespace: <namespace>
spec:
  volumeGroupSnapshotClassName: <volume-group-snapshot-class-name>
  source:
    selector:
      matchLabels:
        group: myGroup
----
+
* `kind`: The `VolumeGroupSnapshot` object requests creation of a volume group snapshot for multiple PVCs.
* `metadata.name`: Name of the volume group snapshot.
* `metadata.namespace`: Namespace for the volume group snapshot.
* `spec.volumeGroupSnapshotClassName`: The `VolumeGroupSnapshotClass` name. This object is created by the administrator and describes how volume group snapshots should be created.
* `spec.source.selector.matchLabels.group`: The name of the label used to group the required PVCs for the snapshot. In this example, it is "myGroup".

.. Create the `VolumeGroupSnapshot` object by running the following command:
+
[source,terminal]
----
$ oc create -f <volume-group-snapshot-filename>.yaml
----

.Results
Individual volume snapshots are created according to how many PVCs were specified as part of the volume group snapshot.

These individual volume snapshots are named with the following format: <hash of VolumeGroupSnaphotContentUUID+volumeHandle>:
[source,yaml]
----
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
  name: snapshot-4dc1c53a29538b36e85003503a4bcac5dbde4cff59e81f1e3bb80b6c18c3fd03
  namespace: default
  ownerReferences:
  - apiVersion: groupsnapshot.storage.k8s.io/v1beta2
    kind: VolumeGroupSnapshot
    name: my-groupsnapshot
    uid: ba2d60c5-5082-4279-80c2-daa85f0af354
  resourceVersion: "124503"
  uid: c0137282-f161-4e86-92c1-c41d36c6d04c 
spec:
  source:
    persistentVolumeClaimName:pvc-1
status:
  volumeGroupSnapshotName: volume-group-snapshot-name
----

In the preceding example, two individual volume snapshots are created as part of the volume group snapshot.

[source,terminal]
----
snapshot-4dc1c53a29538b36e85003503a4bcac5dbde4cff59e81f1e3bb80b6c18c3fd03
snapshot-fbfe59eff570171765df664280910c3bf1a4d56e233a5364cd8cb0152a35965b
----