如何在 SQL Server 2008 R2 中还原 .bak 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14040983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to restore .bak file in SQL Server 2008 R2
提问by Yunus emre
I have a code blog but a problem was occurred. In here my backup file is ISBANK.bak
and database name is new database name. It doesn't contain anything. I want to add .bak
file's content to a new database..
我有一个代码博客,但出现了问题。在这里我的备份文件ISBANK.bak
和数据库名称是新的数据库名称。它不包含任何东西。我想将.bak
文件的内容添加到新数据库中..
RESTORE DATABASE [DBName]
FROM DISK = 'D:\ISBANK.bak'
WITH REPLACE,
MOVE 'DBName' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008RR2\MSSQL\DATA\DBName.mdf',
MOVE 'DBName' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008RR2\MSSQL\DATA\DBName.ldf'
I am getting these errors:
我收到这些错误:
Msg 5133, Level 16, State 1, Line 1
Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL10.SQLSRV2008\MSSQL\DATA\OBERNET_DENEME.mdf" failed with the operating system error 3 (failed to retrieve text for this error. Reason: 15105).
Msg 3156, Level 16, State 3, Line 1
File 'OCEAN' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLSRV2008\MSSQL\DATA\OBERNET_DENEME.mdf'. Use WITH MOVE to identify a valid location for the file.
Msg 5133, Level 16, State 1, Line 1
Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL10.SQLSRV2008\MSSQL\DATA\OBERNET_DENEME.ldf" failed with the operating system error 3 (failed to retrieve text for this error. Reason: 15105).
Msg 3156, Level 16, State 3, Line 1
File 'OCEAN_log' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLSRV2008\MSSQL\DATA\OBERNET_DENEME.ldf'. Use WITH MOVE to identify a valid location for the file.
Msg 3119, Level 16, State 1, Line 1
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
消息 5133,级别 16,状态 1,行 1
文件“C:\Program Files\Microsoft SQL Server\MSSQL10.SQLSRV2008\MSSQL\DATA\OBERNET_DENEME.mdf”的目录查找失败,操作系统错误 3(无法检索此错误的文本。原因:15105)。
消息 3156,级别 16,状态 3,第 1 行
文件“OCEAN”无法恢复到“C:\Program Files\Microsoft SQL Server\MSSQL10.SQLSRV2008\MSSQL\DATA\OBERNET_DENEME.mdf”。使用 WITH MOVE 标识文件的有效位置。
消息 5133,级别 16,状态 1,行 1
文件“C:\Program Files\Microsoft SQL Server\MSSQL10.SQLSRV2008\MSSQL\DATA\OBERNET_DENEME.ldf”的目录查找失败,操作系统错误 3(无法检索此错误的文本。原因:15105)。
消息 3156,级别 16,状态 3,第 1 行
文件“OCEAN_log”无法恢复到“C:\Program Files\Microsoft SQL Server\MSSQL10.SQLSRV2008\MSSQL\DATA\OBERNET_DENEME.ldf”。使用 WITH MOVE 标识文件的有效位置。
消息 3119,级别 16,状态 1,第 1 行
规划 RESTORE 语句时发现了问题。以前的消息提供了详细信息。
消息 3013,级别 16,状态 1,第 1 行
RESTORE DATABASE 异常终止。
回答by Hammad Khan
Edit
编辑
Remove WITH REPLACE
用替换删除
RESTORE DATABASE my_new_database FROM disk = 'E:\path_to_bak_file\database_name_634182143083281212.bak'
WITH
MOVE 'the logical name from previous operation check row 1' TO 'E:\path_to_sql2008_file_onyour_machine\my_new_database.mdf',
MOVE 'the logical name from previous operation check row 2' TO 'E:\path_to_sql2008_file_onyour_machine\my_new_database_log.ldf'
GO
You can also use the Restore utility available in SQL Server Management Studio (SSMS). This is a step by step process which lets yous select the .bak file and restore it as new database (which ever name you like for it).
您还可以使用 SQL Server Management Studio (SSMS) 中提供的还原实用程序。这是一个循序渐进的过程,可让您选择 .bak 文件并将其恢复为新数据库(您喜欢的任何名称)。
Fire SQL Server Management Studio, connect to the server as admin, right click on the database node and select restore.
Fire SQL Server Management Studio,以管理员身份连接到服务器,右键单击数据库节点并选择恢复。