Я пытаюсь создать azure хранилище резервных копий служб восстановления, используя PowerShell вместе с шаблонами arm. Для этого развертывания я создал шаблон развертывания и шаблон параметров. Я редактирую файл параметров шаблона json с помощью powershell с помощью ConvertFrom- Json и снова преобразую обратно в json и сохраняю файл tempalte с помощью ConvertTo- Json.
Когда я выполняю New-AzResourceGroupDeployment, я получаю странную ошибку, как показано ниже Параметр NO_PARAM в запросе недействителен. Укажите правильное значение для параметра NO_PARAM
Ниже является backuppolicy.deploy. json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vaultName": {
"type": "string",
"metadata": {
"description": "Name of the Recovery Services Vault"
}
},
"policyName": {
"type": "string",
"metadata": {
"description": "Name of the Backup Policy"
}
},
"scheduleRunDays": {
"type": "array",
"metadata": {
"description": "Backup Schedule will run on array of Days like, Monday, Tuesday etc. Applies in Weekly Backup Type only."
}
},
"scheduleRunTimes": {
"type": "array",
"metadata": {
"description": "Times in day when backup should be triggered. e.g. 01:00, 13:00. This will be used in LTR too for daily, weekly, monthly and yearly backup."
}
},
"timeZone": {
"type": "string",
"metadata": {
"description": "Any Valid timezone, for example:UTC, Pacific Standard Time. Refer: https://msdn.microsoft.com/en-us/library/gg154758.aspx"
}
},
"weeklyRetentionDurationCount": {
"type": "int",
"metadata": {
"description": "Number of weeks you want to retain the backup"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"resources": [
{
"apiVersion": "2016-06-01",
"name": "[concat(parameters('vaultName'), '/', parameters('policyName'))]",
"type": "Microsoft.RecoveryServices/vaults/backupPolicies",
"location": "[parameters('location')]",
"properties": {
"backupManagementType": "AzureIaasVM",
"instantRpRetentionRangeInDays": 5,
"schedulePolicy": {
"scheduleRunFrequency": "Weekly",
"scheduleRunDays": "[parameters('scheduleRunDays')]",
"scheduleRunTimes": "[parameters('scheduleRunTimes')]",
"schedulePolicyType": "SimpleSchedulePolicy"
},
"retentionPolicy": {
"dailySchedule": null,
"weeklySchedule": {
"daysOfTheWeek": "[parameters('scheduleRunDays')]",
"retentionTimes": "[parameters('scheduleRunTimes')]",
"retentionDuration": {
"count": "[parameters('weeklyRetentionDurationCount')]",
"durationType": "Weeks"
}
},
"retentionPolicyType": "LongTermRetentionPolicy"
},
"timeZone": "[parameters('timeZone')]"
}
}
]
}
Ниже приведены backuppolicy.parameters. json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vaultName": {
"value": "diskencrypt"
},
"policyName": {
"value": "autoamted-policy-changed"
},
"scheduleRunDays": {
"value": [
"Monday",
"Tuesday",
"Friday"
]
},
"scheduleRunTimes": {
"value": [
"20200309T110019Z"
]
},
"timeZone": {
"value": "UTC"
},
"weeklyRetentionDurationCount": {
"value": 5
}
}
}
Ниже код powershell, который я использовал для изменения шаблона json и запуска развертывания
$days = "Monday,Tuesday,Friday"
$ScheduleBackupDays = @()
$days = $days.Split(',')
$CurrentTime = @(Get-Date -Format yyyyMMddTHHmmssZ)
foreach($day in $days){
$ScheduleBackupDays += $day
}
$params = @{
policyName = "autoamted-policy-changed"
vaultName = "diskencrypt"
scheduleRunDays = $ScheduleBackupDays
scheduleRunTimes = $CurrentTime
timeZone = "UTC"
weeklyRetentionDurationCount = 5
}
$templateFile = "$PSScriptRoot\backuppolicy.deploy.json"
$paramtersfile = "$PSScriptRoot\backuppolicy.parameters.json"
$ParameterFileObject = Get-Content -Path $paramtersfile -Raw | ConvertFrom-Json
foreach($Key in $params.Keys){
$ParameterFileObject.parameters.$Key.value = $params.Get_Item($Key)
}
$ParameterFileObject | ConvertTo-Json -Depth 100 | foreach { [System.Text.RegularExpressions.Regex]::Unescape($_) } | Set-Content -Path $paramtersfile
New-AzResourceGroupDeployment -ResourceGroupName diskencrypt -TemplateFile $templateFile -TemplateParameterFile $paramtersfile