Export Azure SQL Database to Azure Storage

You can export the Azure SQL Database using PowerShell , Azure Portal , Visual Studio,SQL Server Management Studio. In this post i have used PowerShell to export the Azure SQL Database to Azure Storage.(You can also export it to you on-premises local storage)

#--------------------------Create SQL Server Azure Database Context ---------------------------#

import-module 'C:Program Files (x86)Microsoft SDKsAzurePowerShellServiceManagementAzureAzure.psd1'

#----Provide the sql login and password whose database will be exported----#

$cred=Get-Credential 

$sqlDatabaseServerNameFQDN='faw5udm867.database.windows.net' 
$Sqlctx=New-AzureSqlDatabaseServerContext -FullyQualifiedServerName $sqlDatabaseServerNameFQDN -Credential $cred 

Get-AzureSqlDatabase -ConnectionContext $Sqlctx | SELECT Name,CollationName,Edition,MaxSizeGB,Createdate |Format-Table –Autosize 

#--------------------------Create Azure Storage Context ---------------------------#

Import-AzurePublishSettingsFile C:\AzureAzure_credentials_file_2.publishsettings 

$subscriptionName = "Free Trial"

$storageAccountName = "dbproxazurestorage" 

$storageaccountkey = Get-AzureStorageKey $storageAccountName | %{$_.Primary} 

$StorageContainer = Get-AzureStorageContainer -Name containerstorage -Context $StorageCtx 

#--------------------------Initiate Export ---------------------------# 

$exportRequest = Start-AzureSqlDatabaseExport -SqlConnectionContext $Sqlctx -StorageContainer $StorageContainer -DatabaseName Rehsosu –BlobName Rehsosu_database_export.bacpac

#--------------------------Check Export Status---------------------------# 

Get-AzureSqlDatabaseImportExportStatus -Request $exportRequest

 

 

image

 

image

Leave a Reply

Your email address will not be published. Required fields are marked *