How to Point in time Restore Azure SQL Database after deleting the database

Azure SQL Database has feature to restore the database to point in time when the database is live. When we have to move the database to different Server we end up deleting the database from old server, we can not perform point in time restore!

About an year back when we had this situation we end up working with Microsoft to perform point in time restore on a deleted DB but this is available through Powershell command now.

SampleCode for reference;


#
$Resourcegroup="ResourceGroupName"                                                                          
$RestoredDBName = "DBName_05172018_0100UTC" # New Name                                                                     
$DBEdition = "Standard"                                                                                              
$DBTier = "S3"                                                                                                      
$RestoreTime = "2018-05-17 01:00"  # Time in UTC                                                                                  
$Servername = "AzureSQLDBServerName"                                                                                         
$DBName = "DeletedDBBame"

Login-AzureRmAccount                                                                                                
Select-AzureRmSubscription -SubscriptionId $SubscriptionId 

$DeletedDatabase = Get-AzureRmSqlDeletedDatabaseBackup -ResourceGroupName $ResourceGroup -ServerName $ServerName | Where-Object {$_.DatabaseN
ame -eq $DBName}

Restore-AzureRmSqlDatabase -FromDeletedDatabaseBackup -DeletionDate $DeletedDatabase.DeletionDate -ResourceGroupName $DeletedDatabase.ResourceGroupName -ServerName $DeletedDatabase.ServerName -TargetDatabaseName $RestoredDBName -ResourceId $DeletedDatabase.ResourceID -Edition $DBEdition -ServiceObjectiveName $DBTier -PointInTime $RestoreTime
#

Ref: https://docs.microsoft.com/en-us/azure/sql-database/sql-database-recovery-using-backups#point-in-time-restore

Advertisements
This entry was posted in Azure, Powershell, SQL, SQL Server, Uncategorized and tagged , , , , . Bookmark the permalink.

2 Responses to How to Point in time Restore Azure SQL Database after deleting the database

  1. Pingback: Frequently used Azure powershell commands | Blog for reference – Vijred

  2. Pingback: catalog | Blog for reference – Vijred

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s