简体   繁体   English

SQL Server数据库复制到另一台服务器(分离并附加)

[英]SQL Server database copy to another server (detach and attach)

I need to copy a database from one server to another. 我需要将数据库从一台服务器复制到另一台服务器。 We follow the detach and attach method. 我们遵循分离和附加方法。 However since replication is configured on the source server, every time we need to unconfigure the replication and detach the DB to copy. 但是,由于复制是在源服务器上配置的,因此每次我们需要取消配置复制并分离数据库以进行复制时。 If I stop the SQL services and copy the .mdf and .ldf files, will it be same as detaching and copying? 如果停止SQL服务并复制.mdf.ldf文件,它将与分离和复制相同吗?

Don't use the attach/detach method; 不要使用attach / detach方法; it keeps part of the replication configuration as you've already discovered. 正如您已经发现的那样,它保留了复制配置的一部分。 Besides, that will require taking your database offline, even if it's briefly. 此外,这将需要使您的数据库脱机,即使是短暂的。

Backup/restore of a DB configured for replication does not carry repl configuration with it. 配置用于复制的数据库的备份/还原不带有repl配置。 If all you need is a standalone copy of the DB, just do a backup using COPY_ONLY option and restore it wherever you need to. 如果您需要的只是数据库的独立副本,则只需使用COPY_ONLY选项进行备份,然后将其还原到所需位置即可。 If you want to preserve the repl configuration, easiest way is to setup repl using scripts. 如果要保留repl配置,最简单的方法是使用脚本设置repl。 That way, you just need to update the server/DB names whenever you need to deploy the same replication topology in a new environment. 这样,只要您需要在新环境中部署相同的复制拓扑,就只需更新服务器/数据库名称。 Strongly recommend you use variables for server & database names without actual values saved in the file. 强烈建议您为服务器和数据库名称使用变量,而不要在文件中保存实际值。 That way you only need to edit those each time you deploy and you won't accidentally deploy on the wrong server/database. 这样,您每次部署时只需要编辑那些内容,而不会意外地在错误的服务器/数据库上进行部署。 See links to BOL below for additional details on each area: 有关每个区域的更多详细信息,请参见下面的BOL链接:

Back Up and Restore Replicated Databases 备份和还原复制的数据库

Scripting Replication 脚本复制

There is no "correct" way to copy, because there are multiple ways to do so, and you do what works best for your scenario. 没有“正确”的复制方式,因为有多种复制方式,您可以根据自己的情况选择最合适的方式。 in your case, if you simply need a copy of the db on another server, do a database backup/restore instead, as it will be simpler than attach/detach since replication is involved. 在您的情况下,如果只需要在另一台服务器上复制数据库,则请执行数据库备份/还原,因为与复制相比,它比附加/分离更简单。

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

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