教程:使用 Azure CLI 管理 Azure VM 中的 SAP HANA 数据库Tutorial: Manage 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. 本文档详细介绍如何在 Azure VM 上管理已备份的 SAP HANA 数据库 - 所有这些操作都使用 Azure CLI。This documentation details how to manage a backed-up SAP HANA database on Azure VM - all using Azure CLI. 还可以使用 Azure 门户执行这些步骤。You can also perform these steps using the Azure portal.

使用 Azure CLI 运行 CLI 命令。Use Azure CLI to run CLI commands.

完成本教程后,可执行以下操作:By the end of this tutorial, you'll be able to:

  • 监视备份和还原作业Monitor backup and restore jobs
  • 保护添加到 SAP HANA 实例的新数据库Protect new databases added to an SAP HANA instance
  • 更改策略Change the policy
  • 停止保护Stop protection
  • 恢复保护Resume protection

如果你已按照使用 CLI 在 Azure 中备份 SAP HANA 数据库中的说明备份 SAP HANA 数据库,则要使用以下资源:If you've used Back up an SAP HANA database in Azure using CLI to back up your SAP HANA database, then you're using the following resources:

  • 名为 saphanaResourceGroup 的资源组 a resource group named saphanaResourceGroup
  • 名为 saphanaVault 的保管库 a vault named saphanaVault
  • 名为 VMAppContainer;Compute;saphanaResourceGroup;saphanaVM 的受保护容器 protected container named VMAppContainer;Compute;saphanaResourceGroup;saphanaVM
  • 名为 saphanadatabase;hxe;hxe 的已备份数据库/项 backed-up database/item named saphanadatabase;hxe;hxe
  • chinanorth2 区域中的资源resources in the chinanorth2 region

借助 Azure CLI 可轻松管理使用 Azure 备份进行备份的 Azure VM 上运行的 SAP HANA 数据库。Azure CLI makes it easy to manage an SAP HANA database running on an Azure VM that's backed-up using Azure Backup. 本教程详细介绍了每个管理操作。This tutorial details each of the management operations.

监视备份和还原作业Monitor backup and restore jobs

若要监视已完成或当前正在运行的作业(备份或还原),请使用 az backup job list cmdlet。To monitor completed or currently running jobs (backup or restore), use the az backup job list cmdlet. 通过 CLI,还可暂停当前正在运行的作业等待作业完成CLI also allows you to suspend a currently running job or wait until a job completes.

az backup job list --resource-group saphanaResourceGroup \
    --vault-name saphanaVault \
    --output table

输出将如下所示:The output will look something like this:

Name                                  Operation              Status      Item Name       Start Time UTC
------------------------------------  ---------------        ---------   ----------      -------------------  
e0f15dae-7cac-4475-a833-f52c50e5b6c3  ConfigureBackup        Completed   hxe             2019-12-03T03:09:210831+00:00  
ccdb4dce-8b15-47c5-8c46-b0985352238f  Backup (Full)          Completed   hxe [hxehost]   2019-12-01T10:30:58.867489+00:00
4980af91-1090-49a6-ab96-13bc905a5282  Backup (Differential)  Completed   hxe [hxehost]   2019-12-01T10:36:00.563909+00:00
F7c68818-039f-4a0f-8d73-e0747e68a813  Restore (Log)          Completed   hxe [hxehost]   2019-12-03T05:44:51.081607+00:00

更改策略Change policy

若要更改 SAP HANA 备份配置基础上的策略,请使用 az backup policy set cmdlet。To change the policy underlying the SAP HANA backup configuration, use the az backup policy set cmdlet. 此 cmdlet 中的 name 参数是指要更改其策略的备份项。The name parameter in this cmdlet refers to the backup item whose policy we want to change. 对于本教程,我们会将 SAP HANA 数据库 saphanadatabase;hxe;hxe 的策略替换为新策略 newsaphanaPolicy 。For this tutorial, we'll be replacing the policy of our SAP HANA database saphanadatabase;hxe;hxe with a new policy newsaphanaPolicy. 可使用 az backup policy create cmdlet 创建新策略。New policies can be created using the az backup policy create cmdlet.

az backup item set policy --resource-group saphanaResourceGroup \
    --vault-name saphanaVault \
    --container-name VMAppContainer;Compute;saphanaResourceGroup;saphanaVM \
    --policy-name newsaphanaPolicy \
    --name saphanadatabase;hxe;hxe \

输出应如下所示:The output should look like this:

Name                                  Resource Group
------------------------------------- --------------
cb110094-9b15-4c55-ad45-6899200eb8dd  SAPHANA

创建增量备份策略Create incremental backup policy

若要创建增量备份策略,请使用以下参数执行 az backup policy create 命令:To create an incremental backup policy, execute the az backup policy create command with the following parameters:

  • --backup-management-type - Azure 工作负载--backup-management-type - Azure Workload
  • --workload-type - SAPHana--workload-type - SAPHana
  • --name - 策略的名称--name - Name of the policy
  • --policy - JSON 文件,其中包含有关计划和保留的相应详细信息--policy - JSON file with appropriate details for schedule and retention
  • --resource-group - 保管库的资源组--resource-group - Resource group of the vault
  • --vault-name - 保管库的名称--vault-name - Name of the vault

例如:Example:

az backup policy create --resource-group saphanaResourceGroup --vault-name saphanaVault --name sappolicy --backup-management-type AzureWorkload --policy sappolicy.json --workload-type SAPHana

示例 JSON (sappolicy.json):Sample JSON (sappolicy.json):

  "eTag": null,
  "id": "/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/saphanaResourceGroup/providers/Microsoft.RecoveryServices/vaults/saphanaVault/backupPolicies/sappolicy",
  "location": null,
  "name": "sappolicy",
  "properties": {
    "backupManagementType": "AzureWorkload",
    "makePolicyConsistent": null,
    "protectedItemsCount": 0,
    "settings": {
      "isCompression": false,
      "issqlcompression": false,
      "timeZone": "UTC"
    },
    "subProtectionPolicy": [
      {
        "policyType": "Full",
        "retentionPolicy": {
          "dailySchedule": null,
          "monthlySchedule": {
            "retentionDuration": {
              "count": 60,
              "durationType": "Months"
            },
            "retentionScheduleDaily": null,
            "retentionScheduleFormatType": "Weekly",
            "retentionScheduleWeekly": {
              "daysOfTheWeek": [
                "Sunday"
              ],
              "weeksOfTheMonth": [
                "First"
              ]
            },
            "retentionTimes": [
              "2021-01-19T00:30:00+00:00"
            ]
          },
          "retentionPolicyType": "LongTermRetentionPolicy",
          "weeklySchedule": {
            "daysOfTheWeek": [
              "Sunday"
            ],
            "retentionDuration": {
              "count": 104,
              "durationType": "Weeks"
            },
            "retentionTimes": [
              "2021-01-19T00:30:00+00:00"
            ]
          },
          "yearlySchedule": {
            "monthsOfYear": [
              "January"
            ],
            "retentionDuration": {
              "count": 10,
              "durationType": "Years"
            },
            "retentionScheduleDaily": null,
            "retentionScheduleFormatType": "Weekly",
            "retentionScheduleWeekly": {
              "daysOfTheWeek": [
                "Sunday"
              ],
              "weeksOfTheMonth": [
                "First"
              ]
            },
            "retentionTimes": [
              "2021-01-19T00:30:00+00:00"
            ]
          }
        },
        "schedulePolicy": {
          "schedulePolicyType": "SimpleSchedulePolicy",
          "scheduleRunDays": [
            "Sunday"
          ],
          "scheduleRunFrequency": "Weekly",
          "scheduleRunTimes": [
            "2021-01-19T00:30:00+00:00"
          ],
          "scheduleWeeklyFrequency": 0
        }
      },
      {
        "policyType": "Incremental",
        "retentionPolicy": {
          "retentionDuration": {
            "count": 30,
            "durationType": "Days"
          },
          "retentionPolicyType": "SimpleRetentionPolicy"
        },
        "schedulePolicy": {
          "schedulePolicyType": "SimpleSchedulePolicy",
          "scheduleRunDays": [
            "Monday",
            "Tuesday",
            "Wednesday",
            "Thursday",
            "Friday",
            "Saturday"
          ],
          "scheduleRunFrequency": "Weekly",
          "scheduleRunTimes": [
            "2017-03-07T02:00:00+00:00"
          ],
          "scheduleWeeklyFrequency": 0
        }
      },
      {
        "policyType": "Log",
        "retentionPolicy": {
          "retentionDuration": {
            "count": 15,
            "durationType": "Days"
          },
          "retentionPolicyType": "SimpleRetentionPolicy"
        },
        "schedulePolicy": {
          "scheduleFrequencyInMins": 120,
          "schedulePolicyType": "LogSchedulePolicy"
        }
      }
    ],
    "workLoadType": "SAPHanaDatabase"
  },
  "resourceGroup": "saphanaResourceGroup",
  "tags": null,
  "type": "Microsoft.RecoveryServices/vaults/backupPolicies"
} 

成功创建策略后,命令的输出将显示执行命令时作为参数传递的策略 JSON。Once the policy is created successfully, the output of the command will display the policy JSON that you passed as a parameter while executing the command.

可以修改策略的以下部分,以指定所需的备份频率和增量备份的保留时间。You can modify the following section of the policy to specify the desired backup frequency and retention for incremental backups.

例如:For example:

{
  "policyType": "Incremental",
  "retentionPolicy": {
    "retentionDuration": {
      "count": 30,
      "durationType": "Days"
    },
    "retentionPolicyType": "SimpleRetentionPolicy"
  },
  "schedulePolicy": {
    "schedulePolicyType": "SimpleSchedulePolicy",
    "scheduleRunDays": [
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday"
    ],
    "scheduleRunFrequency": "Weekly",
    "scheduleRunTimes": [
      "2017-03-07T02:00:00+00:00"
    ],
    "scheduleWeeklyFrequency": 0
  }
}

例如:Example:

如果要仅在星期六进行增量备份并将其保留 60 天,请在策略中进行以下更改:If you want to have incremental backups only on Saturday and retain them for 60 days, make the following changes in the policy:

  • 将 retentionDuration 计数更新为 60 天Update retentionDuration count to 60 days
  • 仅将周六指定为 ScheduleRunDaysSpecify only Saturday as ScheduleRunDays
 {
  "policyType": "Incremental",
  "retentionPolicy": {
    "retentionDuration": {
      "count": 60,
      "durationType": "Days"
    },
    "retentionPolicyType": "SimpleRetentionPolicy"
  },
  "schedulePolicy": {
    "schedulePolicyType": "SimpleSchedulePolicy",
    "scheduleRunDays": [
      "Saturday"
    ],
    "scheduleRunFrequency": "Weekly",
    "scheduleRunTimes": [
      "2017-03-07T02:00:00+00:00"
    ],
    "scheduleWeeklyFrequency": 0
  }
}

保护添加到 SAP HANA 实例的新数据库Protect new databases added to an SAP HANA instance

使用恢复服务保管库注册 SAP HANA 实例会自动发现该实例上的所有数据库。Registering an SAP HANA instance with a Recovery Services vault automatically discovers all the databases on this instance.

但是,如果以后将新数据库添加到 SAP HANA 实例,请使用 az backup protectable-item initialize cmdlet。However, in cases when new databases are added to the SAP HANA instance later, use the az backup protectable-item initialize cmdlet. 此 cmdlet 会发现添加的新数据库。This cmdlet discovers the new databases added.

az backup protectable-item initialize --resource-group saphanaResourceGroup \
    --vault-name saphanaVault \
    --container-name VMAppContainer;Compute;saphanaResourceGroup;saphanaVM \
    --workload-type SAPHANA

然后,使用 az backup protectable-item list cmdlet 列出已在 SAP HANA 实例上发现的所有数据库。Then use the az backup protectable-item list cmdlet to list all the databases that have been discovered on your SAP HANA instance. 但是,此列表会排除已配置备份的数据库。This list, however, excludes those databases on which backup has already been configured. 发现要备份的数据库后,请参阅在 SAP HANA 数据库上启用备份Once the database to be backed-up is discovered, refer to Enable backup on SAP HANA database.

az backup protectable-item list --resource-group saphanaResourceGroup \
    --vault-name saphanaVault \
    --workload-type SAPHANA \
    --output table

要备份的新数据库将显示在此列表中,如下所示:The new database that you want to back up will show 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;newhxe      SAPHanaDatabase          HXE           hxehost       NotProtected

停止对 SAP HANA 数据库的保护Stop protection for an SAP HANA database

可以通过以下几种方式停止保护 SAP HANA 数据库:You can stop protecting an SAP HANA database in a couple of ways:

  • 停止所有将来的备份作业并删除所有恢复点。Stop all future backup jobs and delete all recovery points.
  • 停止所有将来的备份作业,且恢复点保留不变。Stop all future backup jobs and leave the recovery points intact.

如果选择保留恢复点,请记住以下详细内容:If you choose to leave recovery points, keep these details in mind:

  • 所有恢复点都将永久保持不变,所有删除操作都将在停止保护时停止,并保留数据。All recovery points will remain intact forever, and all pruning will stop at stop protection with retain data.
  • 你将为受保护的实例和使用的存储付费。You'll be charged for the protected instance and the consumed storage.
  • 如果在不停止备份的情况下删除数据源,则新备份会失败。If you delete a data source without stopping backups, new backups will fail.

让我们进一步了解停止保护的方法。Let's look at each of the ways to stop protection in more detail.

停止保护并保留数据Stop protection with retain data

若要停止保护并保留数据,请使用 az backup protection disable cmdlet。To stop protection with retain data, use the az backup protection disable cmdlet.

az backup protection disable --resource-group saphanaResourceGroup \
    --vault-name saphanaVault \
    --container-name VMAppContainer;Compute;saphanaResourceGroup;saphanaVM \
    --item-name saphanadatabase;hxe;hxe \
    --workload-type SAPHANA \
    --output table

输出应如下所示:The output should look like this:

Name                                  ResourceGroup
------------------------------------  ---------------  
g0f15dae-7cac-4475-d833-f52c50e5b6c3  saphanaResourceGroup

若要检查此操作的状态,请使用 az backup job show cmdlet。To check the status of this operation, use the az backup job show cmdlet.

停止保护且不保留数据Stop protection without retain data

若要停止保护且不保留数据,请使用 az backup protection disable cmdlet。To stop protection without retain data, use the az backup protection disable cmdlet.

az backup protection disable --resource-group saphanaResourceGroup \
    --vault-name saphanaVault \
    --container-name VMAppContainer;Compute;saphanaResourceGroup;saphanaVM \
    --item-name saphanadatabase;hxe;hxe \
    --workload-type SAPHANA \
    --delete-backup-data true \
    --output table

输出应如下所示:The output should look like this:

Name                                  ResourceGroup
------------------------------------  ---------------  
g0f15dae-7cac-4475-d833-f52c50e5b6c3  saphanaResourceGroup

若要检查此操作的状态,请使用 az backup job show cmdlet。To check the status of this operation, use the az backup job show cmdlet.

恢复保护Resume protection

如果停止对 SAP HANA 数据库的保护且保留数据,可在稍后恢复保护。When you stop protection for the SAP HANA database with retain data, you can later resume protection. 如果不保留备份的数据,则无法恢复保护。If you don't retain the backed-up data, you won't be able to resume protection.

若要恢复保护,请使用 az backup protection resume cmdlet。To resume protection, use the az backup protection resume cmdlet.

az backup protection resume --resource-group saphanaResourceGroup \
    --vault-name saphanaVault \
    --container-name VMAppContainer;Compute;saphanaResourceGroup;saphanaVM \
    --policy-name saphanaPolicy \
    --output table

输出应如下所示:The output should look like this:

Name                                  ResourceGroup
------------------------------------  ---------------  
b2a7f108-1020-4529-870f-6c4c43e2bb9e  saphanaResourceGroup

若要检查此操作的状态,请使用 az backup job show cmdlet。To check the status of this operation, use the az backup job show cmdlet.

后续步骤Next steps