I cannot see the Long-Term Retention (LTR) backups

Published 03-13-2019 07:04 PM 808 Views
Not applicable
First published on MSDN on Oct 23, 2018
Sometimes a user is assigned permissions at Resource Group level or Resource level.
When using Long-Term Retention we have several advantages like each backup will be kept in the long-term storage for the period specified by these parameters or the database can be restored to any existing server under the same subscription as the original database.

Due to this, the backups are associated with the Subscription and not the Resource Group or Server.
A common issue is that the users with permissions at Resource Group level or Resource level will not be able to see the backups.
The user need some read permissions at Subscription level to be able to see the backups.

You can see more details about the roles at Unable to view LTR Backups for Azure SQL Database servers

When it's not possible to assign permissions at Subscription level or we wish to keep the users with as least privileges as possible, the subscription administrator can create a custom role with just that read permissions and assign it to the users/groups that should see the LTR backups.

Please replace {SubscriptionId} and {user@company.com} accordingly.

[code language="powershell"]
#Login to Azure
Login-AzureRmAccount

#List the subscriptions you have access
Get-AzureRmSubscription

#Select the subscription you want to use in case you have access to more than one subscription
Select-AzureRmSubscription -Subscription "{SubscriptionId}"

#Create the custom role
$role = Get-AzureRmRoleDefinition "Reader"
$role.Id = $null
$role.Name = "Long Term Retention Backups - Read"
$role.Description = "Can view the Long Term Retention Backups."
$role.Actions.Clear()
$role.Actions.Add("Microsoft.Sql/locations/longTermRetentionBackups/read")
$role.Actions.Add("Microsoft.Sql/locations/longTermRetentionServers/longTermRetentionBackups/read")
$role.Actions.Add("Microsoft.Sql/locations/longTermRetentionServers/longTermRetentionDatabases/longTermRetentionBackups/read")
$role.AssignableScopes.Clear()
$role.AssignableScopes.Add("/subscriptions/<SubscriptionId>")
New-AzureRmRoleDefinition -Role $role

#List all the roles, confirm that the custome role is available, it can take some time
#Get-AzureRmRoleDefinition | FT Name, IsCustom

#Assign the role
New-AzureRmRoleAssignment -RoleDefinitionName "Long Term Retention Backups - Read" -SignInName "{user@company.com}" -Scope "/subscriptions/{SubscriptionId}"

#Wait some seconds and the user should be able to see the backups now
[/code]


(2018-10-24 update)

In case you get the following error: " New-AzureRmRoleAssignment : The provided information does not map to an AD object id. " this means that the SignInName is not exactly like this, specially with guest users.

If you run the following you will be able to understand the ObjectID you should use:

[code language="powershell"]
Connect-AzureAD

Get-AzureADUser -SearchString "Vitor Tomaz"
[/code]

You should get a result like the following, if not, it means you are probably not using the right 'Name':

[code language="powershell"]
ObjectId DisplayName UserPrincipalName UserType
-------- ----------- ----------------- --------
4db73255-9e71-4e35-9157-ea53d62d63a0 Vitor Tomaz vitor.tomaz_something.com#EXT#@somethingelse.onmicrosoft.com Guest

[/code]

You can now use the ObjectId from the previous result to assign the role:

[code language="powershell"]
#Assign the role using ObjectId
New-AzureRmRoleAssignment -RoleDefinitionName "Long Term Retention Backups - Read" -ObjectId 4db73255-9e71-4e35-9157-ea53d62d63a0 -Scope "/subscriptions/{SubscriptionId}"
[/code]
%3CLINGO-SUB%20id%3D%22lingo-sub-369066%22%20slang%3D%22en-US%22%3EI%20cannot%20see%20the%20Long-Term%20Retention%20(LTR)%20backups%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-369066%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Oct%2023%2C%202018%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20Sometimes%20a%20user%20is%20assigned%20permissions%20at%20Resource%20Group%20level%20or%20Resource%20level.%20%3CBR%20%2F%3E%20When%20using%20Long-Term%20Retention%20we%20have%20several%20advantages%20like%20each%20backup%20will%20be%20kept%20in%20the%20long-term%20storage%20for%20the%20period%20specified%20by%20these%20parameters%20or%20the%20database%20can%20be%20restored%20to%20any%20existing%20server%20under%20the%20same%20subscription%20as%20the%20original%20database.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Due%20to%20this%2C%20the%20backups%20are%20associated%20with%20the%20Subscription%20and%20not%20the%20Resource%20Group%20or%20Server.%20%3CBR%20%2F%3E%20A%20common%20issue%20is%20that%20the%20users%20with%20permissions%20at%20Resource%20Group%20level%20or%20Resource%20level%20will%20not%20be%20able%20to%20see%20the%20backups.%20%3CBR%20%2F%3E%20The%20user%20need%20some%20read%20permissions%20at%20Subscription%20level%20to%20be%20able%20to%20see%20the%20backups.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20You%20can%20see%20more%20details%20about%20the%20roles%20at%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fazuresqldbsupport%2F2018%2F11%2F13%2Funable-to-view-ltr-backups-for-azure-sql-database-servers%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Unable%20to%20view%20LTR%20Backups%20for%20Azure%20SQL%20Database%20servers%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20When%20it's%20not%20possible%20to%20assign%20permissions%20at%20Subscription%20level%20or%20we%20wish%20to%20keep%20the%20users%20with%20as%20least%20privileges%20as%20possible%2C%20the%20subscription%20administrator%20can%20create%20a%20custom%20role%20with%20just%20that%20read%20permissions%20and%20assign%20it%20to%20the%20users%2Fgroups%20that%20should%20see%20the%20LTR%20backups.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20Please%20replace%20%7BSubscriptionId%7D%20and%20%7Buser%40company.com%7D%20accordingly.%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bcode%20language%3D%22powershell%22%5D%20%3CBR%20%2F%3E%20%23Login%20to%20Azure%20%3CBR%20%2F%3E%20Login-AzureRmAccount%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23List%20the%20subscriptions%20you%20have%20access%20%3CBR%20%2F%3E%20Get-AzureRmSubscription%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23Select%20the%20subscription%20you%20want%20to%20use%20in%20case%20you%20have%20access%20to%20more%20than%20one%20subscription%20%3CBR%20%2F%3E%20Select-AzureRmSubscription%20-Subscription%20%22%7BSubscriptionId%7D%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23Create%20the%20custom%20role%20%3CBR%20%2F%3E%20%24role%20%3D%20Get-AzureRmRoleDefinition%20%22Reader%22%20%3CBR%20%2F%3E%20%24role.Id%20%3D%20%24null%20%3CBR%20%2F%3E%20%24role.Name%20%3D%20%22Long%20Term%20Retention%20Backups%20-%20Read%22%20%3CBR%20%2F%3E%20%24role.Description%20%3D%20%22Can%20view%20the%20Long%20Term%20Retention%20Backups.%22%20%3CBR%20%2F%3E%20%24role.Actions.Clear()%20%3CBR%20%2F%3E%20%24role.Actions.Add(%22Microsoft.Sql%2Flocations%2FlongTermRetentionBackups%2Fread%22)%20%3CBR%20%2F%3E%20%24role.Actions.Add(%22Microsoft.Sql%2Flocations%2FlongTermRetentionServers%2FlongTermRetentionBackups%2Fread%22)%20%3CBR%20%2F%3E%20%24role.Actions.Add(%22Microsoft.Sql%2Flocations%2FlongTermRetentionServers%2FlongTermRetentionDatabases%2FlongTermRetentionBackups%2Fread%22)%20%3CBR%20%2F%3E%20%24role.AssignableScopes.Clear()%20%3CBR%20%2F%3E%20%24role.AssignableScopes.Add(%22%2Fsubscriptions%2F%3CSUBSCRIPTIONID%3E%22)%20%3CBR%20%2F%3E%20New-AzureRmRoleDefinition%20-Role%20%24role%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23List%20all%20the%20roles%2C%20confirm%20that%20the%20custome%20role%20is%20available%2C%20it%20can%20take%20some%20time%20%3CBR%20%2F%3E%20%23Get-AzureRmRoleDefinition%20%7C%20FT%20Name%2C%20IsCustom%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23Assign%20the%20role%20%3CBR%20%2F%3E%20New-AzureRmRoleAssignment%20-RoleDefinitionName%20%22Long%20Term%20Retention%20Backups%20-%20Read%22%20-SignInName%20%22%7Buser%40company.com%7D%22%20-Scope%20%22%2Fsubscriptions%2F%7BSubscriptionId%7D%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%23Wait%20some%20seconds%20and%20the%20user%20should%20be%20able%20to%20see%20the%20backups%20now%20%3CBR%20%2F%3E%20%5B%2Fcode%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20(2018-10-24%20update)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20In%20case%20you%20get%20the%20following%20error%3A%20%22%20%3CSTRONG%3E%20New-AzureRmRoleAssignment%20%3A%20The%20provided%20information%20does%20not%20map%20to%20an%20AD%20object%20id.%20%3C%2FSTRONG%3E%20%22%20this%20means%20that%20the%20SignInName%20is%20not%20exactly%20like%20this%2C%20specially%20with%20guest%20users.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20If%20you%20run%20the%20following%20you%20will%20be%20able%20to%20understand%20the%20ObjectID%20you%20should%20use%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bcode%20language%3D%22powershell%22%5D%20%3CBR%20%2F%3E%20Connect-AzureAD%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Get-AzureADUser%20-SearchString%20%22Vitor%20Tomaz%22%20%3CBR%20%2F%3E%20%5B%2Fcode%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20You%20should%20get%20a%20result%20like%20the%20following%2C%20if%20not%2C%20it%20means%20you%20are%20probably%20not%20using%20the%20right%20'Name'%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bcode%20language%3D%22powershell%22%5D%20%3CBR%20%2F%3E%20ObjectId%20DisplayName%20UserPrincipalName%20UserType%20%3CBR%20%2F%3E%20--------%20-----------%20-----------------%20--------%20%3CBR%20%2F%3E%204db73255-9e71-4e35-9157-ea53d62d63a0%20Vitor%20Tomaz%20vitor.tomaz_something.com%23EXT%23%40somethingelse.onmicrosoft.com%20Guest%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5B%2Fcode%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20You%20can%20now%20use%20the%20ObjectId%20from%20the%20previous%20result%20to%20assign%20the%20role%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bcode%20language%3D%22powershell%22%5D%20%3CBR%20%2F%3E%20%23Assign%20the%20role%20using%20ObjectId%20%3CBR%20%2F%3E%20New-AzureRmRoleAssignment%20-RoleDefinitionName%20%22Long%20Term%20Retention%20Backups%20-%20Read%22%20-ObjectId%204db73255-9e71-4e35-9157-ea53d62d63a0%20-Scope%20%22%2Fsubscriptions%2F%7BSubscriptionId%7D%22%20%3CBR%20%2F%3E%20%5B%2Fcode%5D%3C%2FSUBSCRIPTIONID%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-369066%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Oct%2023%2C%202018%20Sometimes%20a%20user%20is%20assigned%20permissions%20at%20Resource%20Group%20level%20or%20Resource%20level.%3C%2FLINGO-TEASER%3E%3C%2FLINGO-BODY%3E
Version history
Last update:
‎Mar 13 2019 07:04 PM
Updated by: