簡體   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