Home
%3CLINGO-SUB%20id%3D%22lingo-sub-386211%22%20slang%3D%22en-US%22%3EPoint-in-time%20restore%20of%20a%20database%20on%20Azure%20SQL%20Managed%20Instance%20using%20AzureRm.Sql%20PowerShell%20library%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-386211%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Jun%2028%2C%202018%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20Azure%20SQL%20Database%20Managed%20Instance%20is%20PaaS%20version%20of%20SQL%20Server%20hosted%20in%20Azure%20cloud.%20Managed%20Instance%20enables%20you%20to%20create%20a%20database%20as%20a%20copy%20of%20the%20existing%20database%20at%20some%20point%20in%20time%20using%20PowerShell.%20In%20this%20post%20you%20will%20see%20sample%20script%20that%20performs%20point%20in%20time%20restore%20of%20database.%20%3CBR%20%2F%3E%20The%20easiest%20way%20to%20manage%20your%20Azure%20SQL%20Database%20is%20to%20use%20%3CA%20href%3D%22https%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FAzureRM.Sql%2F4.8.1-preview%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20AzureRM.Sql(preview)%20%3C%2FA%3E%20PowerShell%20package.%20The%20following%20commands%20should%20install%20everything%20that%20you%20need%20(remove%20version%20once%20it%20gets%20generally%20available%20latest%20version)%3A%20%3CBR%20%2F%3E%20Install-Module%20PowerShellGet%20-Force%20%3CBR%20%2F%3E%20Install-Module%20-Name%20AzureRM%20-AllowClobber%20%3CBR%20%2F%3E%20Install-Module%20-Name%20AzureRM.Sql%20-RequiredVersion%204.8.0-preview%20-AllowPrerelease%20%3CBR%20%2F%3E%20Then%20you%20would%20need%20to%20have%20an%20instance%20with%20some%20existing%20database%20that%20you%20want%20to%20copy.%20You%20can%20use%20the%20following%20script%20to%20restore%20database%20from%20some%20point%20in%20time%20of%20the%20existing%20database.%20You%20just%20need%20to%20set%20the%20following%20variables%3A%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3E%24subscriptionId%20where%20you%20managed%20instance%20is%20placed%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3E%24location%20is%20the%20data%20center%20where%20your%20managed%20instance%20is%20placed%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3E%24resourceGroup%20where%20you%20placed%20the%20managed%20instance%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3E%24managedInstance%20is%20the%20name%20of%20managed%20instance%20(without%20domain%20name)%20where%20your%20source%20and%20target%20databases%20are%20placed%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3E%24database%20is%20the%20name%20of%20database%20that%20you%20would%20like%20to%20restore%20at%20some%20%24pointInTime%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3E%24targetDatabase%20is%20a%20new%20database%20that%20will%20be%20restored.%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24subscriptionId%20%3D%20%22a7m9a942-06c0-9a8b-4b8e-e7b1c70a69e1%22%20%3CBR%20%2F%3E%20%24location%20%3D%20%22West%20Central%20US%22%20%3CBR%20%2F%3E%20%24resourceGroup%20%3D%20%22my%20resource%20group%22%20%3CBR%20%2F%3E%20%24managedInstance%20%3D%20%22my%20managed%20instance%20name%22%20%3CBR%20%2F%3E%20%24database%20%3D%20%22my%20source%20database%22%20%3CBR%20%2F%3E%20%24pointInTime%20%3D%20%222018-06-27T08%3A51%3A39.3882806Z%22%20%3CBR%20%2F%3E%20%24targetDatabase%20%3D%20%22name%20of%20the%20new%20database%20that%20will%20be%20created%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Select-AzureRmSubscription%20-SubscriptionId%20%24subscriptionId%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Restore-AzureRmSqlManagedDatabase%20-FromPointInTimeBackup%20%60%20%3CBR%20%2F%3E%20-ManagedInstanceName%20%24managedInstance%20%60%20%3CBR%20%2F%3E%20-Name%20%24database%20%60%20%3CBR%20%2F%3E%20-PointInTime%20%24pointInTime%20%60%20%3CBR%20%2F%3E%20-TargetManagedDatabaseName%20%24targetDatabase%20%60%20%3CBR%20%2F%3E%20-ResourceGroupName%20%24resourceGroup%20%60%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-386211%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Jun%2028%2C%202018%20Azure%20SQL%20Database%20Managed%20Instance%20is%20PaaS%20version%20of%20SQL%20Server%20hosted%20in%20Azure%20cloud.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-386211%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQLServerStorageEngine%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft
First published on MSDN on Jun 28, 2018
Azure SQL Database Managed Instance is PaaS version of SQL Server hosted in Azure cloud. Managed Instance enables you to create a database as a copy of the existing database at some point in time using PowerShell. In this post you will see sample script that performs point in time restore of database.
The easiest way to manage your Azure SQL Database is to use AzureRM.Sql(preview) PowerShell package. The following commands should install everything that you need (remove version once it gets generally available latest version):
Install-Module PowerShellGet -Force
Install-Module -Name AzureRM -AllowClobber
Install-Module -Name AzureRM.Sql -RequiredVersion 4.8.0-preview -AllowPrerelease
Then you would need to have an instance with some existing database that you want to copy. You can use the following script to restore database from some point in time of the existing database. You just need to set the following variables:

  • $subscriptionId where you managed instance is placed

  • $location is the data center where your managed instance is placed

  • $resourceGroup where you placed the managed instance

  • $managedInstance is the name of managed instance (without domain name) where your source and target databases are placed

  • $database is the name of database that you would like to restore at some $pointInTime

  • $targetDatabase is a new database that will be restored.



$subscriptionId = "a7m9a942-06c0-9a8b-4b8e-e7b1c70a69e1"
$location = "West Central US"
$resourceGroup = "my resource group"
$managedInstance = "my managed instance name"
$database = "my source database"
$pointInTime = "2018-06-27T08:51:39.3882806Z"
$targetDatabase = "name of the new database that will be created"

Select-AzureRmSubscription -SubscriptionId $subscriptionId


Restore-AzureRmSqlManagedDatabase -FromPointInTimeBackup `
-ManagedInstanceName $managedInstance `
-Name $database `
-PointInTime $pointInTime `
-TargetManagedDatabaseName $targetDatabase `
-ResourceGroupName $resourceGroup `