简体   繁体   English

在服务器之间复制数据库的脚本

[英]Script to copy database between servers

The answer from Spike here was very nearly exactly what we needed. 从狼牙答案在这里非常近正是我们所需要的。 The only hurdle is how to have the backup run on one server and the restore run on another through linked server all in one script ? 唯一的障碍是如何在一个脚本中通过一个链接服务器在一个服务器上运行备份,在另一个服务器上运行还原? It must be a script that can be turned into a stored procedure that's fed only source and destination DB names. 它必须是一个脚本,可以将其转换为仅提供源数据库名称和目标数据库名称的存储过程。

Does it present a problem that the source server is SQL Server Express 2012 whereas the destination is the full version? 是否存在源服务器是SQL Server Express 2012而目标服务器是完整版本的问题?

It has to be a script that can run against any DB by just changing the DB name and logical names. 它必须是可以通过更改数据库名称和逻辑名称而可以对任何数据库运行的脚本。 It's for a process that's need to run very regularly and fully automatically against a different DB each time. 这是一个需要定期,完全自动地针对不同数据库运行的过程。

Also, why wouldn't be better to just detach, copy the mdf and ldf, then re-attach? 另外,为什么最好不分离,复制mdf和ldf,然后重新附加呢?

I'd suggest right clicking on the database in Management Studio, clicking Tasks then Generate Scripts. 我建议右键单击Management Studio中的数据库,单击“任务”,然后单击“生成脚本”。

You can script your entire database (make sure in advanced options you select to script both schema and data) and restore it on the other database. 您可以编写整个数据库的脚本(确保在高级选项中选择了编写架构和数据的脚本),并将其还原到另一个数据库上。

You can also backup from one instance and onto another but bear in mind this may have issues if you're moving between versions. 您也可以从一个实例备份到另一个实例,但是请记住,如果在两个版本之间移动,这可能会出现问题。

Transfering LDF/MDF files is possible but in my opinion is difficult and high risk. 可以传输LDF / MDF文件,但我认为这很困难且风险很高。

You can copy a database from one server to another, just follow those steps (SQL Server 2008): 1.Select the database in the source server in SSMS. 您可以按照以下步骤(SQL Server 2008)将数据库从一台服务器复制到另一台服务器:1.在SSMS的源服务器中选择数据库。 2. Right click ->Tasks->Copy Database Wizard to launch the copy database wizard . 2. 右键单击->任务->复制数据库向导以启动复制数据库向导 Enter the source and destination credentials and select either attach/detach or SMO type click next and you can schedule or run immediately, Click finish. 输入源和目标凭据,然后选择附加/分离或SMO类型,然后单击下一步,您可以计划或立即运行,单击完成。

For your reference: 供你参考:

http://msdn.microsoft.com/en-us/library/ms188664.aspx http://msdn.microsoft.com/en-us/library/ms188664.aspx

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

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