Azure Export SQL 数据库示例
Azure Export SQL database example
鉴于 Microsoft 正在弃用以前导出 SQL 数据库的方法,他们提出了一个建议示例 here:
$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
有谁知道我做错了什么吗?
你上面问题中的 PowerShell 脚本示例已经过测试,按我的预期工作。
但是,即使尝试使用 non-existent 资源组、数据库服务器或数据库,我也无法重现与您相同的错误消息。
重要提示:
- 对于
$serverAdmin
和 $serverPassword
,它们的值应该是 single-quoted 而不是 double-quoted 脚本才能工作
- 检查
AzureRm.Sql
模块的版本。我的测试工作是 2.5.0
- 尝试使用 -Debug 作为您的
New-AzureRmSqlDatabaseExport
命令行以查看详细信息
这刚从 MS/Azure 出来,对数据库导出有很大帮助。
使用 az sql db export 时,数据库名称似乎区分大小写。在我的案例中,更正数据库名称和资源组的大小写解决了这个问题。
看起来真的很愚蠢,但对我来说错误是因为我的“DatabaseName”参数区分大小写。
我发送的值是 "database" 但实际的数据库名称是 "Database"
看起来很疯狂,但可能会帮助别人
鉴于 Microsoft 正在弃用以前导出 SQL 数据库的方法,他们提出了一个建议示例 here:
$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
有谁知道我做错了什么吗?
你上面问题中的 PowerShell 脚本示例已经过测试,按我的预期工作。
但是,即使尝试使用 non-existent 资源组、数据库服务器或数据库,我也无法重现与您相同的错误消息。
重要提示:
- 对于
$serverAdmin
和$serverPassword
,它们的值应该是 single-quoted 而不是 double-quoted 脚本才能工作 - 检查
AzureRm.Sql
模块的版本。我的测试工作是 2.5.0 - 尝试使用 -Debug 作为您的
New-AzureRmSqlDatabaseExport
命令行以查看详细信息
这刚从 MS/Azure 出来,对数据库导出有很大帮助。
使用 az sql db export 时,数据库名称似乎区分大小写。在我的案例中,更正数据库名称和资源组的大小写解决了这个问题。
看起来真的很愚蠢,但对我来说错误是因为我的“DatabaseName”参数区分大小写。
我发送的值是 "database" 但实际的数据库名称是 "Database"
看起来很疯狂,但可能会帮助别人