5.17.5. Creating backup hooks
Create backup hooks to run commands in a container in a pod by editing the Backup custom resource (CR). This helps you to run pre-backup and post-backup actions such as quiescing a database or flushing data to disk.
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).
Procedure
Add a hook to the
spec.hooksblock of theBackupCR, as in the following example:apiVersion: velero.io/v1 kind: Backup metadata: name: <backup> namespace: openshift-adp spec: hooks: resources: - name: <hook_name> includedNamespaces: - <namespace> excludedNamespaces: - <namespace> includedResources: [] - pods excludedResources: [] labelSelector: matchLabels: app: velero component: server pre: - exec: container: <container> command: - /bin/uname - -a onError: Fail timeout: 30s post: ...where:
<namespace>- Optional: Specifies the namespaces to which the hook applies. If this value is not specified, the hook applies to all namespaces.
excludedNamespaces- Optional: Specifies the namespaces to which the hook does not apply.
pods- Currently, pods are the only supported resource that hooks can apply to.
excludedResources- Optional: Specifies the resources to which the hook does not apply.
labelSelector- Optional: This hook only applies to objects matching the label. If this value is not specified, the hook applies to all objects.
pre- Specifies an array of hooks to run before the backup.
<container>- Optional: Specifies the container in which the command runs. If the container is not specified, the command runs in the first container in the pod.
/bin/uname-
Specifies the entry point for the
initcontainer being added. onError: Fail-
Specifies the error handling behavior. Allowed values are
FailandContinue. The default isFail. timeout: 30s-
Optional: Specifies how long to wait for the commands to run. The default is
30s. post- Specifies an array of hooks to run after the backup, with the same parameters as the pre-backup hooks.