GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/default?api-version=2023-08-01
400 ManagedInstanceStoppingOrStopped - Conflicting operation submitted while instance is in stopping/stopped state
400 ManagedInstanceStarting - Conflicting operation submitted while instance is in starting state
400 LtrConfigPolicyUnsupportedIfAutoPauseEnabled - Enabling long-term backup retention for a serverless database is not supported if auto-pause is enabled.
400 LtrConfigPolicyDuringVldbMigration - Enabling long-term backup retention for a database during migration to the Hyperscale service tier is not supported.
400 LtrConfigPolicyDuringVldbReverseMigration - Enabling long-term backup retention for a database during a reverse migration from Hyperscale is not supported.
400 DatabaseNamedReplicaBackupRetentionConfigurationNotSupported - User attempted configuring backup retention policy on a Named Replica.
400 LTRNotSupportedForPerDBCMK - Long-term Backup Retention is not supported when Database-level CMK is configured in preview.
400 LTRHyperscaleSetPolicyError - An error has occurred while enabling Long-term backup retention for this database. Please reach out to Microsoft support to enable long-term backup retention.
400 LTRArchiveStorageDisabledOnHyperscaleEdition - Archiving long-term retention backups on Hyperscale databases is not enabled.
400 LTRArchiveStorageFailedOnZoneRedundantBackupStorage - Setting a long-term retention policy with the backup storage access tier set to 'archive' is not supported on zone-redundant backup storage. Use either locally redundant or geo-redundant storage types.
400 LongTermRetentionPolicyNotSupported - Long Term Retention is not supported on this database.
400 LongTermRetentionPolicyInvalid - Long Term Retention policy is invalid.
404 ServerNotInSubscriptionResourceGroup - Specified server does not exist in the specified resource group and subscription.
404 SubscriptionDoesNotHaveServer - The requested server was not found
404 ResourceNotFound - The requested resource was not found.
404 SubscriptionNotFound - The requested subscription was not found.
409 ConflictingServerOperation - Server '{0}' is busy with another operation. Please try your operation later.
429 SubscriptionTooManyRequests - Requests beyond max requests that can be processed by available resources.
503 TooManyRequests - Requests beyond max requests that can be processed by available resources.
Examples
Get the long term retention policy for the database.
GET https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/resourceGroup/providers/Microsoft.Sql/servers/testserver/databases/testDatabase/backupLongTermRetentionPolicies/default?api-version=2023-08-01
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Sql.Models;
using Azure.ResourceManager.Sql;
// Generated from example definition: specification/sql/resource-manager/Microsoft.Sql/stable/2023-08-01/examples/LongTermRetentionPolicyGet.json
// this example is just showing the usage of "LongTermRetentionPolicies_Get" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this SqlDatabaseResource created on azure
// for more information of creating SqlDatabaseResource, please refer to the document of SqlDatabaseResource
string subscriptionId = "00000000-1111-2222-3333-444444444444";
string resourceGroupName = "resourceGroup";
string serverName = "testserver";
string databaseName = "testDatabase";
ResourceIdentifier sqlDatabaseResourceId = SqlDatabaseResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, serverName, databaseName);
SqlDatabaseResource sqlDatabase = client.GetSqlDatabaseResource(sqlDatabaseResourceId);
// get the collection of this LongTermRetentionPolicyResource
LongTermRetentionPolicyCollection collection = sqlDatabase.GetLongTermRetentionPolicies();
// invoke the operation
LongTermRetentionPolicyName policyName = LongTermRetentionPolicyName.Default;
NullableResponse<LongTermRetentionPolicyResource> response = await collection.GetIfExistsAsync(policyName);
LongTermRetentionPolicyResource result = response.HasValue ? response.Value : null;
if (result == null)
{
Console.WriteLine("Succeeded with null as result");
}
else
{
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
LongTermRetentionPolicyData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}