Tutorial: Back up SAP HANA databases in an Azure VM using Azure CLI
This tutorial describes how to back up SAP HANA database instance and SAP HANA System Replication (HSR) instance using Azure CLI.
Azure CLI is used to create and manage Azure resources from the Command Line or through scripts. This documentation details how to back up an SAP HANA database and trigger on-demand backups - all using Azure CLI. You can also perform these steps using the Azure portal.
This document assumes that you already have an SAP HANA database installed on an Azure VM. (You can also create a VM using Azure CLI).
For more information on the supported scenarios, see the support matrix for SAP HANA.
Prerequisites
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
- This tutorial requires version 2.0.30 or later of the Azure CLI.
Create a Recovery Services vault
A Recovery Services vault is a logical container that stores the backup data for each protected resource, such as Azure VMs or workloads running on Azure VMs - like SQL or HANA databases. When the backup job for a protected resource runs, it creates a recovery point inside the Recovery Services vault. You can then use one of these recovery points to restore data to a given point in time.
Create a Recovery Services vault with az backup vault create. Specify the same resource group and location as the VM you wish to protect. Learn how to create a VM using Azure CLI with this VM quickstart.
Choose a database type:
For this tutorial, we'll be using:
- a resource group named saphanaResourceGroup
- a VM named saphanaVM
- resources in the chinanorth2 location.
We'll be creating a vault named saphanaVault.
az backup vault create --resource-group saphanaResourceGroup \
--name saphanaVault \
--location chinanorth2
By default, the Recovery Services vault is set for Geo-Redundant storage. Geo-Redundant storage ensures your backup data is replicated to a secondary Azure region that's hundreds of miles away from the primary region. If the storage redundancy setting needs to be modified, use the az backup vault backup-properties set cmdlet.
az backup vault backup-properties set \
--name saphanaVault \
--resource-group saphanaResourceGroup \
--backup-storage-redundancy "LocallyRedundant/GeoRedundant"
To see if your vault was successfully created, use the az backup vault list cmdlet. You'll see the following response:
Location Name ResourceGroup
--------- --------------- -------------
chinanorth2 saphanaVault saphanaResourceGroup
Register and protect the SAP HANA instance
For the SAP HANA instance (the VM with SAP HANA installed on it) to be discovered by the Azure services, a pre-registration script must be run on the SAP HANA machine. Make sure that all the prerequisites are met before running the script. To learn more about what the script does, refer to the What the pre-registration script does section.
Once the script is run, the SAP HANA instance can be registered with the Recovery Services vault we created earlier.
Choose a database type
To register and protect database instance, follow these steps:
To register the instance, use the az backup container register command. VMResourceId is the resource ID of the VM that you created to install SAP HANA.
az backup container register --resource-group saphanaResourceGroup \ --vault-name saphanaVault \ --workload-type SAPHANA \ --backup-management-type AzureWorkload \ --resource-id VMResourceId
Note
If the VM isn't in the same resource group as the vault, then saphanaResourceGroup refers to the resource group where the vault was created.
Registering the SAP HANA instance automatically discovers all its current databases. However, to discover any new databases that may be added in the future refer to the Discovering new databases added to the registered SAP HANA instance section.
To check if the SAP HANA instance is successfully registered with your vault, use the az backup container list cmdlet. You'll see the following response:
Name Friendly Name Resource Group Type Registration Status ------------------------------------------------------ -------------- -------------------- --------- ---------------------- VMAppContainer;Compute;saphanaResourceGroup;saphanaVM saphanaVM saphanaResourceGroup AzureWorkload Registered
Note
The column “name” in the above output refers to the container name. This container name will be used in the next sections to enable backups and trigger them. Which in this case, is VMAppContainer;Compute;saphanaResourceGroup;saphanaVM.
Enable backup on SAP HANA database
The az backup protectable-item list cmdlet lists out all the databases discovered on the SAP HANA instance that you registered in the previous step.
Choose a database type
To enable database instance backup, follow these steps:
To list the database to be protected, run the following command:
az backup protectable-item list --resource-group saphanaResourceGroup \ --vault-name saphanaVault \ --workload-type SAPHANA \ --output table
You should find the database that you want to back up in this list, which will look as follows:
Name Protectable Item Type ParentName ServerName IsProtected ----------------------------- ---------------------- ------------ ----------- ------------ saphanasystem;hxe SAPHanaSystem HXE hxehost NotProtected saphanadatabase;hxe;systemdb SAPHanaDatabase HXE hxehost NotProtected saphanadatabase;hxe;hxe SAPHanaDatabase HXE hxehost NotProtected
As you can see from the above output, the SID of the SAP HANA system is HXE. In this tutorial, we'll configure backup for the
saphanadatabase;hxe;hxe
database that resides on thehxehost
server.To protect and configure the backups on a database, one at a time, we use the az backup protection enable-for-azurewl cmdlet. Provide the name of the policy that you want to use. To create a policy using CLI, use the az backup policy create cmdlet. For this tutorial, we'll be using the sapahanaPolicy policy.
az backup protection enable-for-azurewl --resource-group saphanaResourceGroup \ --vault-name saphanaVault \ --policy-name saphanaPolicy \ --protectable-item-name "saphanadatabase;hxe;hxe" \ --protectable-item-type SAPHANADatabase \ --server-name hxehost \ --workload-type SAPHANA \ --output table
To check if the above backup configuration is complete, use the az backup job list cmdlet. The output will display as follows:
Name Operation Status Item Name Start Time UTC ------------------------------------ --------------- --------- ---------- ------------------- e0f15dae-7cac-4475-a833-f52c50e5b6c3 ConfigureBackup Completed hxe 2019-12-03T03:09:210831+00:00
The az backup job list cmdlet lists out all the backup jobs (scheduled or on-demand) that have run or are currently running on the protected database, in addition to other operations like register, configure backup, and delete backup data.
Note
Azure Backup doesn’t automatically adjust for daylight saving time changes when backing up a SAP HANA database running in an Azure VM.
Modify the policy manually as needed.
Get the container name
To get container name, run the following command. Learn about this CLI command.
az backup item list --resource-group <resource group name> --vault-name <vault name>
Trigger an on-demand backup
While the section above details how to configure a scheduled backup, this section talks about triggering an on-demand backup. To do this, we use the az backup protection backup-now command.
Note
The retention period of this backup is determined by the type of on-demand backup you have run.
- On-demand full backups are retained for a minimum of 45 days and a maximum of 99 years.
- On-demand differential backups are retained as per the log retention set in the policy.
- On-demand incremental backups aren't currently supported.
Choose a database type
To run an on-demand backup, run the following command:
az backup protection backup-now --resource-group saphanaResourceGroup \
--item-name saphanadatabase;hxe;hxe \
--vault-name saphanaVault \
--container-name VMAppContainer;Compute;saphanaResourceGroup;saphanaVM \
--backup-type Full
--retain-until 01-01-2040
--output table
The output will display as follows:
Name ResourceGroup
------------------------------------ -------------
e0f15dae-7cac-4475-a833-f52c50e5b6c3 saphanaResourceGroup
The response will give you the job name. This job name can be used to track the job status using the az backup job show cmdlet.
Note
Log backups are automatically triggered and managed by SAP HANA internally.
Next steps
To learn how to restore an SAP HANA database in Azure VM using CLI, continue to the tutorial - Restore an SAP HANA database in Azure VM using CLI
To learn how to back up an SAP HANA database running in Azure VM using Azure portal, refer to Backup an SAP HANA databases on Azure VMs