> **Documentation Index**: fetch the complete list of pages as Markdown at <https://www.okteto.com/docs/llms.txt> to find the right page before exploring further.

# Volume Snapshots in Development Environments

Okteto Volume Snapshots allow you to initialize Persistent Volume Claims (PVCs) with data from a previously created snapshot. This lets you work with large datasets or create Development Environments with realistic data from production or staging.

Common use cases:

* Restoring a database (PostgreSQL, MySQL, etc.) with real data for development and testing
* Quickly populating a Development Environment with staging or production data
* Cloning datasets for machine learning models, logs, or images

## How Volume Snapshots work

1. Your application uses a Persistent Volume Claim (PVC) to store data (e.g., a PostgreSQL or MySQL database)
2. You create a snapshot of this volume, capturing the data at that moment
3. When deploying a new Development Environment, you can restore the PVC from the snapshot, ensuring your app starts with the same dataset

This allows you to spin up new environments with fresh, realistic data every time.

## Requirements

* Self-Hosted
* BYOC

On Self-Hosted instances, Volume Snapshots support depends on your cluster configuration. Okteto requires a StorageClass backed by a [CSI driver that supports volume snapshots](https://kubernetes-csi.github.io/docs/snapshot-restore-feature.html), and a `VolumeSnapshotClass` that references that driver. Use this StorageClass for the source persistent volume of your volume snapshots.

Follow [this guide](/docs/self-hosted/install/volume-snapshots.md) to install a compatible CSI driver, create the `VolumeSnapshotClass`, and enable Volume Snapshots in your cluster.

On Bring Your Own Cloud (BYOC) instances, Volume Snapshots are enabled by default.

The default StorageClass on BYOC instances does not support Volume Snapshots. To snapshot a volume, set its StorageClass to `csi-okteto`, which supports Volume Snapshots. Use `csi-okteto` for the source persistent volume of your volume snapshots.

## Using Volume Snapshots in your Development Environment

Okteto enables developers to initialize persistent volume claims with the contents of a pre-existing volume snapshot. The Volume Snapshot is created from a persistent volume claim and can contain database backups, large files, images, or a copy of your staging data.

To use Volume Snapshots with your Development Environment, follow these steps:

* [1. Create the source persistent volume](/docs/core/use-volume-snapshots.md#1-create-the-source-persistent-volume-pvc)
* [2. Create a volume snapshot of the source persistent volume](/docs/core/use-volume-snapshots.md#2-create-a-snapshot-of-the-pvc)
* [3. Consume the volume snapshot in a new persistent volume](/docs/core/use-volume-snapshots.md#3-restore-a-pvc-from-a-snapshot)

### 1. Create the source persistent volume (PVC)

The first step is to ensure your database or application is storing data in a Persistent Volume Claim (PVC). This is the data that you want to be able to clone into your Development Environment. In the example below we use a database, but this could be anything that uses a volume for storage, such as databases, ML models, or images.

> If the default storage class of your cluster doesn't support volume snapshots, make sure you set the storage class to one that is compatible when creating your persistent volume. Check the [requirements](/docs/core/use-volume-snapshots.md#requirements) section to learn more about the available storage classes in Okteto.

* Kubernetes
* Compose

```
apiVersion: v1

kind: PersistentVolumeClaim

metadata:

  name: mysql-pvc

spec:

  storageClassName: csi-okteto

  accessModes:

  - ReadWriteOnce

  resources:

    requests:

      storage: 10Gi

---

apiVersion: v1

kind: Pod

metadata:

  name: mysql

spec:

  containers:

    - name: mysql

      image: mysql

      volumeMounts:

        - name: data

          mountPath: /var/lib/mysql

  volumes:

    - name: data

      persistentVolumeClaim:

        claimName: mysql-pvc
```

```
services:

  mysql:

    image: mysql

    volumes:

      - mysql-pvc:/var/lib/mysql



volumes:

  mysql-pvc:

    driver_opts:

      class: csi-okteto
```

note

Before generating a snapshot of the source volume above, ensure that the PersistentVolumeClaim is bound (i.e. with Status `Bound`), and that the data you want to snapshot is already written to the volume. On the Kubernetes and Compose implementations of the sample volume shown above, the defined PersistentVolumeClaim will be bound by a Pod that runs a MySQL database, but it could be any other application that writes data to your source volume.

### 2. Create a snapshot of the PVC

After creating the source persistent volume, the next step is to create the Volume Snapshot. Volume snapshots are created with the content of the persistent volume at the time of creating the volume snapshot. Further updates on the persistent volume aren't reflected in the volume snapshot content.

This step is independent of whether you created your persistent volume with Kubernetes manifests or a Docker Compose file:

The following manifest creates a volume snapshot from the `mysql-pvc` persistent volume claim:

```
apiVersion: snapshot.storage.k8s.io/v1

kind: VolumeSnapshot

metadata:

  name: mysql-snapshot

spec:

  volumeSnapshotClassName: okteto-snapshot-class

  source:

    persistentVolumeClaimName: mysql-pvc
```

### 3. Restore a PVC from a snapshot

Finally, you can use the Volume Snapshot created in the previous step to populate a new persistent volume. Use the `dev.okteto.com/from-snapshot-name` and `dev.okteto.com/from-snapshot-namespace` annotations on any persistent volume claim to tell Okteto to initialize your persistent volume claim from an existing volume snapshot, as shown below:

* Kubernetes
* Compose

```
apiVersion: v1

kind: PersistentVolumeClaim

metadata:

  annotations:

    dev.okteto.com/from-snapshot-name: mysql-snapshot

    dev.okteto.com/from-snapshot-namespace: staging

  name: pvc-from-snapshot

spec:

  accessModes:

  - ReadWriteOnce

  resources:

    requests:

      storage: 10Gi
```

```
services:

  mongodb:

    image: mysql

    volumes:

      - data:/var/lib/mysql



volumes:

  data:

    labels:

      dev.okteto.com/from-snapshot-name: mysql-snapshot

      dev.okteto.com/from-snapshot-namespace: staging
```

note

If the annotation `dev.okteto.com/from-snapshot-namespace` is **not defined**, Okteto defaults to the Namespace of the new persistent volume claim.

Use the annotation `dev.okteto.com/skip-snapshot-if-same-namespace: "true"` to skip the data cloning operation if the source snapshot and the new persistent volume claim are in the same Namespace.

## Automating snapshot creation in deployments

You can integrate snapshot creation into your Okteto Manifest so every deployment includes an updated snapshot:

```
deploy: 

   - create snapshot

   - deploy app
```
