Creating backup hooks

When performing a backup, it is possible to specify one or more commands to execute in a container within a pod, based on the pod being backed up.

The commands can be configured to performed before any custom action processing (Pre hooks), or after all custom actions have been completed and any additional items specified by the custom action have been backed up (Post hooks).

You create backup hooks to run commands in a container in a pod by editing the Backup custom resource (CR).

Procedure

  • Add a hook to the spec.hooks block of the Backup CR, as in the following example:

    1. apiVersion: velero.io/v1
    2. kind: Backup
    3. metadata:
    4. name: <backup>
    5. namespace: openshift-adp
    6. spec:
    7. hooks:
    8. resources:
    9. - name: <hook_name>
    10. includedNamespaces:
    11. - <namespace> (1)
    12. excludedNamespaces: (2)
    13. - <namespace>
    14. includedResources: []
    15. - pods (3)
    16. excludedResources: [] (4)
    17. labelSelector: (5)
    18. matchLabels:
    19. app: velero
    20. component: server
    21. pre: (6)
    22. - exec:
    23. container: <container> (7)
    24. command:
    25. - /bin/uname (8)
    26. - -a
    27. onError: Fail (9)
    28. timeout: 30s (10)
    29. post: (11)
    30. ...
    1Optional: You can specify namespaces to which the hook applies. If this value is not specified, the hook applies to all namespaces.
    2Optional: You can specify namespaces to which the hook does not apply.
    3Currently, pods are the only supported resource that hooks can apply to.
    4Optional: You can specify resources to which the hook does not apply.
    5Optional: This hook only applies to objects matching the label. If this value is not specified, the hook applies to all objects.
    6Array of hooks to run before the backup.
    7Optional: If the container is not specified, the command runs in the first container in the pod.
    8This is the entry point for the init container being added.
    9Allowed values for error handling are Fail and Continue. The default is Fail.
    10Optional: How long to wait for the commands to run. The default is 30s.
    11This block defines an array of hooks to run after the backup, with the same parameters as the pre-backup hooks.