教程:使用 Azure CLI 备份 Azure VM 中的 SAP HANA 数据库Tutorial: Back up SAP HANA databases in an Azure VM using Azure CLI

Azure CLI 用于从命令行或通过脚本创建和管理 Azure 资源。Azure CLI is used to create and manage Azure resources from the Command Line or through scripts. 本文档详细介绍了如何备份 SAP HANA 数据库并触发按需备份 - 所有这些操作都使用 Azure CLI。This documentation details how to back up an SAP HANA database and trigger on-demand backups - all using Azure CLI. 还可以使用 Azure 门户执行这些步骤。You can also perform these steps using the Azure portal.

本文档假定你已在 Azure VM 上安装了 SAP HANA 数据库。This document assumes that you already have an SAP HANA database installed on an Azure VM. (也可以使用 Azure CLI 创建 VM)。(You can also create a VM using Azure CLI). 完成本教程后,可执行以下操作:By the end of this tutorial, you'll be able to:

  • 创建恢复服务保管库Create a recovery services vault
  • 注册 SAP HANA 实例并发现该实例上的数据库Register SAP HANA instance and discover database(s) on it
  • 在 SAP HANA 数据库上启用备份Enable backup on an SAP HANA database
  • 触发按需备份Trigger an on-demand backup

查看目前针对 SAP HANA 提供支持的场景Check out the scenarios that we currently support for SAP HANA.

若要在本地安装和使用 CLI,必须运行 Azure CLI 版本 xx.xxx.x 或更高版本。To install and use the CLI locally, you must run Azure CLI version xx.xxx.x or later. 若要查找 CLI 版本,请运行 az --versionTo find the CLI version, run az --version. 如需进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install the Azure CLI.

创建恢复服务保管库Create a recovery services vault

恢复服务保管库是一个逻辑容器,用于存储每个受保护资源(例如 Azure VM)或在 Azure VM 上运行的工作负载(例如 SQL 或 HANA 数据库)的备份数据。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.

使用 az backup vault create 创建恢复服务保管库。Create a Recovery Services vault with az backup vault create. 指定与想要保护的 VM 相同的资源组和位置。Specify the same resource group and location as the VM you wish to protect. 了解如何通过此 VM 快速入门使用 Azure CLI 创建 VM。Learn how to create a VM using Azure CLI with this VM quickstart.

本教程将使用以下内容:For this tutorial, we'll be using the following:

  • 名为 saphanaResourceGroup 的资源组a resource group named saphanaResourceGroup
  • 名为 saphanaVM 的 VMa VM named saphanaVM
  • chinanorth2 位置的资源。resources in the chinanorth2 location.

我们将创建一个名为 saphanaVault 的保管库。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. 异地冗余存储可确保将备份数据复制到距主区域数百英里以外的辅助 Azure 区域。Geo-Redundant storage ensures your backup data is replicated to a secondary Azure region that is hundreds of miles away from the primary region. 如果存储冗余设置需要修改,请使用 az backup vault backup-properties set cmdlet。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"

若要查看是否已成功创建保管库,请使用 az backup vault list cmdlet。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

注册并保护 SAP HANA 实例Register and protect the SAP HANA instance

对于要由 Azure 服务发现的 SAP HANA 实例(该实例上安装有包含 SAP HANA 的 VM),必须在 SAP HANA 计算机上运行预注册脚本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.

脚本运行后,可通过之前创建的恢复服务保管库注册 SAP HANA 实例。Once the script is run, the SAP HANA instance can be registered with the recovery services vault we created earlier. 若要注册实例,请使用 az backup container register cmdlet。To register the instance, use the az backup container register cmdlet. VMResourceId 是你创建的用于安装 SAP HANA 的 VM 资源 ID。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 \
    --location chinanorth2 \
    --workload-type SAPHANA \
    --backup-management-type AzureWorkload \
    --resource-id VMResourceId

备注

如果 VM 与保管库不在同一个资源组中,则 saphanaResourceGroup 引用创建保管库所在的资源组。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.

注册 SAP HANA 实例会自动发现其所有当前数据库。Registering the SAP HANA instance automatically discovers all its current databases. 但是,若要发现将来可能添加的任何新数据库,请参考发现已添加到已注册 SAP HANA 的新数据库实例部分。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.

若要检查 SAP HANA 实例是否已成功注册到保管库,请使用 az backup container list cmdlet。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

备注

以上输出中的“name”列是指容器名。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. 在本例中,为 VMAppContainer;Compute;saphanaResourceGroup;saphanaVM。Which in this case, is VMAppContainer;Compute;saphanaResourceGroup;saphanaVM.

在 SAP HANA 数据库上启用备份Enable backup on SAP HANA database

az backup protectable-item list cmdlet 列出了在上一步中注册的 SAP HANA 实例上发现的所有数据库。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.

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

从上面的输出中可以看出,SAP HANA 系统的 SID 是 HXE。As you can see from the above output, the SID of the SAP HANA system is HXE. 在本教程中,我们将为 hxehost 服务器上的 saphanadatabase;hxe;hxe 数据库配置备份 。In this tutorial, we'll configure backup for the saphanadatabase;hxe;hxe database that resides on the hxehost server.

若要在数据库上一次保护和配置一个备份,请使用 az backup protection enable-for-azurewl cmdlet。To protect and configure backup 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. 若要使用 CLI 创建策略,请使用 az backup policy create cmdlet。To create a policy using CLI, use the az backup policy create cmdlet. 本教程将使用 sapahanaPolicy 策略。For this tutorial, we'll be using the sapahanaPolicy policy.

az backup protection enable-for-azurewl --resource-group saphanaResourceGroup \
    --policy-name saphanaPolicy \
    --protectable-item-name saphanadatabase;hxe;hxe  \
    --protectable-item-type SAPHANADatabse \
    --server-name hxehost \
    --workload-type SAPHANA \
    --output table

可以使用 az backup job list cmdlet 检查以上备份配置是否已完成。You can check if the above backup configuration is complete using 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  

az backup job list cmdlet 列出了在受保护数据库上已运行或当前正在运行的所有(计划或按需)备份作业,以及注册、配置备份、删除备份数据等其他操作。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, delete backup data etc.

备注

备份 Azure VM 中运行的 SAP HANA 数据库时,Azure 备份不会针对夏令时更改自动进行调整。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.

触发按需备份Trigger an on-demand backup

尽管上述部分详细介绍了如何配置计划的备份,但本部分介绍如何触发按需备份。While the above section details how to configure a scheduled backup, this section talks about triggering an on-demand backup. 为此,我们现在使用 az backup protection backup-now cmdlet。To do this, we use the az backup protection backup-now cmdlet.

备注

按需备份的保留策略由数据库的基础保留策略决定。The retention policy of an on-demand backup is determined by the underlying retention policy for the database.

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. 此作业名可用于使用 az backup job show cmdlet 来跟踪作业状态。This job name can be used to track the job status using the az backup job show cmdlet.

备注

除了安排完整备份或差异备份,当前还可以手动触发它们。In addition to scheduling a full or differential backup, they can also be currently triggered manually. 日志备份由 SAP HANA 内部自动触发和管理。Log backups are automatically triggered and managed by SAP HANA internally.

Azure 备份目前不支持增量备份。Incremental backups are not currently supported by Azure Backup.

后续步骤Next steps