Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When there is no yearly backup retention policy, Get-AzSqlDatabaseLongTermRetentionPolicy returns 0 for WeekOfYear, but Azure Portal displays 'Week 1' as default and Set-AzSqlDatabaseLongTermRetentionPolicy wants a number between 1 and 52. #27045

Open
sicil1ano opened this issue Jan 24, 2025 · 0 comments
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team.

Comments

@sicil1ano
Copy link

sicil1ano commented Jan 24, 2025

Description

When there is no yearly backup retention policy, Get-AzSqlDatabaseLongTermRetentionPolicy returns 0 for WeekOfYear.
The value "0" does not make sense, as week 0 does not exist in a solar year.
Furthermore, Azure Portal displays "Week 1" as default and Set-AzSqlDatabaseLongTermRetentionPolicy wants a number between 1 and 52. This means Get-AzSqlDatabaseLongTermRetentionPolicy returns a wrong output, or at least an output that is in contradiction with Azure Portal and Set-AzSqlDatabaseLongTermRetentionPolicy.

Issue script & Debug output

$sourceServerName = "sql-source"
$sourceResourceGroup = "rg-dbsource"

foreach ($sourceDb in $sourceDatabases) {
    if ($sourceDb.DatabaseName -eq "master") {
        Write-Output "Skipping master DB."
        continue
    }
        

    # Get the LTR policy for the current database
    $ltrPolicy = Get-AzSqlDatabaseLongTermRetentionPolicy -DatabaseName $sourceDb.DatabaseName `
                                                          -ServerName $sourceServerName `
                                                          -ResourceGroupName $sourceResourceGroup

    # Display the current LTR policy
    Write-Output "Database: $($sourceDb.DatabaseName)"
    Write-Output "Weekly Retention: $($ltrPolicy.WeeklyRetention)"
    Write-Output "Monthly Retention: $($ltrPolicy.MonthlyRetention)"
    Write-Output "Yearly Retention: $($ltrPolicy.YearlyRetention)"
    Write-Output "Week Year Retention: $($ltrPolicy.WeekOfYear)"
}

Skipping master DB.
Database: mydb
Weekly Retention: P5W
Monthly Retention: PT0S
Yearly Retention: PT0S
Week Year Retention: 0

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    Name                                ExportedCommands                                                                                                                                            
---------- -------    ----                                ----------------                                                                                                                                            
Script     4.0.2      Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}                                                                                    
Script     6.0.1      Az.Sql                              {Add-AzSqlDatabaseToFailoverGroup, Add-AzSqlElasticJobStep, Add-AzSqlElasticJobTarget, Add-AzSqlInstanceKeyVaultKey...}

Error output

@sicil1ano sicil1ano added bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Jan 24, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team. and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team.
Projects
None yet
Development

No branches or pull requests

1 participant