我正在尝试为 Azure 虚拟机上的 SQL Server 实例启用自动保护。我想使用对 Azure API 的 REST 调用来完成此操作。
我正在使用
AzureWorkloadSQLAutoProtectionIntent
对象,并遵循 Microsoft Azure 关于此对象的文档。
我编写了以下 PowerShell 脚本,但它不起作用:
$url = "https://management.azure.com/Subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.RecoveryServices/vaults/$vaultName/backupFabrics/Azure/backupProtectionIntent/$intentObjectName`?api-version=$apiVersion"
# Create Headers
$headers = @{
"Authorization" = "Bearer $accessToken"
"Content-Type" = "application/json"
}
# Request Body
$parentID = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/$serverName"
$body = @{
"properties" = @{
"backupManagementType" = "AzureWorkload";
"itemId" = $itemId;
"policyId" = $policyId;
"protectionIntentItemType" = "AzureWorkloadSQLAutoProtectionIntent";
"sourceResourceId" = $parentID;
"workloadItemType" = "SQLDataBase";
}
} | ConvertTo-Json
# Invoke Rest Method
Invoke-RestMethod -Uri $url -Method PUT -Headers $headers -Body $body
当我尝试运行此脚本时,出现以下错误:
错误: “代码”:“BMSUserErrorInvalidInput”,
"message": "为通话提供的输入无效。请检查所需的输入"
我已经仔细检查了所有资源 ID,并且正在使用最新版本的 API。你能帮我理解我在这个脚本中做错了什么吗?使用对 Azure API 的 REST 调用为 SQL Server 实例启用
AzureWorkloadSQLAutoProtectionIntent
的正确步骤是什么?
提前谢谢您。
错误:
错误:“code”:“BMSUserErrorInvalidInput”,“message”:“为呼叫提供的输入无效。请检查所需的输入”
错误
BMSUserErrorInvalidInput
表示其中一个参数不正确或缺失。
检查所有资源 ID(如 subscriptionId
、resourceGroupName
、vaultName
、serverName
、itemId
和 policyId
)是否正确。
以下是调用REST开启自动保护的代码:
PUT https://management.azure.com/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/Azure/backupProtectionIntent/{intentObjectName}?api-version=2024-04-01
Content-Type: application/json
Authorization: Bearer {accessToken}
{
"properties": {
"backupManagementType": "AzureWorkload",
"itemId": "{itemId}",
"policyId": "{policyId}",
"protectionIntentItemType": "AzureWorkloadSQLAutoProtectionIntent",
"sourceResourceId": "{parentID}",
"workloadItemType": "SQLDataBase"
}
}