Skip to main content

Restore Longhorn PV from backup

Unfortunately, the longhorn UIs restore function does not work for in place backups. This means the PV needs to be deleted for the new volume to be created! As of this writing, there is a Github issue open from 2023 regarding this problem.

Steps to restore from backup
  1. Ensure the backup exists in the UI. Navigate to Volumes > <broken PV> > Backups. I open this in a new window. We need to take note of the PV and PVC names.
  2. Scale down the deployment/statefulset using the PV.

    kubectl scale statefulset <name> --replicas 0
  3. Delete the PV/PVC from the longhorn UI
  4. In the backup windows in the longhorn UI. Select Restore. Check the box "Use Previous Name"
  5. Navigate back to volumes and find the restored PV. On the right dropdown click Create PV/PVC. It should ask to use the old information, if not we need to fill in the information from step 1.
  6. Verify the PV/PVC exist and we can edit the PV and look for "volumeName" to match step 1.

     

    spec:
      storageClassName: longhorn
      volumeMode: Filesystem
      volumeName: pvc-<ID from step 1>
  7. Scale the deployment back up

    kubectl scale statefulset <name> --replicas 1