0

I'm trying to make an automated script that restores from the latest LTR backup of an Azure SQL server database.

Using this command:

az sql db restore --dest-name $newdbname --name $dbname--resource-group $resourcegroup --server $servername

In docs there seems to be no way to specify which backup to use except with '--time' but then you have to manually specify the datetime string.

Is there a way to automate this with Azure CLI? I know with PowerShell Az module I can list all backups and select the latest, but I can't use PS is this case.(Docker)

1 Answer 1

0

Answering my own question: Azure CLI does not seem to have this feature implemented. Can use Powershell for this. Automation possible with service principal certificate authentication to Azure and cmdlets for getting the backups:

$server = Get-AzSqlServer -ServerName $serverName -ResourceGroupName $resourceGroup

$ltrBackup = Get-AzSqlDatabaseLongTermRetentionBackup -Location $server.Location -ServerName $serverName -DatabaseName $OldDbName -OnlyLatestPerDatabase

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .