Restore a Backup via CSI
Longhorn can easily restore backups to a volume. For more information on how backups work, refer to the concepts section.
To programmatically restore backups you can use the generic kubernetes csi snapshot mechanism. To learn more about the CSI snapshot mechanism, click here.
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.
PersistentVolumeClaim object where the
dataSource field points to an existing
The csi-provisioner will pick this up and instruct the Longhorn CSI driver to provision a new volume with the data from the associated backup.
You can use the same mechanism to restore Longhorn backups that have not been created via the CSI mechanism.
PersistentVolumeClaim is below. The
dataSource field needs to point to an existing
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: test-restore-snapshot-pvc spec: storageClassName: longhorn dataSource: name: test-snapshot-pvc kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 2Gi
To restore Longhorn backups that have not been created via the CSI mechanism, you have to first manually create a
VolumeSnapshotContent object for the backup.
VolumeSnapshotContent object with the
snapshotHandle field set to
backup-name values can be retrieved from the Backup page in the Longhorn UI.
apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshotContent metadata: name: test-existing-backup spec: volumeSnapshotClassName: longhorn driver: driver.longhorn.io deletionPolicy: Delete source: # NOTE: change this to point to an existing backup on the backupstore snapshotHandle: bs://test-vol/backup-625159fb469e492e volumeSnapshotRef: name: test-snapshot-existing-backup namespace: default
Create the associated
VolumeSnapshot object with the
name field set to
test-snapshot-existing-backup, where the
source field refers to a
VolumeSnapshotContent object via the
This differs from the creation of a backup, in which case the
source field refers to a
PerstistentVolumeClaim via the
Only one type of reference can be set for a
apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: test-snapshot-existing-backup spec: volumeSnapshotClassName: longhorn source: volumeSnapshotContentName: test-existing-backup
Now you can create a
PerstistantVolumeClaim object that refers to the newly created
For an example see Restore a backup via a
VolumeSnapshot object above.
© 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.