title: PowerShell example-restore-backup-Azure SQL database | Microsoft Docs description: Azure PowerShell example script to restore an Azure SQL database from geo-redundant backups services: sql-database ms.service: sql-database ms.subservice: backup-restore ms.custom: ms.devlang: PowerShell ms.topic: sample author: CarlRabeler ms.author: carlrab ms.reviewer: manager: craigg ms.date: 09/07/2018
This PowerShell script example restores an Azure SQL database from a geo-redundant backup, restores a deleted Azure SQL database to its latest backup, and restores an Azure SQL database to a specific point in time.
[!INCLUDE quickstarts-free-trial-note] [!INCLUDE cloud-shell-powershell.md]
If you choose to install and use the PowerShell locally, this tutorial requires the Azure PowerShell module version 5.7.0 or later. Run Get-Module -ListAvailable AzureRM
to find the version. If you need to upgrade, see Install Azure PowerShell module. If you are running PowerShell locally, you also need to run Connect-AzureRmAccount
to create a connection with Azure.
[!code-powershell-interactivemain]
After the script sample has been run, the following command can be used to remove the resource group and all resources associated with it.
Remove-AzureRmResourceGroup -ResourceGroupName $resourcegroupname
This script uses the following commands. Each command in the table links to command specific documentation.
Command | Notes |
---|---|
New-AzureRmResourceGroup | Creates a resource group in which all resources are stored. |
New-AzureRmSqlDatabase | Creates a database in a logical server as a single or a pooled database. |
Get-AzureRmSqlDatabaseGeoBackup | Gets a geo-redundant backup of a database. |
Restore-AzureRmSqlDatabase | Restores a SQL database. |
Remove-AzureRmSqlDatabase | Removes an Azure SQL database. |
Get-AzureRmSqlDeletedDatabaseBackup | Gets a deleted database that you can restore. |
Remove-AzureRmResourceGroup | Deletes a resource group including all nested resources. |
For more information on the Azure PowerShell, see Azure PowerShell documentation.
Additional SQL Database PowerShell script samples can be found in the Azure SQL Database PowerShell scripts.