This is a short example on how to restore only the PVCs using Velero.

Velero is an open source tool which can be used to backup and restore entire Kubernetes clusters or specific resources within a cluster.

Few useful commands when working with Velero can be found below:

Namespace one time backup:

Command line:

velero backup create grafana-backup --backup-location default --include-namespaces grafana

yaml:

cat <<EOF | kubectl apply -f -
apiVersion: velero.io/v1
kind: Backup
metadata:
  labels:
    velero.io/storage-location: default
  name: grafana-backup
  namespace: velero
spec:
  defaultVolumesToRestic: false
  hooks: {}
  includedNamespaces:
  - grafana
  storageLocation: default
  ttl: 720h0m0s
  volumeSnapshotLocations:
  - default
EOF

Create scheduled backups:

Here is a nice online cron check tool https://crontab.guru/

Command line:

velero create schedule grafana-schedule --include-namespaces grafana --schedule "0 20 * * *"
velero get schedules

yaml:

cat <<EOF | kubectl apply -f -
apiVersion: velero.io/v1
kind: Schedule
metadata:
  name: grafana-schedule
  namespace: velero
spec:
  schedule: 0 20 * * *
  template:
    hooks: {}
    includedNamespaces:
    - grafana
    storageLocation: default
    ttl: 720h0m0s
  useOwnerReferencesInBackup: true
EOF

List backups

velero get backups

Create PVC restore only

Here is the important part. Velero will not be able to restore only the PVC without restoring the actual POD as it needs to attach a restic-wait init container to the POD in order to restore the PVC.

If the backup is from another cluster make sure the Kubernetes default token for that specific namespace is created as a secret. It doesn’t need to contain the actual secret value but is important to exist as the secret is mount to the POD.

  1. This step is required only if the backup is from another cluster. Get the token name from the backup, the name will be listed under Secrets:
velero describe backup grafana-backup-20210701180058 --details
  1. Create the token in the new cluster:
kubectl create secret generic default-token-xxxxxx
  1. Delete the component which manages the POD (e.g: sts, deploy, ds).
kubectl delete deploy grafana
  1. Delete the PVC:
kubectl get pvc
kubectl delete pvc PVC_NAME
  1. Restore only the PVCs using velero:
velero get backups
velero restore create --from-backup grafana-backup-20210701180058 --restore-volumes=true --include-resources pods,persistentvolumeclaims,persistentvolumes
  1. Check the restore status:
velero get restore
velero restore describe grafana-backup-20210701180058-20210627190534 --details
  1. Once the restore is complete the POD used for restore and the default token can be delete (if was created initially) and the grafana deployment can be restored. If the app was deployed using helm an example on how to restore the deployment using helm can be found below:
helm history grafana
  1. Get the latest revision deployed and use the rollback command to restore that. This will only restore the deployment. In our example the latest revision is 4.
helm rollback grafana 4 

With this latest step the application will be started and the new restored PVC will be mount.