// Module included in the following assemblies:
//
// * backup_and_restore/application_backup_and_restore/backing-up-applications.adoc

:_mod-docs-content-type: PROCEDURE
[id="oadp-creating-backup-hooks_{context}"]
= Creating backup hooks

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

_Pre_ hooks run before the pod is backed up. _Post_ hooks run after the backup.

.Procedure

* Add a hook to the `spec.hooks` block of the `Backup` CR, as in the following example:
+
[source,yaml]
----
apiVersion: velero.io/v1
kind: Backup
metadata:
  name: <backup>
  namespace: openshift-adp
spec:
  hooks:
    resources:
      - name: <hook_name>
        includedNamespaces:
        - <namespace> <1>
        excludedNamespaces: <2>
        - <namespace>
        includedResources:
        - pods <3>
        excludedResources: [] <4>
        labelSelector: <5>
          matchLabels:
            app: velero
            component: server
        pre: <6>
          - exec:
              container: <container> <7>
              command:
              - /bin/uname <8>
              - -a
              onError: Fail <9>
              timeout: 30s <10>
        post: <11>
...
----
<1> Optional: You can specify namespaces to which the hook applies. If this value is not specified, the hook applies to all namespaces.
<2> Optional: You can specify namespaces to which the hook does not apply.
<3> Currently, pods are the only supported resource that hooks can apply to.
<4> Optional: You can specify resources to which the hook does not apply.
<5> Optional: This hook only applies to objects matching the label. If this value is not specified, the hook applies to all namespaces.
<6> Array of hooks to run before the backup.
<7> Optional: If the container is not specified, the command runs in the first container in the pod.
<8> This is the entrypoint for the init container being added.
<9> Allowed values for error handling are `Fail` and `Continue`. The default is `Fail`.
<10> Optional: How long to wait for the commands to run. The default is `30s`.
<11> This block defines an array of hooks to run after the backup, with the same parameters as the pre-backup hooks.
