【问题标题】:Replication of production env database to staging prior to deployment with Octopus在使用 Octopus 部署之前将生产环境数据库复制到登台
【发布时间】:2014-08-01 22:02:24
【问题描述】:

为了更好地验证我的数据库脚本的部署,作为我 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 带来了很多负载(由于某种原因在运行时无法登录我的门户)。任何想法将不胜感激......

【问题讨论】:

    标签: powershell continuous-integration azure-sql-database octopus-deploy system-testing


    【解决方案1】:

    只是想我会回复一下进展情况。我将以下脚本添加到我的 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"
    

    【讨论】:

    • 你还在用这样的脚本吗?我在WHILE 循环的最后一次调用中收到两个警告和一个错误。你有什么想法吗?
    • 不,抱歉。我切换到使用 deploy.cmd 来使用 Azure CI,而不是使用静态测试数据库,因此不再需要将生产数据复制到测试数据库
    猜你喜欢
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 2013-10-15
    相关资源
    最近更新 更多