Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

OpenShift APIs for Data Protection: VM pre-backup hooks

July 22, 2025
Doron Turgeman
Related topics:
Virtualization
Related products:
Red Hat OpenShiftRed Hat OpenShift Virtualization

    OpenShift APIs for Data Protection is an operator provided by Red Hat. It facilitates backup, recovery, and migration of applications, data, and Kubernetes resources in Red Hat OpenShift clusters. OpenShift APIs for Data Protection leverages Velero, an open source Kubernetes backup tool, and integrates it with cloud and storage providers to provide comprehensive data protection for Red Hat OpenShift Container Platform workloads.

    In a few scenarios, when backing up a virtual machine (VM), you need pre-migration hooks inside the virtual machine to:

    • Minimize the virtual machine size, save backup storage space, and purge unnecessary files such as log files.
    • Get Postgres consistent point-in-time snapshot for KVM.
    • Flush file system buffers.
    • Trigger custom application scripts.

    The classic OpenShift APIs for Data Protection hook solution (creating backup hooks) will not work for the guest VM since it can only run hooks inside a pod, but it does not have the permissions or configuration to log into the Kvirt guest VM to run the hook. This article describes how to execute operations before doing a VM backup with OpenShift APIs for Data Protection.

    VM pre-freeze hooks during backup

    It is possible to execute one or more scripts before the VM freezes. Failure or blocking of the script execution will not prevent the backup from being performed. Hence, scripts cannot be a condition to the backup.

    How to add your scripts

    The scripts will be automatically executed when located inside the virtual machine under /etc/qemu-ga/fsfreeze-hook.d.

    The hook script logs will be written to /var/log/qga-fsfreeze-hook.log.

    For example, say you need to purge files before VM backup. To do this, you will need to create hooks that run before the VM backup and perform the purge script to minimize the VM size before the backup.

    The following steps will help you achieve this:

    1. Log in to the VM.

      The folder /etc/qemu-ga contains:

      • Master script fsfreeze-hook that will trigger before VM freeze and will trigger scripts inside fsfreeze-hook.d.
      • A folder fsfreeze-hook.d  that creates scripts and places them in this folder to run before freeze.
    2. Add the following script purge.sh to delete the log files:
    #!/bin/bash
    # Path to the folder that contains the log files
    DIR="root/my-app/logs"
    if [ -d "$DIR" ]; 
    then
    rm -rf “$DIR”/*
    fi
    1. Ensure the created scripts are executable via chmod +x purge.sh.
    2. Ensure that the deleted files have write permissions for Linux and SELinux (see guidelines for SELinux below).

    Important points

    This documentation provides instructions on creating the VM backup with OADP. Likewise, these describe how to restore a VM with OADP.

    Note that these permission rules on files need to exist:

    1. The script runs as Linux root user permissions.
    2. If SELinux is enabled, follow the rules to allow the script to perform activities on the files. Refer to this blog for more information.
    3. First, run ausearch to generate SELinux denial module.
    4. Run semodule to apply the policy (see how in this blog which contains examples).
    5. To check the SELinux permissions:
      • For the target file, use ls -Z to see the SELinux user/role.
      • To understand the script's permissions, use echo $(id -Z) >> logfile.log to print the permissions.

     

    Related Posts

    • Back up Kubernetes persistent volumes using OADP

    • Kubernetes admission control with validating webhooks

    • Building virtual machines with Red Hat Developer Hub: The what, why, and how

    • Get started with OpenShift APIs for Data Protection

    Recent Posts

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    • How EvalHub manages two-layer Kubernetes control planes

    • Tekton joins the CNCF as an incubating project

    What’s up next?

    This concise guide helps VMware administrators efficiently manage virtual machines (VMs) within the powerful OpenShift platform.

    Get the cheat sheet
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.