Restoring an application
OADP restores resources and persistent volumes from a backup archive. Restore can cover either all objects in the backup archive or it can filter the restored objects by namespace, persistent volume, or label.
For restoring an application, a RestoreCustomResource needs to be defined.
RestoreCustomResourceapiVersion: velero.io/v1
kind: Restore
metadata:
name: mysql-restore
namespace: openshift-adp
spec:
backupName: mysql-backup
excludedResources:
- nodes
- events
- events.events.k8s.io
- backups.velero.io
- restores.velero.io
- resticrepositories.velero.io
restorePVs: trueOADP supports an incremental restore, which makes it possible to only restore data, which has
been modified between two backups. To support incremental restore, a new parameter
existingResourcePolicy has been added.
RestoreCustomResource for an
incremental restore apiVersion: velero.io/v1
kind: Restore
metadata:
name: mysql-restore
namespace: openshift-adp
spec:
backupName: mysql-backup
excludedResources:
- nodes
- events
- events.events.k8s.io
- backups.velero.io
- restores.velero.io
- resticrepositories.velero.io
restorePVs: true
ExistingResourcePolicy: updateFor details see: Add support for Resourcefulness to restore API(GitHub)
For a successful restore of an application to a new Red Hat OpenShift cluster, it is important to maintain the consistency of user ID (UID) of the service account that runs the application. That UID is used to run the application inside the Container.
It is a best practice that the application uses securitycontextconstraints
targeting the service account in deployment to allow privileged containers. This means that the
service account used in the pod is always the same and has one UID on both backup and restore
cluster. Create an SCC or use an existing one that allows custom UID outside of normal allowed
namespace UID ranges.
When the application also needs to be run under a specific custom UID, then the Pod definition needs to use a ServiceAccount with the RunAsAny privilege, and the Pod needs to use the runAsUser to set the UID to the hardcoded UID.
oc create sa sa-with-anyuid
oc adm policy add-scc-to-user anyuid -z sa-with-anyuidapiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
serviceAccountName: sa-with-anyuid
securityContext:
runAsUser: 1001
fsGroup: 1001For more information on Red Hat OpenShift UIDS, refer to A Guide to OpenShift UIDS
The Red Hat article OpenShift APIs for Data Protection (OADP) FAQ provides details on challenges and workarounds during the restore of an application on new cluster.