|
| 1 | +--- |
| 2 | +title: Tutorial - SAP HANA DB backup on Azure using CLI |
| 3 | +description: In this tutorial, learn how to back up SAP HANA databases running on an Azure VM to an Azure Backup Recovery Services vault using Azure CLI. |
| 4 | +ms.topic: tutorial |
| 5 | +ms.date: 12/4/2019 |
| 6 | +--- |
| 7 | + |
| 8 | +# Tutorial: Back up SAP HANA databases in an Azure VM using Azure CLI |
| 9 | + |
| 10 | +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](https://docs.microsoft.com/azure/backup/backup-azure-sap-hana-database). |
| 11 | + |
| 12 | +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](https://docs.microsoft.com/azure/virtual-machines/linux/quick-create-cli)). By the end of this tutorial, you'll be able to: |
| 13 | + |
| 14 | +> [!div class="checklist"] |
| 15 | +> |
| 16 | +> * Create a recovery services vault |
| 17 | +> * Register SAP HANA instance and discover database(s) on it |
| 18 | +> * Enable backup on an SAP HANA database |
| 19 | +> * Trigger an on-demand backup |
| 20 | +
|
| 21 | +Check out the [scenarios that we currently support](https://docs.microsoft.com/azure/backup/sap-hana-backup-support-matrix#scenario-support) for SAP HANA. |
| 22 | + |
| 23 | +[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)] |
| 24 | + |
| 25 | +To install and use the CLI locally, you must run Azure CLI version xx.xxx.x or later. To find the CLI version, run `az --version`. If you need to install or upgrade, see [Install the Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli). |
| 26 | + |
| 27 | +## Create a recovery services vault |
| 28 | + |
| 29 | +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. |
| 30 | + |
| 31 | +Create a Recovery Services vault with [az backup vault create](https://docs.microsoft.com/cli/azure/backup/vault#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](https://docs.microsoft.com/azure/virtual-machines/linux/quick-create-cli). |
| 32 | + |
| 33 | +For this tutorial, we'll be using the following: |
| 34 | + |
| 35 | +* a resource group named *saphanaResourceGroup* |
| 36 | +* a VM named *saphanaVM* |
| 37 | +* resources in the *westus2* location. |
| 38 | + |
| 39 | +We'll be creating a vault named *saphanaVault*. |
| 40 | + |
| 41 | +```azurecli-interactive |
| 42 | +az backup vault create --resource-group saphanaResourceGroup \ |
| 43 | + --name saphanaVault \ |
| 44 | + --location westus2 |
| 45 | +``` |
| 46 | + |
| 47 | +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 is 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](https://docs.microsoft.com/cli/azure/backup/vault/backup-properties?view=azure-cli-latest#az-backup-vault-backup-properties-set) cmdlet. |
| 48 | + |
| 49 | +```azurecli |
| 50 | +az backup vault backup-properties set \ |
| 51 | + --name saphanaVault \ |
| 52 | + --resource-group saphanaResourceGroup \ |
| 53 | + --backup-storage-redundancy "LocallyRedundant/GeoRedundant" |
| 54 | +``` |
| 55 | + |
| 56 | +To see if your vault was successfully created, use the [az backup vault list](https://docs.microsoft.com/cli/azure/backup/vault?view=azure-cli-latest#az-backup-vault-list) cmdlet. You'll see the following response: |
| 57 | + |
| 58 | +```output |
| 59 | +Location Name ResourceGroup |
| 60 | +--------- --------------- ------------- |
| 61 | +westus2 saphanaVault saphanaResourceGroup |
| 62 | +``` |
| 63 | + |
| 64 | +## Register and protect the SAP HANA instance |
| 65 | + |
| 66 | +For the SAP HANA instance (the VM with SAP HANA installed on it) to be discovered by the Azure services, a [pre-registration script](https://aka.ms/scriptforpermsonhana) must be run on the SAP HANA machine. Make sure that all the [prerequisites](https://docs.microsoft.com/azure/backup/tutorial-backup-sap-hana-db#prerequisites) are met before running the script. To learn more about what the script does, refer to the [setting up permissions](https://docs.microsoft.com/azure/backup/tutorial-backup-sap-hana-db#setting-up-permissions) section. |
| 67 | + |
| 68 | +Once the script is run, the SAP HANA instance can be registered with the recovery services vault we created earlier. To register the instance, use the [az backup container register](https://docs.microsoft.com/cli/azure/backup/container?view=azure-cli-latest#az-backup-container-register) cmdlet. *VMResourceId* is the resource ID of the VM that you created to install SAP HANA. |
| 69 | + |
| 70 | +```azurecli-interactive |
| 71 | +az backup container register --resource-group saphanaResourceGroup \ |
| 72 | + --vault-name saphanaVault \ |
| 73 | + --location westus2 \ |
| 74 | + --workload-type SAPHANA \ |
| 75 | + --backup-management-type AzureWorkload \ |
| 76 | + --resource-id VMResourceId |
| 77 | +``` |
| 78 | + |
| 79 | +>[!NOTE] |
| 80 | +>If the VM is not in the same resource group as the vault, then *saphanaResourceGroup* refers to the resource group where the vault was created. |
| 81 | +
|
| 82 | +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](tutorial-sap-hana-manage-cli.md#protect-new-databases-added-to-an-sap-hana-instance) instance section. |
| 83 | + |
| 84 | +To check if the SAP HANA instance is successfully registered with your vault, use the [az backup container list](https://docs.microsoft.com/cli/azure/backup/container?view=azure-cli-latest#az-backup-container-list) cmdlet. You'll see the following response: |
| 85 | + |
| 86 | +```output |
| 87 | +Name Friendly Name Resource Group Type Registration Status |
| 88 | +------------------------------------------------------ -------------- -------------------- --------- ---------------------- |
| 89 | +VMAppContainer;Compute;saphanaResourceGroup;saphanaVM saphanaVM saphanaResourceGroup AzureWorkload Registered |
| 90 | +``` |
| 91 | + |
| 92 | +>[!NOTE] |
| 93 | +> 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*. |
| 94 | +
|
| 95 | +## Enable backup on SAP HANA database |
| 96 | + |
| 97 | +The [az backup protectable-item list](https://docs.microsoft.com/cli/azure/backup/protectable-item?view=azure-cli-latest#az-backup-protectable-item-list) cmdlet lists out all the databases discovered on the SAP HANA instance that you registered in the previous step. |
| 98 | + |
| 99 | +```azurecli-interactive |
| 100 | +az backup protectable-item list --resource-group saphanaResourceGroup \ |
| 101 | + --vault-name saphanaVault \ |
| 102 | + --workload-type SAPHANA \ |
| 103 | + --output table |
| 104 | +``` |
| 105 | + |
| 106 | +You should find the database that you want to back up in this list, which will look as follows: |
| 107 | + |
| 108 | +```output |
| 109 | +Name Protectable Item Type ParentName ServerName IsProtected |
| 110 | +----------------------------- ---------------------- ------------ ----------- ------------ |
| 111 | +saphanasystem;hxe SAPHanaSystem HXE hxehost NotProtected |
| 112 | +saphanadatabase;hxe;systemdb SAPHanaDatabase HXE hxehost NotProtected |
| 113 | +saphanadatabase;hxe;hxe SAPHanaDatabase HXE hxehost NotProtected |
| 114 | +``` |
| 115 | + |
| 116 | +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 the *hxehost* server. |
| 117 | + |
| 118 | +To protect and configure backup on a database, one at a time, we use the [az backup protection enable-for-azurewl](https://docs.microsoft.com/cli/azure/backup/protection?view=azure-cli-latest#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](https://docs.microsoft.com//cli/azure/backup/policy?view=azure-cli-latest#az-backup-policy-create) cmdlet. For this tutorial, we'll be using the *sapahanaPolicy* policy. |
| 119 | + |
| 120 | +```azurecli-interactive |
| 121 | +az backup protection enable-for-azurewl --resource-group saphanaResourceGroup \ |
| 122 | + --policy-name saphanaPolicy \ |
| 123 | + --protectable-item-name saphanadatabase;hxe;hxe \ |
| 124 | + --protectable-item-type SAPHANADatabse \ |
| 125 | + --server-name hxehost \ |
| 126 | + --workload-type SAPHANA \ |
| 127 | + --output table |
| 128 | +``` |
| 129 | + |
| 130 | +You can check if the above backup configuration is complete using the [az backup job list](https://docs.microsoft.com/cli/azure/backup/job?view=azure-cli-latest#az-backup-job-list) cmdlet. The output will display as follows: |
| 131 | + |
| 132 | +```output |
| 133 | +Name Operation Status Item Name Start Time UTC |
| 134 | +------------------------------------ --------------- --------- ---------- ------------------- |
| 135 | +e0f15dae-7cac-4475-a833-f52c50e5b6c3 ConfigureBackup Completed hxe 2019-12-03T03:09:210831+00:00 |
| 136 | +``` |
| 137 | + |
| 138 | +The [az backup job list](https://docs.microsoft.com/cli/azure/backup/job?view=azure-cli-latest#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, delete backup data etc. |
| 139 | + |
| 140 | +## Trigger an on-demand backup |
| 141 | + |
| 142 | +While the above section 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](https://docs.microsoft.com/cli/azure/backup/protection#az-backup-protection-backup-now) cmdlet. |
| 143 | + |
| 144 | +>[!NOTE] |
| 145 | +> The retention policy of an on-demand backup is determined by the underlying retention policy for the database. |
| 146 | +
|
| 147 | +```azurecli-interactive |
| 148 | +az backup protection backup-now --resource-group saphanaResourceGroup \ |
| 149 | + --item-name saphanadatabase;hxe;hxe \ |
| 150 | + --vault-name saphanaVault \ |
| 151 | + --container-name VMAppContainer;Compute;saphanaResourceGroup;saphanaVM \ |
| 152 | + --backup-type Full |
| 153 | + --retain-until 01-01-2040 |
| 154 | + --output table |
| 155 | +``` |
| 156 | + |
| 157 | +The output will display as follows: |
| 158 | + |
| 159 | +```output |
| 160 | +Name ResourceGroup |
| 161 | +------------------------------------ ------------- |
| 162 | +e0f15dae-7cac-4475-a833-f52c50e5b6c3 saphanaResourceGroup |
| 163 | +``` |
| 164 | + |
| 165 | +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](https://docs.microsoft.com/cli/azure/backup/job?view=azure-cli-latest#az-backup-job-show) cmdlet. |
| 166 | + |
| 167 | +>[!NOTE] |
| 168 | +>In addition to scheduling a full or differential backup, they can also be currently triggered manually. Log backups are automatically triggered and managed by SAP HANA internally. |
| 169 | +> |
| 170 | +> Incremental backups are not currently supported by Azure Backup. |
| 171 | +
|
| 172 | +## Next steps |
| 173 | + |
| 174 | +* 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](tutorial-sap-hana-restore-cli.md) |
| 175 | + |
| 176 | +* 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](https://docs.microsoft.com/azure/backup/backup-azure-sap-hana-database) |
0 commit comments