在使用Octopus部署之前将生产环境数据库复制到暂存 [英] Replication of production env database to staging prior to deployment with Octopus
问题描述
为了更好地验证我的数据库脚本的部署,我想使用生产数据库的镜像预先初始化我的Staging数据库,作为我的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-主机未找到TestDB
}
ELSE
{
Remove-AzureSqlDatabase -ServerName $ serverName -Database $ testdb -Force
}
$ dbCopy = Start-AzureSqlDatabaseCopy -ServerName $ serverName -DatabaseName $ sourceDbName -PartnerDatabase $ targetDbName
WHILE($ dbCopy)
{
Write-Progress-Activity复制数据库 -PercentComplete [int] $ dbCopy.PercentComplete
$ dbCopy = Get-AzureSqlDatabaseCopy -ServerName $ serverName -DatabaseCopy $ dbCopy
#睡眠10秒
[System.Threading.Thread] :: Sleep(10000);
}
写主机完成
m仍然不相信这是正确的方式去&它似乎给Azure上的很多负载(无法登录到我的门户,而这是由于某种原因运行)。任何想法都会感激...
只是想我会回复这个进步是怎么回事。我添加了以下脚本到我的UOP(分段)环境的我的章鱼的步骤,它已经很好地工作。原始脚本的主要问题是,我调用 Write-Progess
时采用了一个错误的参数(我刚刚删除了调用,因为它不会在八达通工作正常)。
需要注意的一点是,我必须让我的触手作为我的用户运行。我不知道如何让天蓝色的脚本在本地系统下运行。
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)
{
写主机未找到TestDB
}
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
#睡眠10秒
[System.Threading.Thread] ::睡眠(10000);
}
写主机完成
In order to verify the deployment of my database scripts better, I'd like to pre-initialize my Staging database with a mirror image of the Production database as a first step in my Octopus deployment. I'm using SQL Azure and DACFX. I'm curious if anyone else has tried this...
- Is
Start-AzureSqlDatabaseCopy
the right PS cmdlet to use for this operation? - Will this effect the performance of my production environment?
- Are there any other options to consider?
Update
I developed the below script, which seems to work. However, I'm having trouble blocking completion of the script until the database is finished copying. At some point Get-AzureSqlDatabaseCopy
will throw an error (maybe Azure can't handle the load?).
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"
I'm still not convinced this is the right way to go & it seems to put a lot of load on Azure (wasn't able to log into my portal while this was running for some reason). Any thoughts would be appreciated...
Just thought I'd reply back with how this progress went. I added the below script to my Octopus steps for my UAT (staging) environment and it has been working out very well. The main issue with the original script was that my call to Write-Progess
was taking a bad parameter (I just removed the call since it wouldn't have worked right in Octopus anyway).
One thing to note is that I did have to make my tentacle run as my user. I couldn't figure out a way to get the azure scripts to run under the local system.
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"
这篇关于在使用Octopus部署之前将生产环境数据库复制到暂存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!