将 SQL Server 2008 R2 备份/恢复移动到分离/重新附加
我正在努力更新框架来测试数据库驱动的代码。在每次对数据库进行写入测试之前,都会对数据库备份执行RESTORE ,这需要 15-20 秒,所以我试图通过保留分离的 mdf、ldf 和 ndf 文件的“备份”来加快速度,以便我可以 在每次测试之前创建数据库...用于附加。问题是,使用 RESTORE 时,您可以使用类似以下内容“移动”(或者更具体地说,选择将备份还原到的位置)mdf、ldf 和 ndf 文件:
RESTORE DATABASE [testDB]
FROM DISK = N'\\Path\To\Backup' WITH FILE = 1, RECOVERY,
MOVE N'testDB' TO N'\\Path\To\MDF',
MOVE N'testDB_log' TO N'\\Path\To\LDF',
MOVE N'ftrow_testDB' TO N'\\Path\To\NDF',
NOUNLOAD, REPLACE, STATS = 1
但是,使用 CREATE DATABASE FOR ATTACH,我可以似乎没有找到任何方法来“移动”mdf、ldf 和 ndf 文件。当您附加时,它只使用您指定的文件作为数据库文件:
CREATE DATABASE [testDB] ON
(FILENAME = N'\\Path\To\MDF'),
(FILENAME = N'\\Path\To\LDF'),
(FILENAME = N'\\Path\To\NDF')
FOR ATTACH
这意味着要保留这三个文件的“备份”,我每次都需要从备份目录中复制它们,这比取消更耗时消除任何速度增益。
有人对如何使其发挥作用有任何想法吗?
I'm working on updating a framework to test database driven code. Before every write test to the database it's doing a RESTORE of a database backup, which is taking 15-20 seconds, so I'm trying to speed it up by keeping a "backup" of detached mdf, ldf, and ndf files so that I can just CREATE DATABASE...FOR ATTACH before every test. The problem is that when using RESTORE, you can "move" (or, more specifically, choose where to restore the backup into) the mdf, ldf, and ndf files with something like this:
RESTORE DATABASE [testDB]
FROM DISK = N'\\Path\To\Backup' WITH FILE = 1, RECOVERY,
MOVE N'testDB' TO N'\\Path\To\MDF',
MOVE N'testDB_log' TO N'\\Path\To\LDF',
MOVE N'ftrow_testDB' TO N'\\Path\To\NDF',
NOUNLOAD, REPLACE, STATS = 1
However, with CREATE DATABASE FOR ATTACH, I can't seem to find any way to "move" the mdf, ldf, and ndf files. When you attach, it just uses the files you specify as the database files:
CREATE DATABASE [testDB] ON
(FILENAME = N'\\Path\To\MDF'),
(FILENAME = N'\\Path\To\LDF'),
(FILENAME = N'\\Path\To\NDF')
FOR ATTACH
This means to keep a "backup" of those three files I'll need to copy them from a backup directory every time, which is time consuming and more than cancels out any speed gains.
Anyone have any ideas on how to make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想不出任何方法来让它工作,所以我只是尽可能地缩小数据库并将它们置于简单恢复模式 - 这加快了相当多的速度。
I couldn't figure out any way to get this to work, so I just shrunk the databases as much as I could and put them in simple recovery mode - that sped it up a decent amount.