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 a Ready state.

  • You must have a Velero Backup CR.

Procedure

  1. Create a Restore CR, as in the following example:

    1. apiVersion: velero.io/v1
    2. kind: Restore
    3. metadata:
    4. name: <restore>
    5. namespace: openshift-adp
    6. spec:
    7. backupName: <backup> (1)
    8. excludedResources:
    9. - nodes
    10. - events
    11. - events.events.k8s.io
    12. - backups.velero.io
    13. - restores.velero.io
    14. - resticrepositories.velero.io
    15. restorePVs: true
    1Name of the Backup CR.
  2. Verify that the status of the Restore CR is Completed:

    1. $ oc get restore -n openshift-adp <restore> -o jsonpath='{.status.phase}'
  3. Verify that the backup resources have been restored:

    1. $ oc get all -n <namespace> (1)
    1Namespace 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 the Restore CR, as in the following example:

    1. apiVersion: velero.io/v1
    2. kind: Restore
    3. metadata:
    4. name: <restore>
    5. namespace: openshift-adp
    6. spec:
    7. hooks:
    8. resources:
    9. - name: <hook_name>
    10. includedNamespaces:
    11. - <namespace> (1)
    12. excludedNamespaces:
    13. - <namespace>
    14. includedResources:
    15. - pods (2)
    16. excludedResources: []
    17. labelSelector: (3)
    18. matchLabels:
    19. app: velero
    20. component: server
    21. postHooks:
    22. - init:
    23. initContainers:
    24. - name: restore-hook-init
    25. image: alpine:latest
    26. volumeMounts:
    27. - mountPath: /restores/pvc1-vm
    28. name: pvc1-vm
    29. command:
    30. - /bin/ash
    31. - -c
    32. - exec:
    33. container: <container> (4)
    34. command:
    35. - /bin/bash (5)
    36. - -c
    37. - "psql < /backup/backup.sql"
    38. waitTimeout: 5m (6)
    39. execTimeout: 1m (7)
    40. onError: Continue (8)
    1Optional: Array of namespaces to which the hook applies. If this value is not specified, the hook applies to all namespaces.
    2Currently, pods are the only supported resource.
    3Optional: This hook only applies to objects matching the label selector.
    4Optional: If the container is not specified, the command runs in the first container in the pod.
    5Array of commands that the hook runs.
    6Optional: 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.
    7Optional: How long to wait for the commands to run. The default is 30s.
    8Allowed values for error handling are Fail and Continue:
    • Continue: Only command failures are logged.

    • Fail: No more restore hooks run in any container in any pod. The status of the Restore CR will be PartiallyFailed.