|
| 1 | +--- |
| 2 | +title: Restore a deleted logical server (preview) |
| 3 | +titleSuffix: Azure SQL Database |
| 4 | +description: Learn about restoring a deleted logical server in Azure SQL Database. |
| 5 | +author: WilliamDAssafMSFT |
| 6 | +ms.author: wiassaf |
| 7 | +ms.reviewer: dinethi |
| 8 | +ms.date: 02/28/2025 |
| 9 | +ms.service: azure-sql-database |
| 10 | +ms.subservice: backup-restore |
| 11 | +ms.topic: how-to |
| 12 | +ms.custom: |
| 13 | + - azure-sql-split |
| 14 | +monikerRange: "=azuresql || =azuresql-db" |
| 15 | +ROBOTS: NOINDEX |
| 16 | +--- |
| 17 | +# Restore a deleted logical server in Azure SQL Database (preview) |
| 18 | + |
| 19 | +[!INCLUDE [appliesto-sqldb](../includes/appliesto-sqldb.md)] |
| 20 | + |
| 21 | +This article provides steps to restore an Azure SQL Database server, also known as a logical server, if it was accidentally deleted. |
| 22 | + |
| 23 | +> [!IMPORTANT] |
| 24 | +> This feature is in preview and is currently only enabled for certain subscriptions. |
| 25 | +
|
| 26 | +You can restore a deleted Azure SQL logical server and its underlying databases with one of the following two methods: |
| 27 | + |
| 28 | +## Restore an Azure SQL Database logical server using PowerShell and REST API |
| 29 | + |
| 30 | +Follow these steps to set up the variables needed to restore the deleted logical server, using PowerShell to invoke a REST API call. |
| 31 | + |
| 32 | +1. Sign in to Azure in your PowerShell terminal. |
| 33 | + |
| 34 | + ```powershell |
| 35 | + Login-AzAccount |
| 36 | + ``` |
| 37 | + |
| 38 | +1. Set the proper Azure context for your subscription. |
| 39 | + |
| 40 | + ```powershell |
| 41 | + $context = Get-AzContext |
| 42 | + ``` |
| 43 | + |
| 44 | +1. Replace `<subscription-id>` with your subscription name. |
| 45 | + |
| 46 | + ```powershell |
| 47 | + Select-AzSubscription -Context $context -Name <subscription-id> |
| 48 | + ``` |
| 49 | + |
| 50 | +1. Set variables in your PowerShell terminal. |
| 51 | + |
| 52 | + ```powershell |
| 53 | + $azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile |
| 54 | + $profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azProfile) |
| 55 | + $token = $profileClient.AcquireAccessToken($context.Tenant.TenantId) |
| 56 | + $authToken = $token.AccessToken |
| 57 | + $headers = @{} |
| 58 | + $headers.Add('Authorization', 'Bearer ' + $authToken) |
| 59 | + ``` |
| 60 | + |
| 61 | +1. Replace `<subscription-id>`, `<your-resource-group-id>`, and `<your-server-id>` with the appropriate unique IDs. |
| 62 | + |
| 63 | + ```powershell |
| 64 | + $uri="https://management.azure.com/subscriptions/<your-subscription-id>]/resourceGroups/<your-resource-group-id>/providers/Microsoft.Sql/servers/<your-server-id>?api-version=2023-05-01-preview" |
| 65 | + ``` |
| 66 | + |
| 67 | + We now have the auth header ($headers) that we need to be able to run the API. |
| 68 | + |
| 69 | +1. Create an API call body. Replace `<Azure region name>` with your region name, for example, `East US 2`. |
| 70 | + |
| 71 | + ```powershell |
| 72 | + $body={ |
| 73 | + "properties": { |
| 74 | + "createMode": "Restore" |
| 75 | + }, |
| 76 | + "location": "<Azure region name>" |
| 77 | + } |
| 78 | + ``` |
| 79 | +
|
| 80 | +1. Now you're ready to run the following PowerShell command to initiate the restore of the deleted Azure SQL Database logical server: |
| 81 | +
|
| 82 | + ```powershell |
| 83 | + Invoke-RestMethod -Method PUT -Headers $headers -Uri $uri -ContentType 'application/json' -Body $body |
| 84 | + ``` |
| 85 | + |
| 86 | +## Restore an Azure SQL Database logical server using PowerShell |
| 87 | + |
| 88 | +Use the following steps to restore your deleted Azure SQL logical server using [Restore-AzSqlServer](/powershell/module/az.sql/restore-azsqldatabase). |
| 89 | + |
| 90 | +1. Open a new PowerShell window. |
| 91 | + |
| 92 | +1. Install the `Az.Tools.Installer` module. |
| 93 | + |
| 94 | + ```powershell |
| 95 | + Install-Module -Name Az.Tools.Installer -Repository PSGallery |
| 96 | + ``` |
| 97 | + |
| 98 | +1. Install the `Az.Accounts` module. |
| 99 | + |
| 100 | + ```powershell |
| 101 | + Install-Module Az.Accounts -Repository PSGallery |
| 102 | + ``` |
| 103 | + |
| 104 | +1. Use the `Az.Tools.Installer` to install the NuGet package. |
| 105 | + |
| 106 | + ```powershell |
| 107 | + Install-AzModule -Path https://azposhpreview.blob.core.windows.net/public/Az.Sql.5.2.0.nupkg |
| 108 | + ``` |
| 109 | + |
| 110 | +1. Sign in and connect to your Azure account. |
| 111 | + |
| 112 | + ```powershell |
| 113 | + Connect-AzAccount |
| 114 | + ``` |
| 115 | + |
| 116 | +1. Select the desired subscription, replace `<subscription-id>` with the subscription name. |
| 117 | + |
| 118 | + ```powershell |
| 119 | + Select-AzSubscription -Subscription "<subscription-id>" |
| 120 | + ``` |
| 121 | + |
| 122 | +1. Run the restore command as follows. Replace `<your-server-name>` and `<your-resource-group-id>` with your deleted logical server's name and resource group ID. |
| 123 | + |
| 124 | + ```powershell |
| 125 | + $servername = <your-server-name> |
| 126 | + $resourcegroup = <your-resource-group-id> |
| 127 | + Restore-AzSqlServer -ServerName $servername -ResourceGroup $resourcegroup |
| 128 | + ``` |
| 129 | + |
| 130 | +## Restore the deleted databases |
| 131 | + |
| 132 | +Once the logical server is restored, restoring the databases is next. Look in the **Deleted databases** tab on the **Backups** page, by browsing to the server resource in Azure portal. For more information, see [Restore a database from a backup in Azure SQL Database](recovery-using-backups.md). |
| 133 | + |
| 134 | +## Delete the logical server without recovery |
| 135 | + |
| 136 | +To delete an Azure SQL logical server without the possibility of recovery, contact Microsoft Support and [open a support case](https://azure.microsoft.com/support/create-ticket/). |
| 137 | + |
| 138 | +## Related content |
| 139 | + |
| 140 | +- [Automated backups in Azure SQL Database](automated-backups-overview.md) |
0 commit comments