How to import a large .bacpac file into Azure SQL Server

How to import a large .bacpac file into Azure SQL Server

When importing a very large bacpac file into a new Azure database, there are several methods and configuration options to consider. Here are some ways to accomplish this task, along with important configuration options and different languages and command line tools:

  1. Azure Portal:

    • In the Azure portal, navigate to your Azure SQL Database server.
    • Select "Import database" and choose the bacpac file from your local machine or Azure storage account.
    • Specify the database name, edition, service objective, and maximum database size.
    • Choose the authentication method (SQL Server authentication or Azure Active Directory).
    • Review the settings and click "OK" to start the import process.
  2. SqlPackage Command-Line Utility:

    • SqlPackage is a command-line utility that comes with SQL Server Data Tools (SSDT) and can be used to import bacpac files.
    • Open a command prompt and navigate to the directory where SqlPackage is installed.
    • Use the following command to import the bacpac file:
      sqlpackage.exe /Action:Import /SourceFile:"<bacpac_file_path>" /TargetServerName:"<server_name>.database.windows.net" /TargetDatabaseName:"<database_name>" /TargetUser:"<username>" /TargetPassword:"<password>"
      
    • Additional configuration options:
      • /Edition: Specifies the edition of the database (e.g., Basic, Standard, Premium).
      • /ServiceObjective: Specifies the performance level for the database (e.g., S0, P1).
      • /DatabaseMaxSize: Specifies the maximum size of the database (e.g., 250GB).
  3. PowerShell:

    • Use the New-AzSqlDatabaseImport cmdlet in PowerShell to import the bacpac file.
    • Install the Azure PowerShell module if not already installed.
    • Connect to your Azure account using Connect-AzAccount.
    • Run the following command to start the import process:
      $importRequest = New-AzSqlDatabaseImport -ResourceGroupName "<resource_group>" -ServerName "<server_name>" -DatabaseName "<database_name>" -StorageKeyType "StorageAccessKey" -StorageKey $(Get-AzStorageAccountKey -ResourceGroupName "<storage_resource_group>" -StorageAccountName "<storage_account>").Value[0] -StorageUri "https://<storage_account>.blob.core.windows.net/<container>/<bacpac_file>" -AdministratorLogin "<username>" -AdministratorLoginPassword $(ConvertTo-SecureString -String "<password>" -AsPlainText -Force) -Edition "<edition>" -ServiceObjectiveName "<service_objective>" -DatabaseMaxSizeBytes "<max_size>"
    • Monitor the progress of the import operation using Get-AzSqlDatabaseImportExportStatus.
  4. Azure Data Studio:

    • Azure Data Studio is a cross-platform database tool that supports importing bacpac files.
    • Install Azure Data Studio and connect to your Azure SQL Database server.
    • Right-click on the database and select "Import Data-tier Application".
    • Choose the bacpac file and specify the database name, edition, service objective, and maximum database size.
    • Click "Import" to start the import process.

Configuration Options:

  • Database Edition: Choose the appropriate edition based on your performance and feature requirements (e.g., Basic, Standard, Premium).
  • Service Objective: Select the performance level that suits your workload (e.g., S0, P1, P2).
  • Database Max Size: Specify the maximum size of the database to accommodate the imported data.
  • Authentication: Choose between SQL Server authentication or Azure Active Directory authentication.

Remember to consider the size of your bacpac file and ensure that your Azure SQL Database has sufficient storage and performance capabilities to handle the imported data.

It's also recommended to perform the import operation during off-peak hours to minimize the impact on production workloads.