Point-in-time restore of a database on Azure SQL Managed Instance using AzureRm.Sql PowerShell library
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 `
Comments
- Anonymous
August 06, 2018
Great, thanks for sharing!