I am trying to enable autoprotect for a SQL Server instance on an Azure virtual machine. I want to do this using a REST call to the Azure API.
I’m using the AzureWorkloadSQLAutoProtectionIntent
object and have followed Microsoft Azure’s documentation regarding this object.
I have written the following PowerShell script, but it is not working:
$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
When I try to run this script, I get the following error:
Error:
"code": "BMSUserErrorInvalidInput",
"message": "Input provided for the call is invalid. Please check the required inputs"
I’ve double-checked all my resource IDs and am using the latest version of the API. Can you help me understand what I’m doing wrong in this script? What are the correct steps to enable AzureWorkloadSQLAutoProtectionIntent
for a SQL Server instance using a REST call to the Azure API?
Thank you in advance.
2
Answers
I was able to make it work. My backup container name was missing the 'VMAppContainer' value:
You can find the container using the following documentation:
→ https://learn.microsoft.com/en-us/rest/api/backup/protection-containers/get?view=rest-backup-2024-04-01&tabs=HTTP
Here is my final code:
ERROR:
The error
BMSUserErrorInvalidInput
indicates that one of the parameters is incorrect or missing.Check if all resource IDs, like
subscriptionId
,resourceGroupName
,vaultName
,serverName
,itemId
, andpolicyId
, are correct.The below is the code to call the REST to enable automatic protection: