Skip to main content
Pre-backup and post-backup scripts for File server
Updated over 7 months ago

Overview

Druva allows administrators to configure File server agents to execute custom pre-backup scripts and post-backup scripts. Pre-backup scripts are executed before backup jobs to perform specific pre-backup operation. Post-backup scripts are executed after backup jobs to perform specific post-backup operation. You can configure backup policy with the settings for pre-backup and post-backup scripts to perform customer-driven processing tasks. For example,

  • To backup database dumps as flat files using the Druva File server agent and delete the dump files after the Druva backup job completes.

  • To stop an antivirus service before the backup job and restarting the service after backup completes.

Considerations

Configuring pre-backup and post-backup scripts in File server backup policy is optional. Before configuring the pre-backup script and post-backup script settings, you should consider the following information:

  • The pre-backup scripts and the post-backup scripts must be present on the same File server, which is configured with Druva for backup.

  • You can configure the pre-backup scripts and the post-backup scripts only for Windows and Linux File servers supported by Druva.

  • The pre-backup scripts and post-backup scripts should be executable files. Ensure that the scripts are created as per the following conventions:

    • For Linux File server, save the scripts as pre_script.sh and post_script.sh.

    • For Windows File server, save the scripts as pre_script.bat and post_script.bat.

  • If the pre-backup script or post-backup script execution fails, alert and email will be generated for the respective script failure at the end of the last retried job.

  • When the pre-backup or post-backup script is killed externally, for example, through Task Manager or command line ( kill -9 <pid> ), then the backup cycle gets executed after the context of the script exits.

  • If the script execution time limit is not specified, the pre-backup and post-backup scripts run until the script execution is complete or 1 year, whichever is less.

Steps to configure pre-backup and post-backup scripts

The following diagram depicts the steps to configure pre-backup scripts and post-backup scripts.

Steps to configure custom scripts

  1. Create pre-backup scripts and post-backup scripts on File Servers.
    For more information on how to create custom scripts, see Guidelines to create custom backup scripts.

  2. Configure the backup policy with the following script settings on the Druva portal:

    1. Enable custom script execution for File Servers.

    2. Specify the folder location containing scripts on the File Servers.

    3. Specify the option to skip backup operation if the pre-backup script execution fails or pre-backup script is unavailable at the configured location.

    4. Specify the script timeout option.

  3. The File server agent executes the pre-backup and post-backup scripts from the path configured in the backup policy on the source server.
    When the pre-backup and post-backup scripts are executed, the agent passes a set of arguments to these scripts. These arguments are interpreted in the following sequence:

    • For pre_backup script: [ script_name, job_id ]

    • For post_backup script: [ script_name, job_id, pre_script_status_integer, backup_status_integer ]
      where,

      • script_name represents the absolute path of script.

      • job_id represents the job identification number of the current backup job.

      • pre_script_status_integer represents the status of the pre-script execution.

      • backup_status_integer represents the status of the backup job execution.

Workflow of backup job execution with custom scripts

You must configure the File server backup policy in order to run the custom scripts during backup job execution. Scripts will be executed before and after the backup execution based on the configured backup policy.

The following diagram depicts the lifecycle of the backup job when the pre-backup scripts and post-backup scripts are enabled.

Behavior of pre-backup and post-backup script execution and backup job status

When a File server backup policy is configured with pre-backup and post-backup scripts, the user actions affect the pre-backup and post-backup script execution. The following section describes the behavior of pre-backup and post-backup script execution based on the user interaction.

  • Job Retry: For every Job Retry operation, the pre-backup and post-backup script will execute before and after the backup job. Alert and email will be generated for the respective script failure at the end of last retried job.

  • Backup job cancel: When a Backup job is canceled during pre-backup script execution, the pre-backup script is executed, the backup job is canceled, and the post-backup script is executed. When a backup job is canceled during post-backup script execution, the post-backup script is executed, and the job is canceled.

  • Backup window expiry: When a backup window expires at the time of pre-script execution, the pre-backup script execution exits with the Failed status and the post-backup script is executed.

  • Backup now: When a running job is a manually triggered backup (Backup Now), the pre-backup and post-backup scripts are executed as expected.

  • When Enterprise Workloads agent does not report any status for pre-backup and post-backup scripts, the statuses of the pre-backup and post-backup scripts is N/A.

The following table summarizes the statuses of the pre-backup scripts and post-backup scripts corresponding to the statuses of the backup job execution.

Pre script status

Run backup?

Backup status

Run post script?

Post script status

Successful

Yes

Backup status is one of the following:

  • Successful

  • Failed

Yes

Post-script backup status is one of the following:

  • Successful

  • Failed

Successful

Yes

Backup status is one of the following:

  • Successful

  • Failed

Yes

Skipped (when script is unavailable at the specified location)

Failed

User defined

If backup is executed,

  • Successful

  • Failed

If backup is not executed,

  • Failed

Yes

Post-script backup status is one of the following:

  • Successful

  • Failed

Skipped

User defined

If backup is executed, the backup status is one of the following:

  • Successful

  • Failed

If backup is not executed, the backup status is,

  • Failed

No

Skipped

Guidelines to create custom backup scripts

The following are the best practices to create custom pre-backup and post-backup scripts:

  • Create the pre-backup and post-backup scripts as per the following conventions:

    • Linux File server: pre_script.sh and post_script.sh

    • Windows File server: pre_script.bat and post_script.bat

  • Ensure that the pre-backup and post-backup scripts should not trigger any process in the background.

Did this answer your question?