To restore a SQL server database from multiple files we can use the RESTORE DATABASE T-SQL command.
Before we do the restore process it is good to know the name of the “.mdf” and “.ldf” files in the backup set. To find this out we can run the RESTORE FILELISTONLY command in the following syntax:
RESTORE FILELISTONLY FROM
DISK = 'E:\Db_Backups\FILE1_FULL.BAK',
DISK = 'E:\Db_Backups\FILE2_FULL.BAK',
DISK = 'E:\Db_Backups\FILE3_FULL.BAK'
In the above example I assume the full backup consists of 3 files, “FILE1_FULL.BAK”, “FILE2_FULL.BAK”, and “FILE3_FULL.BAK”. The files in this case files are locate in E drive “Db_Backups” folder.
The above command will output the name of the “.mdf” and “.ldf” files contained in the backup set. Once we get those we can run the actual restore command in the following way:
RESTORE DATABASE My_DB FROM
DISK = 'E:\Db_Backups\FILE1_FULL.BAK',
DISK = 'E:\Db_Backups\FILE2_FULL.BAK',
DISK = 'E:\Db_Backups\FILE3_FULL.BAK'
WITH
MOVE My_DB ' TO 'E:\DATA\ My_DB.mdf',
MOVE My_DB _log' TO 'E:\LOGS\ My_DB _log.LDF',
STATS =1
Using the Move command we move the restored data and log files to a location of our choice and with STATS set as 1 we get a detailed verbose of the tasks happening similar to this:
1 percent processed.
2 percent processed.
3 percent processed.
…
100 percent processed.
Processed 108352 pages for database My_DB ', file My_DB ' on file 1.
Processed 5 pages for database ' My_DB ', file ' My_DB _log' on file 1.
RESTORE DATABASE successfully processed 108357 pages in 11.006 seconds (80.652 MB/sec).
When the database we try to restore does not exist and when the backup set is not a full backup, we receive the following error:
Msg 3118, Level 16, State 1, Line 1
The database " My_DB " does not exist. RESTORE can only create a database when restoring either a full backup or a file backup of the primary file.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
In this case we have to make sure we are using a Full backup to restore.
Before we do the restore process it is good to know the name of the “.mdf” and “.ldf” files in the backup set. To find this out we can run the RESTORE FILELISTONLY command in the following syntax:
RESTORE FILELISTONLY FROM
DISK = 'E:\Db_Backups\FILE1_FULL.BAK',
DISK = 'E:\Db_Backups\FILE2_FULL.BAK',
DISK = 'E:\Db_Backups\FILE3_FULL.BAK'
In the above example I assume the full backup consists of 3 files, “FILE1_FULL.BAK”, “FILE2_FULL.BAK”, and “FILE3_FULL.BAK”. The files in this case files are locate in E drive “Db_Backups” folder.
The above command will output the name of the “.mdf” and “.ldf” files contained in the backup set. Once we get those we can run the actual restore command in the following way:
RESTORE DATABASE My_DB FROM
DISK = 'E:\Db_Backups\FILE1_FULL.BAK',
DISK = 'E:\Db_Backups\FILE2_FULL.BAK',
DISK = 'E:\Db_Backups\FILE3_FULL.BAK'
WITH
MOVE My_DB ' TO 'E:\DATA\ My_DB.mdf',
MOVE My_DB _log' TO 'E:\LOGS\ My_DB _log.LDF',
STATS =1
Using the Move command we move the restored data and log files to a location of our choice and with STATS set as 1 we get a detailed verbose of the tasks happening similar to this:
1 percent processed.
2 percent processed.
3 percent processed.
…
100 percent processed.
Processed 108352 pages for database My_DB ', file My_DB ' on file 1.
Processed 5 pages for database ' My_DB ', file ' My_DB _log' on file 1.
RESTORE DATABASE successfully processed 108357 pages in 11.006 seconds (80.652 MB/sec).
When the database we try to restore does not exist and when the backup set is not a full backup, we receive the following error:
Msg 3118, Level 16, State 1, Line 1
The database " My_DB " does not exist. RESTORE can only create a database when restoring either a full backup or a file backup of the primary file.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
In this case we have to make sure we are using a Full backup to restore.
Comments