Skip to content

Commit e4c522d

Browse files
Merge pull request #227921 from AbhishekMallick01/Feb-20-2023-BAK
Restore SQL DB from BAK file
2 parents 5078073 + 90688c3 commit e4c522d

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

articles/backup/restore-sql-database-azure-vm.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Restore SQL Server databases on an Azure VM
33
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.
44
ms.topic: conceptual
5-
ms.date: 11/08/2022
5+
ms.date: 02/20/2023
66
ms.service: backup
77
author: jyothisuri
88
ms.author: jsuri
@@ -187,6 +187,44 @@ If the total string size of files in a database is greater than a [particular li
187187

188188
![Restore Database with large file](./media/backup-azure-sql-database/restore-large-files.jpg)
189189

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+
190228
## Cross Region Restore
191229

192230
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

Comments
 (0)