title | description | author | ms.author | ms.reviewer | ms.date | ms.service | ms.subservice | ms.topic | ms.custom | ms.devlang |
---|---|---|---|---|---|---|---|---|---|---|
PowerShell: Restore geo-backup for Azure SQL Managed Instance |
Azure PowerShell example script to restore an Azure SQL Managed Instance database from a geo-redundant backup. |
Stralle |
strrodic |
mathoma, nvraparl |
07/03/2019 |
sql-managed-instance |
backup-restore |
sample |
devx-track-azurepowershell |
powershell |
[!INCLUDEappliesto-sqldb]
This PowerShell script example restores an Azure SQL Managed Instance database from a remote geo-region (geo-restore).
[!INCLUDE quickstarts-free-trial-note] [!INCLUDE updated-for-az] [!INCLUDE cloud-shell-try-it.md]
If you choose to install and use PowerShell locally, this tutorial requires Azure PowerShell 1.4.0 or later. If you need to upgrade, see Install Azure PowerShell module. If you are running PowerShell locally, you also need to run Connect-AzAccount
to create a connection with Azure.
# Connect-AzAccount
# The SubscriptionId in which to create these objects
$SubscriptionId = '<put subscription_id here>'
# Set the information for your managed instance
$SourceResourceGroupName = "myResourceGroup-$(Get-Random)"
$SourceInstanceName = "myManagedInstance-$(Get-Random)"
$SourceDatabaseName = "myInstanceDatabase-$(Get-Random)"
# Set the information for your destination managed instance
$TargetResourceGroupName = "myTargetResourceGroup-$(Get-Random)"
$TargetInstanceName = "myTargetManagedInstance-$(Get-Random)"
$TargetDatabaseName = "myTargetInstanceDatabase-$(Get-Random)"
Connect-AzAccount
Set-AzContext -SubscriptionId $SubscriptionId
$backup = Get-AzSqlInstanceDatabaseGeoBackup `
-ResourceGroupName $SourceResourceGroupName `
-InstanceName $SourceInstanceName `
-Name $SourceDatabaseName
$backup | Restore-AzSqlInstanceDatabase -FromGeoBackup `
-TargetInstanceDatabaseName $TargetDatabaseName `
-TargetInstanceName $TargetInstanceName `
-TargetResourceGroupName $TargetResourceGroupName
Use the following command to remove the resource group and all resources associated with it.
Remove-AzResourceGroup -ResourceGroupName $TargetResourceGroupName
This script uses the following commands. Each command in the table links to command specific documentation.
Command | Notes |
---|---|
New-AzResourceGroup | Creates a resource group in which all resources are stored. |
Get-AzSqlInstanceDatabaseGeoBackup | Gets one or more geo-backups from a database within an Azure SQL Managed Instance. |
Restore-AzSqlInstanceDatabase | Creates a database on SQL Managed Instance from geo-backup. |
Remove-AzResourceGroup | Deletes a resource group, including all nested resources. |
For more information about PowerShell, see Azure PowerShell documentation.
Additional PowerShell script samples for Azure SQL Database can be found in Azure SQL Database PowerShell scripts.