繁体   English   中英

将生产环境数据库复制到使用Octopus进行部署之前的登台

[英]Replication of production env database to staging prior to deployment with 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"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM