SQL Server:强制备份/恢复位置

发布于 2024-11-30 08:50:27 字数 1358 浏览 1 评论 0原文

使用 BACKUP DATABASE 命令在笔记本电脑上复制了 SQL Server Express 数据库的副本,现在我尝试使用 T-SQL 语句将其恢复到另一台计算机上:

RESTORE DATABASE [OurDB]
FROM DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part1.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part2.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part3.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part4.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part5.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part6.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part7.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part8.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part9.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part10.bak'
WITH REPLACE
GO

但是当它尝试恢复我收到错误

消息 5133,级别 16,状态 1,第 1 行
目录查找文件“c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\AppConfig_Data.ndf”失败, 操作系统错误 3(无法检索此错误的文本。 原因:1815)。

还有其他几个,都是类似的错误。问题是 SQL Server 似乎正在尝试将数据库还原到目录 C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\(源计算机上的数据目录)备份是从.

但在新计算机上我想恢复到 SQL Server 数据路径是 C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA

如何更改数据中的路径-文件以使其恢复到正确的位置?

Took a copy of a database of SQL Server Express on a laptop using the BACKUP DATABASE command, now I'm trying to restore it to a different computer using the T-SQL statement:

RESTORE DATABASE [OurDB]
FROM DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part1.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part2.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part3.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part4.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part5.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part6.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part7.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part8.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part9.bak',
DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part10.bak'
WITH REPLACE
GO

But when it tries to restore I get the error

Msg 5133, Level 16, State 1, Line 1
Directory lookup for the file "c:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\DATA\AppConfig_Data.ndf" failed with the
operating system error 3 (failed to retrieve text for this error.
Reason: 1815).

And a couple of others, all similar errors. The problem is it looks like SQL Server is trying to restore the database to the directory C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\, the data directory on the source computer the backup was taken from.

But on the new computer I want to restore to the SQL Server data path is C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA

How do I change the path in the data-files to get it to restore to the correct location?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城旧梦 2024-12-07 08:50:27

您需要向 RESTORE 命令添加附加信息来定义这些位的位置 - 类似于:

RESTORE DATABASE [OurDB]
FROM DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part1.bak',
MOVE N'Your_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\OurDB.mdf',  
MOVE N'Your_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\OurDB_Log.ldf'

You need to add additional info to your RESTORE command to define where those bits should go - something like:

RESTORE DATABASE [OurDB]
FROM DISK = N'C:\Documents and Settings\Sam\Desktop\DBBackup\part1.bak',
MOVE N'Your_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\OurDB.mdf',  
MOVE N'Your_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\OurDB_Log.ldf'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文