为了更好地验证我的数据库脚本的部署,我想使用生产数据库的镜像预初始化我的暂存数据库,作为我的 Octopus 部署的第一步。我正在使用 SQL Azure 和 DACFX。我很好奇是否还有其他人尝试过这个...
Start-AzureSqlDatabaseCopy
是用于此操作的正确 PS cmdlet 吗?- 这会影响我的生产环境的性能吗?
- 是否还有其他选择可供考虑?
更新
我开发了下面的脚本,它似乎有效。但是,在数据库完成复制之前,我无法阻止脚本的完成。在某些时候 Get-AzureSqlDatabaseCopy
会抛出错误(也许 Azure 无法处理负载?)。
Import-Module 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\ServiceManagement\Azure\Azure.psd1'
$serverName = "..."
$sourceDbName = "..."
$targetDbName = "..."
$testdb = Get-AzureSqlDatabase -ServerName $serverName -DatabaseName $targetDbName -ErrorAction SilentlyContinue
IF (!$testdb)
{
Write-Host "TestDB Not Found"
}
ELSE
{
Remove-AzureSqlDatabase -ServerName $serverName -Database $testdb -Force
}
$dbCopy = Start-AzureSqlDatabaseCopy -ServerName $serverName -DatabaseName $sourceDbName -PartnerDatabase $targetDbName
WHILE ($dbCopy)
{
Write-Progress -Activity "Copying Database" -PercentComplete [int]$dbCopy.PercentComplete
$dbCopy = Get-AzureSqlDatabaseCopy -ServerName $serverName -DatabaseCopy $dbCopy
# Sleep 10 seconds
[System.Threading.Thread]::Sleep(10000);
}
Write-Host "Complete"
我仍然不相信这是正确的方法&它似乎给 Azure 带来了很多负载(由于某种原因在运行时无法登录我的门户)。任何想法将不胜感激...
最佳答案
只是想我会回复这个进展如何。我将以下脚本添加到我的 UAT(暂存)环境的 Octopus 步骤中,并且运行良好。原始脚本的主要问题是我对 Write-Progess
的调用采用了错误的参数(我只是删除了该调用,因为无论如何它在 Octopus 中都无法正常工作)。
需要注意的一件事是,我确实必须让我的触手以我的用户身份运行。我想不出让 azure 脚本在本地系统下运行的方法。
Import-Module 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\ServiceManagement\Azure\Azure.psd1'
$serverName = "..."
$sourceDbName = "..."
$targetDbName = "..."
$testdb = Get-AzureSqlDatabase -ServerName $serverName -DatabaseName $targetDbName -ErrorAction SilentlyContinue
IF (!$testdb)
{
Write-Host "TestDB Not Found"
}
ELSE
{
Remove-AzureSqlDatabase -ServerName $serverName -Database $testdb -Force
}
$dbCopy = Start-AzureSqlDatabaseCopy -ServerName $serverName -DatabaseName $sourceDbName -PartnerDatabase $targetDbName
WHILE ($dbCopy)
{
$dbCopy = Get-AzureSqlDatabaseCopy -ServerName $serverName -DatabaseCopy $dbCopy
# Sleep 10 seconds
[System.Threading.Thread]::Sleep(10000);
}
Write-Host "Complete"
关于powershell - 在使用 Octopus 部署之前将生产环境数据库复制到暂存区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25089325/