You can customize backups and restores in Tanzu Mission Control using backup and restore hooks.

Backup Hooks

Application workloads may require custom scripts or commands to be run before or after the backup operation. Examples of using hooks while creating backups are:

  • freezing the file system to ensure that all pending disk I/O operations have completed prior to backup

  • deleting files that should not be backed up

  • exporting database prior to backup

Velero supports executing commands in containers in pods during a backup. When performing a backup, you can specify one or more commands to execute in a container in a pod when that pod is being backed up. Pre hooks run before the pod is backed up. Post hooks run after the backup.

There are two ways to specify hooks, annotations on the pod itself, and in the BackupSpec. Tanzu Mission Control allows you to define backup hooks while scheduling backup and specifies hooks in the Backup spec.

For example, to freeze a file system, you may want to run:

  • pre hook command “/sbin/fsfreeze --freeze /var/log/nginx”

  • post hook command “/sbin/fsfreeze --unfreeze /var/log/nginx”

For more information about Velero and backup hooks, see https://velero.io/docs/main/backup-hooks.

Restore Hooks

Application workloads may require custom scripts or commands to be run during or after the restore process. Examples of using hooks while creating backups are:

  • create a TEMP file prior to restore

  • run a command into restored pod before the application containers can start

You can create restore hooks to run commands in init containers, before the application container starts, or in the application container itself. Velero supports two kinds of restore hooks:

  1. InitContainer restore hooks: These will add init containers into restored pods to perform any necessary setup before the application containers of the restored pod can start. You can use InitContainerhooks to run any setup needed for the pod to resume running from its backed-up state. There are two ways to specify InitContainerhooks:

    1. specifying hooks in annotations

    2. specifying hooks in the RestoreSpec

    Tanzu Mission control allows you to define InitContainer hooks while restoring a backup and specifies hooks in the Restore spec.

  2. Exec restore hooks: These will execute custom commands or scripts in containers of a restored Kubernetes pod. You can use an Execrestore hook to execute commands in a restored pod’s containers after they start. There are two ways to specify Exec hooks:

    1. specifying hooks in annotations

    2. specifying hooks in the RestoreSpec

Tanzu Mission control allows you to define Exec hooks while restoring a backup and specifies hooks in the Restore spec.

For more information about Velero and restore hooks, see https://velero.io/docs/main/restore-hooks/.