Automatically trigger on-demand SAP HANA on Azure VM Backup for multiple Databases - Code Sample

@20aman    Aug 24, 2021

Let's assume you have various SAP HANA databases on Azure VMs that are being backed up in Azure Recovery Services Vault using the Backup services i.e. the daily backup. Before performing any major activity in your environment, you will want to take an on-demand backup. This helps you to have a fallback option if anything goes wrong during the activity. To extend the expiry date you may want to update the policy temporarily as the on-demand backup for SAP HANA on Azure VMs, doesn't allow the feature to specify the expiry date.

The script I present in this post automates the triggering of this on-demand backup for multiple SAP HANA databases. The script takes the name of VMs and related SAP HANA database information in a csv file as input.

NOTE: As the feature to trigger the SAP HANA database is available only with the CLI cmdlet, we are using the CLI command. Please ensure that you have AZ CLI also installed in your environment by following the instructions here: How to install the Azure CLI.

Script location

The latest version of the script can be found in GitHub here: Trigger-AzSAPHANAOnDemandBackup

The input CSV file sample is also located at the same location. Use this file to provide the VM names and related SAP HANA database information as an input to the script. Update the path to this file in the script input variables. Update this file as per your environment.

Script Working

The script starts by checking if the input config file (with VM names) exists or not. If not, then the script prints the message to check the path and exit. It then imports the CSV file. Then it sets the context to the right recovery services vault and starts iterating through the VMs. Then it sets the item and container variables as below.

$itemName = "SAPHanaDatabase;$instanceName;$databaseName"
$containerName = "VMAppContainer;Compute;$VMResourceGroup;$vmName"

Finally, it triggers the on-demand backup using the below az cli command.

az backup protection backup-now --resource-group $rgOfVault --item-name $itemName --vault-name $vaultName --container-name $containerName --backup-type Full --output table

I hope this script helps you save lots of time during on-demand backup creation. If you have any improvements you would like to see in the script feel free to provide that as a comment here or a pull request on GitHub.





Comments powered by Disqus