Sub topic 12
Restoring a backup and remapping namespaces
This chapter assumes you have Velero installed with a backup storage location, and that you have created the shop-backup backup from the previous chapters. You should be comfortable with kubectl and with namespaces, Deployments, and PersistentVolumeClaims.
How a Velero restore works
A restore reads a backup from object storage and recreates its resources in the cluster. Velero represents each restore as a Restore custom resource. The server controller creates the objects in a fixed order, so that namespaces, storage classes, and volumes exist before the Pods that use them.
Velero does not overwrite existing objects by default. If a resource already exists, Velero skips it and records a warning. This makes a restore safe to run against a live namespace, but it also means a restore will not roll back changes to objects that still exist.
Restoring into a different namespace
Restoring over the live namespace is risky when you only want to check a backup. A namespace mapping restores into a new namespace instead, which leaves the original untouched.
velero restore create --from-backup shop-backup \
--namespace-mappings shop:shop-restored
velero restore get
velero restore describe <restore-name> --detailsThe --namespace-mappings flag takes source:destination pairs. Velero creates the destination namespace if it does not exist. Replace <restore-name> with the name shown by velero restore get. Without --restore-name, Velero builds one from the backup name and a timestamp.
Checking the result
A restore can finish with the phase Completed and still have problems. Check three things.
- The phase.
Completedmeans all items were processed.PartiallyFailedmeans some failed, andFailedmeans the restore could not run. - The warnings and errors in
velero restore describe --details. - The workloads themselves.
kubectl get all,pvc -n shop-restored
kubectl get pods -n shop-restoredIf volumes were backed up with file system backup, the Pods wait for Velero to copy the data back. The describe --details output lists each volume restore and its progress.
Common problems
| Symptom | Likely cause | What to do |
|---|---|---|
| Warning: resource already exists | The object is still in the cluster | Delete it first, or restore to a mapped namespace |
| Pods stay in `Pending` | The PVC cannot bind, or the storage class is missing | Check the PVC and the storage class in the target cluster |
| Service or Ingress conflicts | A cluster-wide value, such as a NodePort, is already in use | Remove the conflicting object, or edit the restored one |
| Restore stuck in `InProgress` | Volume data is still being copied | Wait, and check the node agent Pods |
Restoring a subset
You can restore part of a backup with the same filters that backups use, such as --include-resources or --selector. This is useful when only one Deployment or ConfigMap was deleted by mistake.
velero restore create --from-backup shop-backup \
--include-resources deployments,configmaps \
--namespace-mappings shop:shop-restoredExercise
You run velero restore create --from-backup shop-backup while the shop namespace still has a Deployment that was edited after the backup. The restore finishes as Completed with a warning. What happened to the edited Deployment, and how can you restore the backed-up version?
Show answer
Velero skipped the Deployment because it already exists, so your edit is still in place, and the warning records the skip. To get the backed-up version, either delete the Deployment and restore again, or restore into another namespace with --namespace-mappings shop:shop-restored and compare or copy the object from there.