SQL Server RESTORE FILELISTONLY

Overview

The RESTORE FILELISTONLY option allows you to see a list of the files that were backed up.  So for example if you have a full backup you will see all of the data files (mdf) and the log file (ldf).

Explanation

This information can only be returned using T-SQL there is not a way to get this information from SQL Server Management Studio. Although if you do a restore and select options, you will see some of this information in SSMS.

The RESTORE FILELISTONLY option can be simply issued as follows for a backup that exists on disk.  If there are multiple backups in one file and you do not specify “WITH FILE = X” you will only get information for the first backup in the file.  To get the FILE number use RESTORE HEADERONLY and use the “Position” column.

Get filelistlonly information from a backup file

RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.BAK' WITH FILE = 1
GO

The result set would like the following.  The things that are helpful here include the LogicalName and PhysicalName.

ColumnNameValue – Row 1
LogicalNameAdventureWorks_Data
PhysicalNameC:\Program Files\Microsoft
SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf
TypeD
FileGroupNamePRIMARY
Size202113024
MaxSize35184372080640
FileId1
CreateLSN0
DropLSN0
UniqueId50A534B0-156C-42B7-82FE-A57D21A53EEA
ReadOnlyLSN0
ReadWriteLSN0
BackupSizeInBytes177012736
SourceBlockSize512
FileGroupId1
LogGroupGUIDNULL
DifferentialBaseLSN0
DifferentialBaseGUID00000000-0000-0000-0000-000000000000
IsReadOnly0
IsPresent1
ColumnNameValue – Row2
LogicalNameAdventureWorks_Log
PhysicalNameC:\Program Files\Microsoft
SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Log.ldf
TypeL
FileGroupNameNULL
Size153092096
MaxSize2199023255552
FileId2
CreateLSN0
DropLSN0
UniqueId4F544777-6DBB-4BBC-818A-72C0B878610C
ReadOnlyLSN0
ReadWriteLSN0
BackupSizeInBytes0
SourceBlockSize512
FileGroupId0
LogGroupGUIDNULL
DifferentialBaseLSN0
DifferentialBaseGUID00000000-0000-0000-0000-000000000000
IsReadOnly0
IsPresent1

Leave a Reply

Your email address will not be published. Required fields are marked *