I made a script to restore .bak or backup files. It works for some databases, but not for one. How do I make it work for any type of .bak file ? This is in sql server 2008. The error message is -
Msg 3234, Level 16, State 1, Line 1 Logical file 'Northwind_Data' is not part of database 'Northwind'. Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Line 1 RESTORE DATABASE is terminating abnormally.
Script -
IF DB_ID('Northwind') IS NULL BEGIN RESTORE DATABASE [Northwind] FILE = N'Northwind_Data' FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\Backup\Northwind.bak' WITH FILE = 1, MOVE N'Northwind_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind.mdf', MOVE N'Northwind_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind_0.LDF', NOUNLOAD, STATS = 10 END
SQL-Server: Error - Logical file is not part of database. Use RESTORE FILELISTONLY to list the logical file names - Stack Overflow SQL-Server: Error - Logical file is not part of database. Use RESTORE FILELISTONLY to list the logical file names
Error - Logical file is not part of database. Use RESTORE FILELISTONLY to list the logical file names Error - Logical file is not part of database. Use RESTORE FILELISTONLY to list the logical file names I made a script to restore .bak or backup files.
Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Line 1 RESTORE DATABASE is terminating abnormally. Show activity on this post. And then replace logical name shown by RESTORE FILELISTONLY in script below
Use RESTORE FILELISTONLY to list the logical file names. Msg 3013, Level 16, State 1, Line 1 RESTORE DATABASE is terminating abnormally. The issue was that I was not referencing the logical files properly.
Please run below sql and check logical names
RESTORE FILELISTONLY FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\Backup\Northwind.bak'
And then replace logical name shown by RESTORE FILELISTONLY
in script below
--If database already exists do not restore IF DB_ID('Northwind') IS NULL BEGIN RESTORE DATABASE [Northwind] FILE = N'Northwind_Data' FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\Backup\Northwind.bak' WITH FILE = 1, NOUNLOAD, STATS = 10, MOVE N'YOUR logical name of data file as shown by RESTORE FILELISTONLY command' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind.mdf', MOVE N'YOUR logical name of Log file as shown by RESTORE FILELISTONLY command' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind_0.LDF' END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With