Export Azure SQL Database

This Azure tutorial will discuss multiple approaches to export Azure SQL Database.

Export Azure SQL Database To bak File

The information below will help you export Azure SQL Database to the bak file. We will discuss here 2 approaches to export the Azure SQL database to a bak file.

Approach-1

  1. Log in to the Azure Portal (https://portal.azure.com/).
  2. Search for the SQL Database and then click on the search result SQL databases.
Export Azure SQL Database

3. Now you can see the list of Azure SQL databases that you have created. Click on the particular Database that you want to export as a .bak file.

4. On the SQL Database page, click on the Export button as shown below.

azure sql database export

5. On the Export Database window, provide the below details

  • File name: Provide the file name.
  • Subscription: You must provide a valid Azure subscription you want to use here.
  • Storage: Click on the Configure Required Settings option to select the storage account and then the container.
  • Server admin login: Provide the Server admin login username here.
  • Password: Provide a valid Password.

Finally, click on the OK button.

azure sql export database

6. Once the export is completed, you will find the .bacpac file downloaded on the Storage container you selected above.

powershell backup azure sql database

7. Now, you need to download the .bacpac file locally as a next step. For that, please right-click the .bacpac file, click the Download option, and save it in a local path.

export database azure

8. The next step is to create the .BAK file from the .bacpac file using the SQL Server Management Studio (SSMS). Connect to the SSMS and Right-click on the Database node –> Click on the Import Data-tier Application as shown below.

how to export database from azure data studio

9. Click on the Next button on the next page.

10. On the Import Settings tab, select the Import from local disk option, then Browse to your local path, select the .bacpac file you saved above, and click the Next button.

azure sql database export to blob storage

11. On the Database Settings tab, you can provide a new name for your Database or keep the default name as it is. Leave the other options as it is. Click on the Next button.

azure data studio export table

12. Now, on the Summary tab, you can cross-check if all the information is correct. If you want to change anything, you can click on the Previous button or the Finish button.

export azure sql database to bak file

13. it will take a few seconds to progress and show you the Operation Complete screen. In case of any error, it will show you in red color. Click on each error to know more details.

14. You find the newly created database under the Database node in the SQL Server Management Studio.

15. Right-click on the new Database –> select Tasks –> Click on the BackUp… option as highlighted below.

how to export data from azure sql database

16. On the next window, click the Remove button to remove the existing path. Then click the Add button to add a new path to save the .bak file.

restore bacpac to sql server existing database

17. Once you click the Add button, select the destination path, provide the filename, and click the Ok button. It will store the file as .BAK extension.

18. You are done !!! Now, in the destination path, you will find the .bak file.

Approach-2

  1. Connect to the Azure SQL DB instance.
  2. Right-click on the Database –> Select the Tasks option –> Click on the Export Data-tier Application option.
replicate azure sql database to local

3. Now, click on the Next button and then choose the option to save to local disk on the Export settings tab. That will store a .bacpac file there.

4. The next step is to connect to your Local SQL server Instance.

5. Right-click on the Database –> Click on the Import Data-tier Application option. Click on the Next button on the Import Settings tab, and select the .bacpac file from the local path you have saved before.

How to Export Azure SQL Database To bak File

6. Once the database import is complete, Right-click on it –> select Tasks –> Click on the BackUp… option as highlighted below.

How to create BAK file from azure sql db

7. Now, you can see it is providing us the option to Back up the DB to Disk and with the file name as the .bak extension file with the local path.

create BAK file from azure sql db

How to Export Azure SQL Database

Let’s discuss here how to export the Azure SQL database from the Azure portal. To export the Azure SQL database from the Azure portal, you need to save the SQL database into a BACPAC file.

How To Export An Azure SQL Database With The Azure Portal

First, you need to create a storage account in Azure Portal.

It is ready to use if you have successfully created a storage account following the above link.

1. to export the Azure SQL database from the Azure portal, click on the database you want to export and then click on the Export button.

export azure sql database to bak file

2. From the Export database window, Click on the Storage (Configure required settings) link

export azure sql database

3. Select the storage account you created from the Storage Accounts window by following the link above.

azure sql database export

4. Now, it will ask to create a container since you do not have a container created as of now. To create a container, click on the + Container button.

azure sql export database

5. In the New container window, please provide a valid name for your container and leave the Public access level as is. Now click the Create button to create the container.

powershell backup azure sql database

6. You can see the container created successfully. Click on the Select button.

export database azure

7. On the Export database window, provide the below details

  • File name: provide a file name, or use the default one.
  • Subscription: Your subscription details will load by default. Cross-check if it is correct, or you can choose the correct one.
  • Storage: You need to configure and select the container as per the above-mentioned steps.
  • Server admin login: Provide the username for the admin login.
  • Password: Provide the password for the admin login.
  • Click on the OK button
how to export database from azure data studio

Now, you can see the request submitted to the export database. You can check the progress on the Import/Export History tab.

azure sql database export to blob storage

If you want to check the Bacpac file created, click on the container just created, and you can see a file with the Bacpac extension.

To download the Bacpac file, click on the … (three dots) button or right-click on the file and then select the download option from the popup.

azure data studio export table

Verify the Bacpac file downloaded successfully on your local machine. Later on, you can import it back to Azure or a SQL Server on-premises installation

Azure SQL database export option


How to Export Azure SQL Database using SQLPackage utility

Above, we have discussed the steps to export an Azure SQL Database with the Azure Portal. We can also export an Azure SQL Database using the SQLPackage utility.

SqlPackage.exe is a command-line utility that helps you to perform multiple tasks like Creating a database snapshot (.dacpac) file, Exporting a live database, Importing the data to a new DB, Creating different XML reports and Transact-SQL scripts, etc.

If you will consider an example, you can export a database using SqlPackage.exe with Active Directory Universal Authentication using the below script

SqlPackage.exe /a:Export /tf:testExport.bacpac /scs:"Data Source=apptestserver.database.windows.net;Initial Catalog=DemoDB;" /ua:True /tid:"xyz.onmicrosoft.com"

How to Export Azure SQL Database using SQL Server Management Studio (SSMS)

The latest version of SQL Server Management Studio provides you the option of a wizard that helps you export a database. Below are the steps you need to follow to export the database.

  1. The first step is to connect to the SQL Server instance.
  2. Navigate to the Object Explorer window, expand the node, and select the instance you want to export.
  3. The third step is to right-click on the database name, click the Tasks option, and then select the Export Data-tier Application option.
  4. Click on the check box. Do not show this page again; the option not to show the Introduction page to display in the future, then click on the Next button to the next page and then click on the Cancel button to cancel the operation.
  5. On the Export Settings Page, you can choose to either Save to a local disk or Save to Azure in terms of a BACPAC file.
  6. Click the Re-run Validation option on the Validation page to cross-check the validation status, or click the Next button to continue.
  7. Finally, click the Finish button on the Summary page to complete the Export operation.

How to Export Azure SQL Database using PowerShell

We can use the New-AzSqlDatabaseExport command to submit the Export request to the Azure SQL database service.

We can use the below cmdlet. Set all the variable values as per your database configuration.

$mysubscriptionId = "XXXXX"
$myserverAdmin = 'XXXX'
$myserverPassword = 'XXXX'
$mysecurePassword = ConvertTo-SecureString $myserverPassword -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential($myserverAdmin, $mysecurePassword)
$MyResourceGroupName = 'Your resource group name'
$MyServerName = 'Your server name'
$MyDatabaseName = 'Your database name'
$MyStorageKeytype = 'Your storage key type'
$MyStorageKey = 'YourStorageAccountKey'
$bacpacFilename = $DatabaseName + (Get-Date).ToString("yyyyMMddHHmm") + ".bacpac"
$BaseStorageUri = "https://XXXXX.blob.core.windows.net/XXXXX"
$BacpacUri = $BaseStorageUri + $bacpacFilename

$exportRequest = New-AzSqlDatabaseExport -ResourceGroupName $MyResourceGroupName -ServerName $MyServerName `
  -DatabaseName $MyDatabaseName -StorageKeytype $MyStorageKeytype -StorageKey $MyStorageKey -StorageUri $BacpacUri `
  -AdministratorLogin $creds.UserName -AdministratorLoginPassword $creds.Password
How to Export Azure SQL Database using PowerShell

How to Export Azure SQL Database to Local Machine

Well, there are multiple ways by which you can export Azure SQL Database or download the Azure SQL Database to the local machine. Those are as below

  1. Using Azure Portal
  2. Using SQL Server Import and Export Wizard
  3. Using SqlPackage utility
  4. Using SSIS Tools
  5. Using BCP utility
  6. Using SqlBackupAndFtp

How to Export Azure SQL Database Using SSIS

SQL Server Integration Services is an excellent platform allowing you to export the Azure SQL Database easily.

If you have a .dtsx file or SSIS package, you can export the Azure SQL Database using the command-line tool. Now, with the available .dtsx file, you can run it either with the DTEXEC.EXE command-line utility or with the help of the DTEXECUI application.

Say your .dtsx file name is Demo.dtsx file, then you can run it like below

DTEXEC.EXE /F "Demo.dtsx"

You can also use the DTEXECUI application for the same purpose if you don’t want the command line utility.

How to Export Azure SQL Database Using BCP Utility

The first step is to install the BCP Utility. Once you have installed the BCP Utility, you can use the below command to back up the Azure SQL database.

bcp Demobackupdb.Demo.Test out c:\sqlfile\tsinfo.dat -c -U raj -S tcp:testbackupserver.database.windows.net

Demobackupdb is the name of the database. The Demo is the schema name, and Test is the table to export. The name of the file is tsinfo.dat. -c is for converting the char data type. -U is to mention the username. -S Azure server name.

FAQs

How to cancel Azure SQL database export

If the export process gets stuck in between or for some reason, you want to cancel the Azure SQL database export operation. It would be best if you did the below things

You probably need to delete the storage account/container where it is exporting the data. Then, We can set Allow Azure Services to No. We can get this option under the Manage Allowed IP Addresses page.

You can try it out this way. If you still have the same issue, you must talk to the Azure support guys.

You may like the following Azure tutorials:

Conclusion

In this tutorial, we learned multiple approaches to export Azure SQL Database. I hope you have enjoyed this Article !!!