0

I am trying to deploy a Recovery Services Vault next to a Storage account and a Sync Service. Everything goes through correctly, but my Backup Retention Policy keeps throwing an error back with "Parameter NO_PARAM in request is invalid. Please provide correct value for parameter NO_PARAM" and the policy doesn't get created on the Azure side. I've narrowed the issue down to being something related to the "scheduleRunTimes" parameter, but I feel like I've followed the Microsoft Templates and other templates on the web 1:1.

Here is my .json template:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "storageName": {
            "type": "string"
        },
        "storageLocation": {
            "type": "string"
        },
        "syncName": {
            "type": "string"
        },
        "recoveryName": {
            "type": "string"
        },
        "policyName": {
            "type": "string"
        },
        "scheduleRunTime": {
            "type": "string",
            "defaultValue": "03:30",
            "metadata": {
                "description": "Time of day when backup should be triggered in 24 hour HH:MM format, where MM must be 00 or 30. (Ignore if using existing Backup Policy)."
            }
        }
    },

    "functions": [],
    "variables": {
        "scheduleRunTimes": [
        "[format('2020-01-01T{0}:00Z', parameters('scheduleRunTime'))]"
    ]
    },
    "resources": [
        {
            "name": "[parameters('storageName')]",
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2021-04-01", 
            "location": "[parameters('storageLocation')]",
            "kind": "StorageV2",
            "sku": {
                "name": "Standard_LRS"
            }
        },
        {
            "type": "Microsoft.StorageSync/storageSyncServices",
            "apiVersion": "2020-09-01",
            "name": "[parameters('syncName')]",
            "location": "[parameters('storageLocation')]",
            "properties": {}
        },
        {
            "type": "Microsoft.RecoveryServices/vaults",
            "apiVersion": "2022-04-01",
            "name": "[parameters('recoveryName')]",
            "sku": {
                "name": "RS0",
                "tier": "Standard"
            },
            "location": "[parameters('storageLocation')]",
            "properties": {}
        },
        {
            "type": "Microsoft.RecoveryServices/vaults/backupPolicies",
            "apiVersion": "2022-06-01-preview",
            "name": "[concat(parameters('recoveryName'), '/', parameters('policyName'))]",
            "dependsOn": [ "[concat('Microsoft.RecoveryServices/vaults/', parameters('recoveryName'))]" ],
            "location": "[parameters('storageLocation')]",
            "properties": {
                "backupManagementType": "AzureStorage",
                "workLoadType": "AzureFileShare",
                "schedulePolicy": {
                    "scheduleRunFrequency": "Daily",
                    "scheduleRunTimes": "[variables('scheduleRunTimes')]",
                    "schedulePolicyType": "LongTermSchedulePolicy"
                },
                "timeZone": "UTC",
                "retentionPolicy": {
                    "retentionPolicyType": "LongTermRetentionPolicy",
                    "dailySchedule": {
                        "retentionTimes": "[variables('scheduleRunTimes')]",
                        "retentionDuration": {
                            "count": 30,
                            "durationType": "Days"
                        }
                    },
                    "weeklySchedule": {
                        "retentionDuration": {
                            "count": 5,
                            "durationType": "Weeks"
                        },
                        "daysOfTheWeek": ["Sunday"],
                        "retentionTimes": "[variables('scheduleRunTimes')]"
                    },
                    "monthlySchedule": {
                        "retentionDuration": {
                            "count": 13,
                            "durationType": "Months"
                        },
                        "retentionScheduleDaily": {
                            "daysOfTheMonth": [
                                {
                                    "date": 1,
                                    "isLast": false
                                }
                            ]
                        },
                        "retentionScheduleWeekly": {
                            "daysOfTheWeek": ["Sunday"],
                            "weeksOfTheMonth": ["First"]
                        },
                        "retentionScheduleFormatType": "Daily",
                        "retentionTimes": "[variables('scheduleRunTimes')]"
                    },
                    "yearlySchedule": {
                        "monthsOfYear": ["January"],
                        "retentionDuration": {
                            "count": 10,
                            "durationType": "Years"
                        },
                        "retentionScheduleDaily": {
                            "daysOfTheMonth": [
                                {
                                    "date": 1,
                                    "isLast": false
                                }
                            ]
                        },
                        "retentionScheduleWeekly": {
                            "daysOfTheWeek": ["Sunday"],
                            "weeksOfTheMonth": ["First"]
                        },
                        "retentionScheduleFormatType": "Daily",
                        "retentionTimes": "[variables('scheduleRunTimes')]"
                    }
                }
            }
        }
    ],
    "outputs": {}
}

And here is the .ps1 powershell for deploying:

Connect-AzAccount
$subName = Read-Host -Prompt "Enter the Subscription ID to use for deployment"
Set-AzContext -Subscription $subName
$officeName = Read-Host -Prompt "Enter the Office code I.E AMS, LDN or CPH"

$rgName = "RG-$officeName-FileSync"
$storageName = "afs$officeName"
$syncName = "$officeName-file-sync"
$recoveryName = "$officeName-AFSRecoveryVault"
$storageLocation = Read-Host -Prompt "Enter the desired Azure location for the AFS deployment"
$policyName = "scrapedforanynomity"

New-AzResourceGroup -Name $rgName -Location $storageLocation -Force
New-AzResourceGroupDeployment `
    -Name 'AFS-deployment2' `
    -ResourceGroupName $rgName `
    -TemplateFile 'C:\Users\Guldhammeren\Documents\Visual Studio Code\lasse.guldhammer\afs-01.json' `
    -storageName $storageName `
    -syncName $syncName `
    -storageLocation $storageLocation `
    -recoveryName $recoveryName `
    -policyName $policyName `
    -scheduleRunTime "03:00"

I simply can't figure out why it won't work? Appreciate any help!

I've already tried to enter the time as another format, but this results in another error code saying "InvalidUserRequestInput". So this means to me that the format is correct?

1 Answers1

0

As described Date functions of Arm templates in MS Doc, You can use datetimeAdd function to set the schedule for the resource.

I modified your code as below and it worked for me.

 "variables": {
    "startTime": "[dateTimeAdd(parameters('baseTime'), 'PT1H')]"
}

Complete script:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "storageName": {
            "type": "string"
        },
        "storageLocation": {
            "type": "string"
        },
        "syncName": {
            "type": "string"
        },
        "recoveryName": {
            "type": "string"
        },
        "policyName": {
            "type": "string"
        },
        "baseTime": {
      "type": "string",
      "defaultValue": "[utcNow('u')]",
      "metadata": {
        "description": "Schedule will start one hour from this time."
      }
    }
    }   ,

    "functions": [],
    "variables": {
    "startTime": "[dateTimeAdd(parameters('baseTime'), 'PT1H')]"
  },
    "resources": [
        {
            "name": "[parameters('storageName')]",
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2021-04-01", 
            "location": "[parameters('storageLocation')]",
            "kind": "StorageV2",
            "sku": {
                "name": "Standard_LRS"
            }
        },
        {
            "type": "Microsoft.StorageSync/storageSyncServices",
            "apiVersion": "2020-09-01",
            "name": "[parameters('syncName')]",
            "location": "[parameters('storageLocation')]",
            "properties": {}
        },
        {
            "type": "Microsoft.RecoveryServices/vaults",
            "apiVersion": "2022-04-01",
            "name": "[parameters('recoveryName')]",
            "sku": {
                "name": "RS0",
                "tier": "Standard"
            },
            "location": "[parameters('storageLocation')]",
            "properties": {}
        },
        {
            "type": "Microsoft.RecoveryServices/vaults/backupPolicies",
            "apiVersion": "2022-06-01-preview",
            "name": "[concat(parameters('recoveryName'), '/', parameters('policyName'))]",
            "dependsOn": [ "[concat('Microsoft.RecoveryServices/vaults/', parameters('recoveryName'))]" ],
            "location": "[parameters('storageLocation')]",
            "properties": {
                "backupManagementType": "AzureStorage",
                "workLoadType": "AzureFileShare",
                "schedulePolicy": {
                    "scheduleRunFrequency": "Daily",
                    "startTime": "[variables('startTime')]",
                    "schedulePolicyType": "LongTermSchedulePolicy"
                },
                "timeZone": "UTC",
                "retentionPolicy": {
                    "retentionPolicyType": "LongTermRetentionPolicy",
                    "dailySchedule": {
                        "retentionTimes": "[variables('startTime')]",
                        "retentionDuration": {
                            "count": 30,
                            "durationType": "Days"
                        }
                    },
                    "weeklySchedule": {
                        "retentionDuration": {
                            "count": 5,
                            "durationType": "Weeks"
                        },
                        "daysOfTheWeek": ["Sunday"],
                        "retentionTimes": "[variables('startTime')]"
                    },
                    "monthlySchedule": {
                        "retentionDuration": {
                            "count": 13,
                            "durationType": "Months"
                        },
                        "retentionScheduleDaily": {
                            "daysOfTheMonth": [
                                {
                                    "date": 1,
                                    "isLast": false
                                }
                            ]
                        },
                        "retentionScheduleWeekly": {
                            "daysOfTheWeek": ["Sunday"],
                            "weeksOfTheMonth": ["First"]
                        },
                        "retentionScheduleFormatType": "Daily",
                        "retentionTimes": "[variables('startTime')]"
                    },
                    "yearlySchedule": {
                        "monthsOfYear": ["January"],
                        "retentionDuration": {
                            "count": 10,
                            "durationType": "Years"
                        },
                        "retentionScheduleDaily": {
                            "daysOfTheMonth": [
                                {
                                    "date": 1,
                                    "isLast": false
                                }
                            ]
                        },
                        "retentionScheduleWeekly": {
                            "daysOfTheWeek": ["Sunday"],
                            "weeksOfTheMonth": ["First"]
                        },
                        "retentionScheduleFormatType": "Daily",
                        "retentionTimes": "[variables('startTime')]"
                    }
                }
            }
        }
    ],
    "outputs": {}
}

Output:

enter image description here

Deployment succeeded:

enter image description here

Updated code:

{
"protectedItemType": "type of the item",
        "policyId": "[format('{0}/backupPolicies/{1}', resourceId('Microsoft.RecoveryServices/vaults', variables('vault')), variables('policyName'))]",
        "sourceResourceId": "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.RecoveryServices/vaults', variables('recoveryName'))]",
        "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]"
      ]
Jahnavi
  • 3,076
  • 1
  • 3
  • 10
  • Hi Jahnavi, Thanks for the input! I can see on your screenshot that the ProvisioningState is "Failed" - Mine does the same with your code and failes with the following error message: The current operation failed due to an internal service error "Invalid input error". Please retry the operation after some time. If the issue persists, please contact Microsoft support. (Code:CloudInvalidInputError) All the resources gets created, but the backup policy isnt created due to this inputerror. – Lasse Emil Guldhammer Sørensen Mar 06 '23 at 12:25
  • @LasseEmilGuldhammerSørensen Actually the script is working. can you restart powershell once and try again! – Jahnavi Mar 06 '23 at 12:41
  • I've just tried and I still get the error? Can you check if the the backup policy actually gets created when you run it? I can see the storage account, sync service and recovery vault is created, but when I go into the recovery vault and check for the backup policy, then I can't see it? – Lasse Emil Guldhammer Sørensen Mar 06 '23 at 12:45
  • Yes. I figured it out. As detailed in [MS Doc](https://learn.microsoft.com/en-us/azure/backup/quick-backup-vm-template), You need to add properties field in the above detailed way and add `dependsOn` block to enable/add the policy. @LasseEmilGuldhammerSørensen – Jahnavi Mar 06 '23 at 13:34
  • Sorry, I don't think I understand that. Can you post a code snippet with the changes implemented? – Lasse Emil Guldhammer Sørensen Mar 06 '23 at 14:03
  • I was saying about the portion of code that I updated in the answer. You need to add `dependsOn` to set up a policy for a resource and it is clearly detailed in MSDoc which I gave in the comment section. Can you try! @LasseEmilGuldhammerSørensen – Jahnavi Mar 07 '23 at 05:11