简体   繁体   English

Azure 导出 SQL 数据库示例

[英]Azure Export SQL database example

Given Microsoft is deprecating the previous method of exporting a SQL DB they have put up a suggested example here :鉴于 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

I have filled in all the credentials as suggested in their example and I am getting this error:我已按照他们的示例中的建议填写了所有凭据,但出现此错误:

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

Does anyone have any idea what I am doing wrong?有谁知道我做错了什么?

It appears that the database name is case sensitive when using az sql db export.使用 az sql db export 时,数据库名称似乎区分大小写。 Correcting the casing on the database name and resource group solved this issue in my case.在我的情况下,更正数据库名称和资源组的大小写解决了这个问题。

The PowerShell script example in your question above is tested working as expected for me.上面问题中的 PowerShell 脚本示例已按我的预期工作。

However, I am not able to reproduce the same error message as yours even try to use non-existent resource group, database server or database.但是,即使尝试使用不存在的资源组、数据库服务器或数据库,我也无法重现与您相同的错误消息。

Important Note:重要的提示:

  1. For $serverAdmin and $serverPassword , their values should be single-quoted instead of double-quoted for the script to work对于$serverAdmin$serverPassword ,它们的值应该是单引号而不是双引号以使脚本工作
  2. Check the version of your AzureRm.Sql module.检查AzureRm.Sql模块的版本。 Mine tested working is 2.5.0我的测试工作是2.5.0
  3. Try to use -Debug for your New-AzureRmSqlDatabaseExport command line to see the details尝试将-Debug用于您的New-AzureRmSqlDatabaseExport命令行以查看详细信息

Seems really stupid but the error for me was because my "DatabaseName" parameter was case sensitive.看起来很愚蠢,但对我来说错误是因为我的“DatabaseName”参数区分大小写。

I was sending in the value "database" but the actual database name was "Database"我正在发送值“数据库”,但实际的数据库名称是“数据库”

seems crazy but might help someone out看起来很疯狂,但可能会帮助某人

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

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