如何在sql server 2008中恢复备份文件时处理.ndf文件

时间:2013-05-16 10:06:19

标签: sql-server sql-server-2008 sql-server-2008-r2

我正在尝试通过.bak文件恢复数据库,同时恢复我遇到了这个错误

enter image description here

如何避免此错误并成功恢复,

注意:针对此Dababase

1. one .mdf file Ex: <DBNAME>_Primary01.mdf (Logical Name: FI_Primary)
2. one .ldf file EX: <DBNAME>_Log01.ldf (Logical Name: FI_Log)
3. six .ndf file Ex: <DBNAME>_Data01.ndf (Logical Name: FI_Data)
                 Ex: <DBNAME>_Data_201.ndf(Logical Name: FI_Data_2)
                 Ex: <DBNAME>_Index01.ndf(Logical Name: FI_Index)
                 Ex: <DBNAME>_Index_201.ndf(Logical Name: FI_Index_2)
                 Ex: <DBNAME>_Large01.ndf(Logical Name: FI_Large)
                 Ex: <DBNAME>_Large_Index01.ndf(Logical Name: FI_Large_Index)

RESTORE DATABASE [MESDB] FROM  DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup\MESDB.bak' 
WITH  FILE = 1,  MOVE N'FI_Primary' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MESDB.mdf',  
MOVE N'FI_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MESDB.ndf',  
MOVE N'FI_Index' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MESDB.ndf',  
MOVE N'FI_Data_2' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MESDB.ndf', 
 MOVE N'FI_Index_2' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MESDB.ndf',  
 MOVE N'FI_Large' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MESDB.ndf',  
 MOVE N'FI_Large_Index' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MESDB.ndf',  
 MOVE N'FI_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MESDB.ldf',  NOUNLOAD,  STATS = 10
GO

2 个答案:

答案 0 :(得分:2)

你最喜欢已经在“C:\ Program Files \ Microsoft SQL Server \ MSSQL10.MSSQLSERVER \ MSSQL \ DATA \ MESDB.ndf”中拥有一个数据库文件,并将其附加到正在运行的数据库。

您应删除现有数据库,或还原到新位置。我将您的路径重命名为名为DATA2的目录。那应该没问题。

RESTORE DATABASE [MESDB] FROM  DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup\MESDB.bak' 
WITH  FILE = 1,  MOVE N'FI_Primary' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA2\MESDB.mdf',  
MOVE N'FI_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA2\MESDB.ndf',  
MOVE N'FI_Index' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA2\MESDB.ndf',  
MOVE N'FI_Data_2' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA2\MESDB.ndf', 
MOVE N'FI_Index_2' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA2\MESDB.ndf',  
MOVE N'FI_Large' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA2\MESDB.ndf',  
MOVE N'FI_Large_Index' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA2\MESDB.ndf',  
MOVE N'FI_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA2\MESDB.ldf',  NOUNLOAD,  STATS = 10
GO

答案 1 :(得分:1)

您不能在同一文件路径中拥有多个数据文件(显然......)。 MESDB.ndf用于多个文件。为每个文件提供唯一的物理路径。