Application consistent virtual machines backup
You must annotate the virt-launcher pod with the NetBackup pre and post hooks if it is responsible for spawning virtual machines (VMs), as VMs cannot be created without it.
Commands to freeze and unfreeze the virtual machines:
/usr/bin/virt-freezer --freeze --name <vm-name> --namespace <namespace>
/usr/bin/virt-freezer --unfreeze --name <vm-name> --namespace <namespace>
# kubectl annotate pod -l vm.kubevirt.io/name=<vm-name> -n <vm-namespace> netbackup-pre.hook.backup.velero.io/command='["/usr/bin/virt-freezer", "--freeze", "--name", "<vm-name>", "--namespace", "<vm-namespace>"]'
netbackup-pre.hook.backup.velero.io/container=compute
netbackup-post.hook.backup.velero.io/command='
["/usr/bin/virt-freezer", "--unfreeze", "--name",
"<vm-name>", "--namespace", "<vm-namespace>"]'
netbackup-post.hook.backup.velero.io/container=compute
In NetBackup, when performing a Restore Virtual Machine operation, Velero pre- and post-restore hooks are not executed for KubeVirt-based virtual machines. This limitation arises because KubeVirt dynamically generates launcher pods for virtual machines, and their creation process is decoupled from Velero's restore workflow. As a result, Velero is unable to associate or apply its hooks to these dynamically created pods.
To execute post-restore actions within a KubeVirt virtual machine, users can utilize the cloudInitNoCloud mechanism to inject and run scripts directly inside the guest operating system after the VM is restored.
Warning:
Even though NetBackup supports Velero restore hooks, NetBackup has limitations while using it for KubeVirt based VMs
Note:
In order to achieve app consistency, it is necessary to install qemu-guest-agent on virtual machines to implement kubevirt-specific pre-exec and post-exec rules.
For more details, about configuration of NetBackup pre and post hook, see https://www.veritas.com/
Post restore hook example:
InitContainer Restore Hooks annotations:
init.hook.restore.velero.io/container-image
init.hook.restore.velero.io/container-name
init.hook.restore.velero.io/command
InitContainer Restore Hooks As Pod Annotation Example:
$ kubectl annotate pod -n <POD_NAMESPACE> <POD_NAME> \
init.hook.restore.velero.io/container-name=restore-hook \
init.hook.restore.velero.io/container-image=alpine:latest \
init.hook.restore.velero.io/command='["/bin/ash", "-c", "date"]'
Exec Restore Hooks annotations:
post.hook.restore.velero.io/container
post.hook.restore.velero.io/command
post.hook.restore.velero.io/on-error
post.hook.restore.velero.io/exec-timeout
post.hook.restore.velero.io/wait-timeout
Exec Restore Hooks As Pod Annotation Example:
$ kubectl annotate pod -n <POD_NAMESPACE> <POD_NAME> \
post.hook.restore.velero.io/container=postgres \
post.hook.restore.velero.io/command='["/bin/bash", "-c", "psql < /backup/backup.sql"]' \
post.hook.restore.velero.io/wait-timeout=5m \
post.hook.restore.velero.io/exec-timeout=45s \
post.hook.restore.velero.io/on-error=Continue