×

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:

    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 objects.
    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 entry point 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.