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)

robliv
  • 101
  • 1

1 Answers1

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
robliv
  • 101
  • 1