Restore charm PV
This guide describes how to back up and restore a Persistent Volume for a charm that stores some data in the PVC managed by Juju.
Requirements
- A client charm that provides a backup configuration via the interface. For example, MinIO operator.
- Charmed Velero deployed and configured.
- The client charm is related to Charmed Velero.
The Juju feature is only available with export JUJU_DEV_FEATURE_FLAGS=k8s-attach-storage
.
Set up the environment variables
Define these variables before running any commands:
CLIENT_MODEL="client-model"
CLIENT_APP="my-app"
CLIENT_ENDPOINT="velero-backup-config"
Create a backup for the client charm
juju switch velero
juju run velero-operator/0 create-backup target=${CLIENT_APP}:${CLIENT_ENDPOINT} model=$CLIENT_MODEL
juju run velero-operator/0 list-backups
Save the backup UID from the list-backups
action for later use.
Prepare the client charm
juju switch $CLIENT_MODEL
juju scale-application $CLIENT_APP 0
juju storage
juju remove-storage ${CLIENT_APP}-data/<id>
Restore with Charmed Velero
juju switch velero
juju run velero-operator/0 list-backups
juju run velero-operator/0 restore backup-uid=<backup-uid>
Discover restored PVs
Confirm that the restored Persistent Volume (PV) still points to the old Persistent Volume Claim (PVC) and note the name of the restored PV:
kubectl get pv
kubectl get pv <pv-name> -o jsonpath='{.spec.claimRef.namespace}/{.spec.claimRef.name}{"\n"}'
Import restored PVs into Juju storage & Reattach
Import the restored PV using juju
. <storage_name>
is the charm’s storage (e.g., minio-data). The
--force
flag is required to change the PV’s Reclaim Policy to retain and set PV’s claimRef to null before attaching later.
juju import-filesystem kubernetes <pv_name> ${CLIENT_APP}-data --force
Reattach the restored PV by retrieving the new storage name from juju storage
and adding it to the application unit. --attach-storage
flag instructs Juju to create a new PVC and bind a PV to it.
juju add-unit $CLIENT_APP --attach-storage ${CLIENT_APP}-data/<id>
Check the application
Check the status of the application and confirm that the PVC was reattached:
juju status $CLIENT_APP
kubectl -n $CLIENT_MODEL get pvc
kubectl -n $CLIENT_MODEL describe pvc <claim>