Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

$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?

like image 619
Mr_road Avatar asked Feb 01 '17 15:02

Mr_road


People also ask

How do I export Azure SQL database to local SQL Server?

Connect to your SQL Azure database that you want to copy locally using SQL Server Management Studio (SSMS). Export your database to a local . bacpac file. Follow steps in wizard and finish the process.

How do I export data from Azure SQL to Excel?

Connect Excel and load data To connect Excel to a database in SQL Database, open Excel and then create a new workbook or open an existing Excel workbook. In the menu bar at the top of the page, select the Data tab, select Get Data, select From Azure, and then select From Azure SQL Database.


1 Answers

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.

like image 104
Jim Wooley Avatar answered Sep 20 '22 23:09

Jim Wooley