【发布时间】:2017-01-04 22:39:06
【问题描述】:
我不确定如何调试它,假设这不是 cmdlet 的问题。我正在尝试用自动化工作流替换自动化 SQL 导出,但我似乎无法让 Start-AzureSqlDatabaseExport 工作——它不断收到以下警告和错误消息。
d4fc0004-0c0b-443e-ad1b-310af7fd4e2a:[localhost]:客户端会话 ID: 'c12c92eb-acd5-424d-97dc-84c4e9c4f914-2017-01-04 19:00:23Z'
d4fc0004-0c0b-443e-ad1b-310af7fd4e2a:[localhost]:客户端请求 ID: 'd534f5fd-0fc0-4d68-8176-7508b35aa9d8-2017-01-04 19:00:33Z'
Start-AzureSqlDatabaseExport : 对象引用未设置为对象的实例。
在 DBBackup:11 字符:11 + + CategoryInfo : NotSpecified: (:) [Start-AzureSqlDatabaseExport], NullReferenceException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.SqlDatabase.Database.Cmdlet.StartAzureSqlDatabaseExport
这似乎与其他一些问题相似,但它们似乎没有答案或不适用。我在 Powershell 环境中确实有类似的过程。我用 Azure 的自动导出替换了该过程,现在这似乎是一个糟糕的选择!我尝试了许多变体,例如使用 sqlcontext 和 databasename 而不是数据库。
这是我的代码,其中敏感部分替换为 ****:
workflow DBBackup {
param(
[parameter(Mandatory=$true)]
[string] $dbcode
)
$cred = Get-AutomationPSCredential -Name "admindbcredentials"
$VerbosePreference = "Continue"
inlineScript {
$dbcode = $using:dbcode
$cred = $using:cred
if ($dbcode -eq $null)
{
Write-Output "Database code must be specified"
}
Else
{
$dbcode = $dbcode.ToUpper()
$dbsize = 1
$dbrestorewait = 10
$dbserver = "kl8p7d444a"
$stacct = $dbcode.ToLower()
$stkey = "***storagekey***"
Write-Verbose "DB Server '$dbserver' DB Code '$dbcode'"
Write-Verbose "Storage Account '$stacct'"
$url = "https://$dbserver.database.windows.net"
$sqlctx = New-AzureSqlDatabaseServerContext -ManageUrl $url -Credential $cred
# $sqlctx = New-AzureSqlDatabaseServerContext -ManageUrl $url -Credential $cred
$stctx = New-AzureStorageContext -StorageAccountName $stacct -StorageAccountKey $stkey
$dbname = "FSUMS_" + $dbcode
$dt = Get-Date
$timestamp = $dt.ToString("yyyyMMdd") + "_" + $dt.ToString("HHmmss")
$bkupname = $dbname + "_" + $timestamp + ".bacpac"
$stcon = Get-AzureStorageContainer -Context $stctx -Name "backups"
$db = Get-AzureSqlDatabase -Context $sqlctx -DatabaseName $dbname
Write-Verbose "Backup $dbname to $bkupname in storage account $stacct"
Start-AzureSqlDatabaseExport $sqlctx -DatabaseName $dbname -StorageContainer $stcon -BlobName $bkupname
}
}
}
【问题讨论】:
标签: azure automation export backup workflow