Skip to main content
Pre-backup and post-backup scripts for NAS
Updated over 3 months ago

Overview

Druva allows administrators to configure pre-backup and post-backup scripts for NAS backups. The pre-backup scripts perform specific pre-backup tasks before backup jobs, while post-backup scripts perform specific post-backup tasks after backup jobs. You can configure the pre and post backup scripts in the backup policy.

When to use pre-backup and post-backup scripts?

You may want to use pre and post backup scripts to perform tasks like:

  • Stopping an anti-virus service before the backup job and restarting the service after the backup completes.

  • Backing up database dumps as flat files using the NAS agent and then deleting the dump files after the backup completes.

  • Change permissions on files or servers before a backup, and reset them after the backup completes.

Here is an example pre_script.bat file to stop services before a backup:

#pre-script to stop a service

@echo off

NET STOP Service Name

if ERRORLEVEL 1 goto error

exit

:error

echo There was a problem stopping the service

Here is an example post_script.bat file to stop services before a backup:

#post-script to start a service

@echo off

NET START Service Name

if ERRORLEVEL 1 goto error

exit

:error

echo There was a problem starting the service

Considerations

Configuring pre and post backup scripts in NAS backup policies is optional. Consider the following information before configuring pre and post backup scripts in a NAS backup policy:

  • The pre and post backup scripts must be present on the NAS proxy used to backup the configured NAS share.

  • You can only configure pre and post backup scripts for NAS shares on supported NAS proxies. For more information, see Software requirements for NAS proxy

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

    • For NFS shares, name the scriptspre_script.shand post_script.sh.

    • For SMB shares, name the scripts pre_script.bat and post_script.bat.

  • Alerts and emails are generated at the end of the last retried job if a pre-backup or post-backup script execution fails.

  • 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.

Best Practices

Make sure that the pre- and post-scripts are present in the same location for all the proxies in the Backup Proxy Pool.

Steps to configure pre-backup and post-backup scripts

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

Configure NAS pre post scripts.png
  1. Create pre-backup and post-backup scripts on the NAS proxy.

    • Script to backup NFS shares: pre_script.sh and post_script.sh

    • Script to backup SMB shares: pre_script.bat and post_script.bat

  2. Create a new backup policy or edit an existing one and perform the following tasks:

    Pre-post script settings.png
    • WINDOWS PROXY

      • Enable Scripts:Enable pre-backup and post-backup scripts execution for SMB share backups. When you enable scripts, the Scripts location field gets enabled.

      • Scripts Location:Enter the location of the folder that contains the pre-backup and post-backup scripts on the NAS proxy.

    • LINUX PROXY

      • Enable Scripts:Enable pre-backup and post-backup scripts for NFS share backups.When you enable scripts, the Scripts location field gets enabled.

      • Scripts Location:Enter the location of the folder that contains the pre-backup and post-backup scripts on the NAS proxy.

    • SKIP BACKUP IF

      • Pre-script is not present at the specified location:Select the option to skip the backup if a pre-backup script is not available at the specified script location.

      • Pre-script execution fails:Select the option to skip the backup if a pre-backup script execution fails.

      • Abort pre/post script execution if it does not complete in X Minutes/Hours:Enter the duration in minutes or hours after which Druva should abort the pre-backup or post-backup script execution. You can leave this field blank if you don’t want to enter a timeout value. In that case the pre-backup and post-backup scripts run until the script execution is complete or one year, whichever is lesser.

  3. The NAS agent executes the pre-backup and post-backup scripts from the path specified in the backup policy. 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:

    1. For pre_backup script: [ script_name, job_id ]

    2. 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. To interpret the values of the pre-script status integers, see Pre-script status.

      • backup_status_integer represents the status of the backup job execution. To interpret the values of the backup status integers, see Backup status.

Workflow of backup job execution with custom scripts

To run pre-backup and post-backup scripts during the backup job execution, you must configure them in the NAS backup policy.The following diagram depicts the life cycle of the backup job when the pre-backup scripts and post-backup scripts are disabled and enabled.

Script workflow.png

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

When you configure a NAS backup policy with pre-backup and post-backup scripts, your actions affect the script execution. The following section describes the behavior of pre-backup and post-backup script execution based on user interaction.

  • Job Retry: For every job retry operation, the pre-backup and post-backup scripts will execute before and after the backup job. Respective script failures generate alerts and emails at the end of the last retried job.

  • Canceled backup job: When you cancel a backup job during pre-backup script execution, the NAS agent executes the pre-backup script, cancels the backup job, and then executes the post-backup script. When you cancel a backup job during post-backup script execution, the Enterprise Workloads agent executes the post-backup script and then cancels the job.

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

  • Backup now: When you manually trigger a backup ( Backup Now ), the NAS agent executes the pre-backup and post-backup scripts as expected.

  • The pre-backup and post-backup scripts' status is N/A when the NAS agent does not report any status for them.

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 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,

  • Successful

  • Failed

No

Skipped

Did this answer your question?