|
2 | 2 | title: Restore SQL Server databases on an Azure VM
|
3 | 3 | description: This article describes how to restore SQL Server databases that are running on an Azure VM and that are backed up with Azure Backup. You can also use Cross Region Restore to restore your databases to a secondary region.
|
4 | 4 | ms.topic: conceptual
|
5 |
| -ms.date: 11/08/2022 |
| 5 | +ms.date: 02/20/2023 |
6 | 6 | ms.service: backup
|
7 | 7 | author: jyothisuri
|
8 | 8 | ms.author: jsuri
|
@@ -187,6 +187,44 @@ If the total string size of files in a database is greater than a [particular li
|
187 | 187 |
|
188 | 188 | 
|
189 | 189 |
|
| 190 | +## Recover a database from .bak file using SSMS |
| 191 | + |
| 192 | +You can use *Restore as Files* operation to restore the database files in `.bak` format while restoring from the Azure portal. [Learn more](restore-sql-database-azure-vm.md#restore-as-files). |
| 193 | + |
| 194 | +When the restoration of the `.bak` file to the Azure virtual machine is complete, you can trigger restore using **TSQL commands** through SSMS. |
| 195 | + |
| 196 | +To restore the database files to the *original path on the source server*, remove the `MOVE` clause from the TSQL restore query. |
| 197 | + |
| 198 | +**Example** |
| 199 | + |
| 200 | + ```azurecli-interactive |
| 201 | + USE [master] |
| 202 | + RESTORE DATABASE [<DBName>] FROM DISK = N'<.bak file path>' |
| 203 | + ``` |
| 204 | + |
| 205 | +>[!Note] |
| 206 | +>You shouldn’t have the same database files on the target server (restore with replace). Also, you can [enable instant file initialization on the target server to reduce the file initialization time overhead]( /sql/relational-databases/databases/database-instant-file-initialization?view=sql-server-ver16). |
| 207 | +
|
| 208 | +To relocate the database files from the target restore server, you can frame a TSQL command using the `MOVE` clauses. |
| 209 | + |
| 210 | + ```azurecli |
| 211 | + USE [master] |
| 212 | + RESTORE DATABASE [<DBName>] FROM DISK = N'<.bak file path>' MOVE N'<LogicalName1>' TO N'<TargetFilePath1OnDisk>', MOVE N'<LogicalName2>' TO N'<TargetFilePath2OnDisk>' GO |
| 213 | + ``` |
| 214 | + |
| 215 | +**Example** |
| 216 | + |
| 217 | + ```azurecli |
| 218 | + USE [master] |
| 219 | + RESTORE DATABASE [test] FROM DISK = N'J:\dbBackupFiles\test.bak' WITH FILE = 1, MOVE N'test' TO N'F:\data\test.mdf', MOVE N'test_log' TO N'G:\log\test_log.ldf', NOUNLOAD, STATS = 5 |
| 220 | + GO |
| 221 | + ``` |
| 222 | + |
| 223 | +If there are more than two files for the database, you can add additional move clauses to the restore query. You can also use SSMS for database recovery using `.bak` files. [Learn more]( /sql/relational-databases/backup-restore/restore-a-database-backup-using-ssms?view=sql-server-ver16). |
| 224 | + |
| 225 | +>[!Note] |
| 226 | +>For large database recovery, we recommend you to use TSQL statements. If you want to relocate the specific database files, see the list of database files in the JSON format created during the **Restore as Files** operation. |
| 227 | +
|
190 | 228 | ## Cross Region Restore
|
191 | 229 |
|
192 | 230 | As one of the restore options, Cross Region Restore (CRR) allows you to restore SQL databases hosted on Azure VMs in a secondary region, which is an Azure paired region.
|
|
0 commit comments