https://stackoverflow.com/questions/22245808/sql-server-error-logical-file-is-not-part-of-database-use-restore-fileliston
I experienced this issue when trying to restore a database on MS SQL Server 2012.
Here's is my script for restoring the database:
USE master;
GO
ALTER DATABASE my_db SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
RESTORE DATABASE my_db
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\my_db_backup.bak'
WITH REPLACE,
MOVE 'my_db' TO 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\my_db.mdf',
MOVE 'my_db_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\my_db_log.ldf'
GO
ALTER DATABASE my_db SET MULTI_USER;
GO
And I was encountering the error:
Msg 3234, Level 16, State 1, Line 1
Logical file 'my_db' is not part of database 'my_db'.
Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Here's how I fixed it:
The issue was that I was not referencing the logical files properly.
I had to run the RESTORE FILELISTONLY
command below on the backup file:
RESTORE FILELISTONLY
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Backup\my_db_backup.bak'
This displayed the LogicalName and the corresponding PhysicalName of the Data and Log files for the database respectively:
LogicalName PhysicalName
com.my_db C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\com.my_db.mdf
com.my_db_log C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\com.m
1> RESTORE FILELISTONLY
2> FROM DISK = '/data/dbbackup/Camp_Macro.bak'
3> go
LogicalName PhysicalName Type FileGroupName Size MaxSize FileId CreateLSN DropLSN UniqueId ReadOnlyLSN ReadWriteLSN BackupSizeInBytes SourceBlockSize FileGroupId LogGroupGUID DifferentialB aseLSN DifferentialBaseGUID IsReadOnly IsPresent TDEThumbprint SnapshotUrl
-------------------------------------------------------------------------------------------------------------------------------- -------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------- ---- ---------------------------------------------------------------------------------------------------------- ---------------------- -------------------- -------------------- -------------------- --------------------------- --------------------------- ------------------------- ----------- --------------------------- --------------------------- -------------------- --------------- ----------- ------------------------------------ ------------- -------------- ------------------------------------ ---------- --------- ------------------------------------------ --------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------
Camp_Macros_Data C:\Program Files\Microsoft SQL Server\ MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Camp_Macro.mdf D PRIMARY 3211264 35184372080640 1 0 0 D3EF0F25-0362-4350-8E80-4 BCB3FAF2A61 0 0 3080192 512 1 NULL 1270 00000012200037 41407C89-4889-405C-8B5F-63D427939647 0 1 NULL NULL
Camp_Macros_Log C:\Program Files\Microsoft SQL Server\ MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Camp_Macro_1.ldf L NULL 4194304 2199023255552 2 0 0 65DD3631-9172-4C21-9BEB-8 B0AA88BBD23 0 0 0 512 0 NULL 0 00000000-0000-0000-0000-000000000000 0 1 NULL NULL
(2 rows affected)
Network packet size (bytes): 4096
1 xact[s]:
Clock Time (ms.): total 38 avg 38.0 (26.3 xacts per sec.)
No comments:
Post a Comment