简体   繁体   中英

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?

Don't use the attach/detach method; 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. 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. If you want to preserve the repl configuration, easiest way is to setup repl using scripts. 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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