Replication of production env database to staging prior to deployment with Octopus

ε祈祈猫儿з 提交于 2019-12-11 03:16:27

问题


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...


回答1:


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"


来源:https://stackoverflow.com/questions/25089325/replication-of-production-env-database-to-staging-prior-to-deployment-with-octop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!