Home Forums SQL Server 2005 Administering How to get RESTORE FILELISTONLY resultset into a table? RE: How to get RESTORE FILELISTONLY resultset into a table?

  • Leo Nosovsky (2/14/2008)


    Does anyone know how to populate a table with the results of RESTORE FILELISTONLY for subsequent querying? Specifically, I need logical file names and their types from a db backup file.

    Thanks,

    Leo

    Hello Leo,

    Here is the logic. You can format as you like.

    declare @path varchar(25)

    create table #tmp

    (

    LogicalName nvarchar(128)

    ,PhysicalName nvarchar(260)

    ,Type char(1)

    ,FileGroupName nvarchar(128)

    ,Size numeric(20,0)

    ,MaxSize numeric(20,0),

    Fileidtinyint,

    CreateLSN numeric(25,0),

    DropLSN numeric(25, 0),

    UniqueID uniqueidentifier,

    ReadOnlyLSN numeric(25,0),

    ReadWriteLSN numeric(25,0),

    BackupSizeInBytes bigint,

    SourceBlocSize int,

    FileGroupId int,

    LogGroupGUID uniqueidentifier,

    DifferentialBaseLSN numeric(25,0),

    DifferentialBaseGUID uniqueidentifier,

    IsReadOnly bit,

    IsPresent bit

    )

    set @path = 'C:\Northwind.BAK'

    insert #tmp

    EXEC ('restore filelistonly from disk = ''' + @path + '''')

    select * from #tmp

    go

    drop table #tmp


    Lucky