Create a Backup via CSI
Backups in Longhorn are objects in an off-cluster backupstore, and the endpoint to access the backupstore is the backup target. For more information, see this section.
To programmatically create backups, you can use the generic Kubernetes CSI snapshot mechanism. To learn more about the CSI snapshot mechanism, click here.
Prerequisite: CSI snapshot support needs to be enabled on your cluster. If your kubernetes distribution does not provide the kubernetes snapshot controller as well as the snapshot related custom resource definitions, you need to manually deploy them. For more information, see Enable CSI Snapshot Support.
To create a backup using the CSI mechanism, create a Kubernetes
VolumeSnapshot object via
kubectl. An example is here.
A backup is created. The
VolumeSnapshot object creation leads to the creation of a
VolumeSnapshotContent Kubernetes object.
VolumeSnapshotContent refers to a Longhorn backup in its
VolumeSnapshotContent.snapshotHandle field with the name
When the VolumeSnapshot object is created with kubectl, the
VolumeSnapshot.uuid field is used to identify a Longhorn snapshot and the associated
This creates a new Longhorn snapshot named
Then a backup of that snapshot is initiated, and the CSI request returns.
VolumeSnapshotContent object named
snapcontent-uuid is created.
The CSI snapshotter sidecar periodically queries the Longhorn CSI plugin to evaluate the backup status.
Once the backup is completed, the
VolumeSnapshotContent.readyToUse flag is set to true.
To see the backup, click Backup in the top navigation bar and navigate to the backup-volume mentioned in the
For information on how to restore a volume via a
refer to this page.
VolumeSnapshot object is below. The
source needs to point to the PVC of the Longhorn volume for which a backup should be created.
volumeSnapshotClassName field points to a
We create a default class named
longhorn, which uses
Delete as its
apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: test-snapshot-pvc spec: volumeSnapshotClassName: longhorn source: persistentVolumeClaimName: test-vol
If you want the associated backup for a volume to be retained when the
VolumeSnapshot is deleted, create a new
Retain set as the
For more information about snapshot classes, see the kubernetes documentation for VolumeSnapshotClasses.
© 2019-2023 Longhorn Authors | Documentation Distributed under CC-BY-4.0
© 2023 The Linux Foundation. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.