How VolumeSnapshot works in Stash

This guide will show you how Stash takes snapshot of PersistentVolumeClaims and restore them from snapshot using Kubernetes VolumeSnapshot API.

Before You Begin

How Backup Process Works?

The following diagram shows how Stash creates VolumeSnapshot via Kubernetes native API. Open the image in a new tab to see the enlarged version.

  Stash Backup Flow
Fig: Volume Snapshotting Process in Stash

The VolumeSnapshot process consists of the following steps:

  1. At first, a user creates a BackupConfiguration crd which specifies the targeted workload or targeted PVC.

  2. Stash operator watches for BackupConfiguration crd.

  3. When it finds a BackupConfiguration crd, it creates a CronJob to take a periodic backup of the target volumes.

  4. The CronJob triggers backup on each scheduled time slot by creating a BackupSession crd.

  5. Stash operator watches for BackupSession crd.

  6. When it finds a BackupSession crd, it creates a volume snapshotter Job to take snapshot of the targeted volumes.

  7. The volume snapshotter Job creates VolumeSnapshot crd for each PVC of the target and waits for the CSI driver to complete snapshotting. These VolumeSnasphot crd names follow the following format:

  <PVC name>-<BackupSession creation timestamp in Unix epoch seconds>
  1. CSI external-snapshotter controller watches for VolumeSnapshot.

  2. When it finds a VolumeSnapshot object, it backups VolumeSnapshot in the respective cloud storage.

  3. Once the snapsotting is completed, Stash Operator updates the status.phase field of the BackupSession crd.

How Restore Process Works?

The following diagram shows how Stash restores PersistentVolumeClaims from snapshot using Kubernetes VolumeSnapshot API. Open the image in a new tab to see the enlarged version.

  Stash Backup Flow
Fig: Restore process from snapshot in Stash

The restore process consists of the following steps:

  1. At first, a user creates a RestoreSession crd which specifies the volumeClaimTemplates. VolumeClaimTemplates hold the information about VolumeSnapshot.

  2. Stash operator watches for RestoreSession crd.

  3. When it finds a RestoreSession crd, it creates a Restore Jobto restore PVC from the snapshot.

  4. The restore Job creates PVC with spec.dataSource field set to the respective VolumeSnapshot name.

  5. CSI external-snapshotter controller watches for PVC.

  6. When it finds a new PVC with spec.dataSource field set, it reads the information about the VolumeSnapshot.

  7. The controller downloads the respective data from the cloud and populate the PVC with it.

  8. Once restore process is completed, the Stash operator updates the status.phase field of the BackupSession crd.

Next Steps

  1. See a step by step guide to snapshot the volumes of a Deployment here.
  2. See a step by step guide to snapshot the volumes of a StatefulSet here.
  3. See a step by step guide to snapshot a stand-alone PVC here.