Azure Export SQL database example

痞子三分冷 提交于 2019-12-12 10:44:29

问题


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

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?


回答1:


The PowerShell script example in your question above is tested working as expected for me.

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
  2. Check the version of your AzureRm.Sql module. Mine tested working is 2.5.0
  3. Try to use -Debug for your New-AzureRmSqlDatabaseExport command line to see the details



回答2:


It appears that the database name is case sensitive when using az sql db export. Correcting the casing on the database name and resource group solved this issue in my case.




回答3:


This has just come out from MS/Azure and helps greatly with DB Export.

https://github.com/Microsoft/sql-server-samples/tree/master/samples/manage/azure-automation-automated-export



来源:https://stackoverflow.com/questions/41983010/azure-export-sql-database-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!