繁体   English   中英

Azure 导出 SQL 数据库示例

[英]Azure Export SQL database example

鉴于 Microsoft 正在弃用以前的导出 SQL 数据库的方法,他们在此处提供了一个建议示例:

$subscriptionId = "YOUR AZURE SUBSCRIPTION ID"

Login-AzureRmAccount
Set-AzureRmContext -SubscriptionId $subscriptionId

# Database to export
$DatabaseName = "DATABASE-NAME"
$ResourceGroupName = "RESOURCE-GROUP-NAME"
$ServerName = "SERVER-NAME"
$serverAdmin = "ADMIN-NAME"
$serverPassword = "ADMIN-PASSWORD" 
$securePassword = ConvertTo-SecureString -String $serverPassword -AsPlainText -Force
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $serverAdmin, $securePassword

# Generate a unique filename for the BACPAC
$bacpacFilename = $DatabaseName + (Get-Date).ToString("yyyyMMddHHmm") + ".bacpac"

# Storage account info for the BACPAC
$BaseStorageUri = "https://STORAGE-NAME.blob.core.windows.net/BLOB-CONTAINER-NAME/"
$BacpacUri = $BaseStorageUri + $bacpacFilename
$StorageKeytype = "StorageAccessKey"
$StorageKey = "YOUR STORAGE KEY"

$exportRequest = New-AzureRmSqlDatabaseExport -ResourceGroupName $ResourceGroupName -ServerName $ServerName `
   -DatabaseName $DatabaseName -StorageKeytype $StorageKeytype -StorageKey $StorageKey -StorageUri $BacpacUri `
   -AdministratorLogin $creds.UserName -AdministratorLoginPassword $creds.Password
$exportRequest

# Check status of the export
Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $exportRequest.OperationStatusLink

我已按照他们的示例中的建议填写了所有凭据,但出现此错误:

New-AzureRmSqlDatabaseExport : NotFound: Entity not found to invoke export
At C:\Users\bob\Desktop\DBBackupScript.ps1:47 char:18
+ ... rtRequest = New-AzureRmSqlDatabaseExport -ResourceGroupName $Resource ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureRmSqlDatabaseExport], CloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.ImportExport.Cmdlet.NewAzureSqlDatabaseExport

有谁知道我做错了什么?

使用 az sql db export 时,数据库名称似乎区分大小写。 在我的情况下,更正数据库名称和资源组的大小写解决了这个问题。

上面问题中的 PowerShell 脚本示例已按我的预期工作。

但是,即使尝试使用不存在的资源组、数据库服务器或数据库,我也无法重现与您相同的错误消息。

重要的提示:

  1. 对于$serverAdmin$serverPassword ,它们的值应该是单引号而不是双引号以使脚本工作
  2. 检查AzureRm.Sql模块的版本。 我的测试工作是2.5.0
  3. 尝试将-Debug用于您的New-AzureRmSqlDatabaseExport命令行以查看详细信息

看起来很愚蠢,但对我来说错误是因为我的“DatabaseName”参数区分大小写。

我正在发送值“数据库”,但实际的数据库名称是“数据库”

看起来很疯狂,但可能会帮助某人

暂无
暂无

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

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