admin管理员组文章数量:1315332
I wanted to create a policy that automatically gives databases a long term retention instead of doing it manually every time so I created this code but for some reason the database does not get any retention automatically.
There are no errors when creating it and I have assigned it to the resource group where the SQL MI resides. It is not a role issue either. Could anyone explain why it isn't working? I have created a new database and waited a few hours for it to fully deploy but it was not given the weekly, monthly, or yearly retention.
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Sql/managedInstances/databases"
}
]
},
"then": {
"effect": "deployIfNotExists",
"details": {
"type": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies",
"existenceCondition": {
"anyOf": [
{
"field": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/weeklyRetention",
"notEquals": "P12W"
},
{
"field": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/monthlyRetention",
"notEquals": "P12M"
},
{
"field": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/yearlyRetention",
"notEquals": "P5Y"
}
]
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": ".json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies",
"apiVersion": "2021-02-01-preview",
"name": "[concat(parameters('fullDbName'), '/default')]",
"properties": {
"weeklyRetention": "P12W",
"monthlyRetention": "P12M",
"yearlyRetention": "P5Y",
"weekOfYear": 1
}
}
]
}
},
"databaseName": {
"value": "[field('name')]"
}
}
}
}
},
"parameters": {}
}
I wanted to create a policy that automatically gives databases a long term retention instead of doing it manually every time so I created this code but for some reason the database does not get any retention automatically.
There are no errors when creating it and I have assigned it to the resource group where the SQL MI resides. It is not a role issue either. Could anyone explain why it isn't working? I have created a new database and waited a few hours for it to fully deploy but it was not given the weekly, monthly, or yearly retention.
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Sql/managedInstances/databases"
}
]
},
"then": {
"effect": "deployIfNotExists",
"details": {
"type": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies",
"existenceCondition": {
"anyOf": [
{
"field": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/weeklyRetention",
"notEquals": "P12W"
},
{
"field": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/monthlyRetention",
"notEquals": "P12M"
},
{
"field": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies/yearlyRetention",
"notEquals": "P5Y"
}
]
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "https://schema.management.azure/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Sql/managedInstances/databases/backupLongTermRetentionPolicies",
"apiVersion": "2021-02-01-preview",
"name": "[concat(parameters('fullDbName'), '/default')]",
"properties": {
"weeklyRetention": "P12W",
"monthlyRetention": "P12M",
"yearlyRetention": "P5Y",
"weekOfYear": 1
}
}
]
}
},
"databaseName": {
"value": "[field('name')]"
}
}
}
}
},
"parameters": {}
}
Share
Improve this question
asked Jan 30 at 9:34
DanDan
1
1 Answer
Reset to default 0When you say the policy is triggered but not applied on the database Look at the 'Activity Logs' on the corresponding Azure SQL managed instance Server.
- Go to your Azure SQL managed instance Server >> Activity Log.
- Look for deployIfNotExists policy on your Azure SQL Managed Instance or database server.
- The error message will provide details on why the policy failed.
Other possible reasons are as follows:
- Incorrect Name Reference in Deployment might cause the issue while applying the Policy on database, or there may be parameters you created are incorrect.
- make sure you applied policy on correct scope either on resource group level or database server level.
- parameter values provided in the policy definition match the expected data types and formats. For example, LTRWeekOfYear is defined as an integer, so ensure that the value provided is a valid integer
本文标签:
版权声明:本文标题:Creating an Azure Policy to automatically give any SQL Managed Instance Databases a LTR instead of manually assigning them to ea 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741976014a2408124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论