如何使用PowerShell在弹性池中复制数据库

时间:2018-10-11 22:54:01

标签: powershell azure-sql-database azure-elasticpool

您能否建议将同一数据库中的一个数据库复制到另一个数据库的PowerShell代码?

我正在尝试使用

  1. New-AzureRmSqlDatabaseCopy,但执行失败,因为New-AzureRmSqlDatabaseCopy不适用于弹性池。
  2. How to Execute and Store Transact-SQL (T-SQL) Query Results in a PowerShell Array,但由于超时异常而出错。
  3. Invoke-Sqlcmd也失败,并出现 Invoke-Sqlcmd:执行超时到期。操作完成之前已过超时时间,或者服务器未响应异常。

这是我需要的:

  1. 将数据库复制到同一弹性池中。手动执行操作时,我使用“创建数据库[数据库名称_02]作为[数据库名称_01]的副本” T-SQL脚本。
  2. 在复制时收到通知(大约需要5-7分钟的时间),或者在复制失败时收到错误消息。

提前非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我认为New-AzureRmSqlDatabaseCopy可以正常工作,如果要在弹性池中复制数据库,则数据库及其副本应位于同一台sql服务器中。

您可以尝试下面的命令,它对我而言效果很好。

New-AzureRmSqlDatabaseCopy -ResourceGroupName <ResourceGroupName> -ServerName <ServerName> -DatabaseName <databaseName of the db to be copied> -CopyDatabaseName <databaseName of the copy> -ElasticPoolName <ElasticPoolName>

enter image description here

检查门户:

enter image description here

相关问题