Restoring applications
You restore application backups by creating a Restore custom resources (CRs).
You can create restore hooks to run commands in init containers, before the application container starts, or in the application container itself.
Creating a Restore CR
You restore a Backup
custom resource (CR) by creating a Restore
CR.
Prerequisites
You must install the OpenShift API for Data Protection (OADP) Operator.
The
DataProtectionApplication
CR must be in aReady
state.You must have a Velero
Backup
CR.
Procedure
Create a
Restore
CR, as in the following example:apiVersion: velero.io/v1
kind: Restore
metadata:
name: <restore>
namespace: openshift-adp
spec:
backupName: <backup> (1)
excludedResources:
- nodes
- events
- events.events.k8s.io
- backups.velero.io
- restores.velero.io
- resticrepositories.velero.io
restorePVs: true
1 Name of the Backup
CR.Verify that the status of the
Restore
CR isCompleted
:$ oc get restore -n openshift-adp <restore> -o jsonpath='{.status.phase}'
Verify that the backup resources have been restored:
$ oc get all -n <namespace> (1)
1 Namespace that you backed up.
Creating restore hooks
You create restore hooks to run commands in a container in a pod while restoring your application by editing the Restore
custom resource (CR).
You can create two types of restore hooks:
An
init
hook adds an init container to a pod to perform setup tasks before the application container starts.If you restore a Restic backup, the
restic-wait
init container is added before the restore hook init container.An
exec
hook runs commands or scripts in a container of a restored pod.
Procedure
Add a hook to the
spec.hooks
block of theRestore
CR, as in the following example:apiVersion: velero.io/v1
kind: Restore
metadata:
name: <restore>
namespace: openshift-adp
spec:
hooks:
resources:
- name: <hook_name>
includedNamespaces:
- <namespace> (1)
excludedNamespaces:
- <namespace>
includedResources:
- pods (2)
excludedResources: []
labelSelector: (3)
matchLabels:
app: velero
component: server
postHooks:
- init:
initContainers:
- name: restore-hook-init
image: alpine:latest
volumeMounts:
- mountPath: /restores/pvc1-vm
name: pvc1-vm
command:
- /bin/ash
- -c
- exec:
container: <container> (4)
command:
- /bin/bash (5)
- -c
- "psql < /backup/backup.sql"
waitTimeout: 5m (6)
execTimeout: 1m (7)
onError: Continue (8)
1 Optional: Array of namespaces to which the hook applies. If this value is not specified, the hook applies to all namespaces. 2 Currently, pods are the only supported resource. 3 Optional: This hook only applies to objects matching the label selector. 4 Optional: If the container is not specified, the command runs in the first container in the pod. 5 Array of commands that the hook runs. 6 Optional: If the waitTimeout
is not specified, the restore waits indefinitely. You can specify how long to wait for a container to start and for preceding hooks in the container to complete. The wait timeout starts when the container is restored and might require time for the container to pull the image and mount the volumes.7 Optional: How long to wait for the commands to run. The default is 30s
.8 Allowed values for error handling are Fail
andContinue
:Continue
: Only command failures are logged.Fail
: No more restore hooks run in any container in any pod. The status of theRestore
CR will bePartiallyFailed
.