简体   繁体   English

寻求从多个bak文件还原到测试SQL数据库

[英]Seeking to restore from multiple bak files to a test SQL database

we have a large SQL db that we split into 4 separate bak files in a nightly backup so it can be more easily sent offsite. 我们有一个大的SQL数据库,我们在夜间备份中分成4个独立的bak文件,因此可以更容易地发送到异地。 We use this statement (db names changed) 我们使用此语句(更改了db名称)

BACKUP DATABASE [Data] TO
DISK = 'd:\back\data1.bak',
DISK = 'd:\back\data2.bak',
DISK = 'd:\back\data3.bak',
DISK = 'd:\back\data4.bak'
WITH  INIT, NOUNLOAD, NAME = 'Data backup',  NOSKIP ,  STATS = 10,  NOFORMAT

All four of the backups have the same logical names for the mdf and ldf files in the bak. 所有四个备份都具有bak中mdf和ldf文件的相同逻辑名称。

I want to be able to restore these four backups into a different database on the server for testing. 我希望能够将这四个备份还原到服务器上的不同数据库中进行测试。 I found a t-sql script in this post which I think will do this but I am not sure. 我在这篇文章中发现了一个t-sql脚本,我认为会这样做,但我不确定。 Can someone help? 有人可以帮忙吗?

I'm thinking I could adapt and run the script as follows: 我想我可以调整并运行脚本如下:

RESTORE DATABASE Data_test FROM
DISK = 'd:\back\data1.bak',
DISK = 'd:\back\data2.bak',
DISK = 'd:\back\data3.bak',
DISK = 'd:\back\data4.bak'
WITH MOVE 'Prod_Data' TO 'D:\SQLDb\Data_Test1.mdf',
MOVE 'Prod_Data' TO 'D:\SQLDb\Data_Test2.ndf',
MOVE 'Prod_Data' TO 'D:\SQLDb\Data_Test3.ndf',
MOVE 'Prod_Data' TO 'D:\SQLDb\Data_Test4.ndf',
MOVE 'Prod_Log' TO 'C:\SQLtlogs\Data_test1.ldf'

Do you think this would work? 你认为这会有用吗? And will this test db not conflict with the prod db from which it was restored? 并且这个测试db是否与恢复它的prod db不冲突? Any help would be great, thanks. 任何帮助都会很棒,谢谢。

OK, I actually got this to work with the GUI for SSMS. 好的,我实际上已经使用了SSMS的GUI。 All you have to do is choose Tasks, Restore Database, choose from device, then add all four files of the separate bak files, then click OK and do the restore with Overwrite, modifying the file names for mdf and ldf as needed so they are for the test db and not production. 您所要做的就是选择Tasks,Restore Database,从设备中选择,然后添加单独bak文件的所有四个文件,然后单击OK并使用Overwrite进行恢复,根据需要修改mdf和ldf的文件名,这样它们就是用于测试db而不是生产。 SSMS knows the four files are part of the same media set and reassembles them into the mdf and ldf file. SSMS知道这四个文件是同一媒体集的一部分,并将它们重新组合成mdf和ldf文件。 Looks like I did not need a script after all. 看起来我毕竟不需要脚本。

I used this TRANSACT-SQL command to do almost the same thing you requested. 我用这个TRANSACT-SQL命令做了你要求的几乎相同的事情。 The only difference is that I was only moving each logical file to a single physical file. 唯一的区别是我只是将每个逻辑文件移动到一个物理文件。 My command (modified to use your example) looks like this: 我的命令(修改为使用您的示例)如下所示:

RESTORE DATABASE Data_test FROM
DISK = 'd:\back\data1.bak',
DISK = 'd:\back\data2.bak',
DISK = 'd:\back\data3.bak',
DISK = 'd:\back\data4.bak'
WITH MOVE 'Prod_Data' TO 'D:\SQLDb\Data_Test1.mdf',
MOVE 'Prod_Log' TO 'C:\SQLtlogs\Data_test1.ldf'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM