Comments (28)

  1. Tarek Nabeel says:

    Excellent post , thanks !

  2. Adeel Rehman Sheikh says:

    Thank you, Mohamad

  3. deepak says:

    Is there a way we can schedule for it to be stored on our local machine?

    1. Currently no, you would have to write a second script using something like azcopy to download the bacpac from blob storage.

  4. Adam Levitt says:

    I’d like to do this using C# Azure SDK instead of powershell. Is there a code example for that?

  5. Adithep Pruekpitakpong says:

    Perfect post! Thank you!

    One more question. How much does Automation Accounts cost?
    As I know, Microsoft Azure charges for Storage Account which we use to keep .bacpac.

    1. According to the calculator you can either do the free option for 500 minutes of process time or $0.002/minute of process time (running time for automation runbooks)

  6. Adam Levitt says:

    New-AzureRmSqlDatabaseExport — this command is not recognized. Anything I’m missing here?

  7. Baskar says:

    We are getting the following error “New-AzureRmSqlDatabaseExport : Cannot validate argument on parameter ‘AdministratorLogin’. The argument is null or
    empty. Provide an argument that is not null or empty, and then try the command again.
    At ExportAzureDB-PowerShellWorkflowScript:3 char:3”

    1. Hi Baskar, try to confirm you provide the value for this parameter in this script.

  8. Alex says:

    Great tutorial! Works well!

  9. Morten says:

    “For an archive to be transactionally consistent, you must either ensure that no write activity is occurring during the export or export from a transactionally consistent copy of your Azure SQL database”

    I’m guessing this script does not account for the problem above?

    1. Correct, you need to do a CREATE DATABASE AS COPY operation (or copy via powershell) to be safe.

  10. Hi,
    Thanks for the above Script. it works Great.
    one thing we can add in the Script is Export Status. at present we just look at the Export Status and job ends as succeeded even though Backup is running and still hasn’t come into storage account.
    if we could add the below Change to the Script then job will be running and ocne the job ends we will see the bacpac file in our storage account.
    while ($exportStatus.Status -eq “InProgress”)
    $exportStatus = Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $exportRequest.OperationStatusLink

    Start-Sleep -s 10

    $Status= $exportStatus.Status
    if($Status -eq “Succeeded”)
    Write-Output “Azure SQL DB Export $Status for $DatabaseName”
    Write-Output “Azure SQL DB Export Failed for $DatabaseName”

    Please share your view on this.

    1. Considering the functionality is in a-sync mode its enough to have success message for the submission of the request. for whom sync mode is needed – this PS piece can be great!
      Thank you for sharing!

    2. Thank you so much for your suggestion, you may replace this part directly, I test it and should works.

      # Check status of the export
      $exportStatus = Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $exportRequest.OperationStatusLink
      Write-Output “Azure SQL DB Export Completed at $DatabaseName”

  11. Alex a says:

    Hi Muhamad,

    Thank you for your great post.
    I was running your script and it was done whiteout any error, however I don’t see any generated bacpac file in my blob storage container. can you please advice whats wrong?

    1. Hi Alex,
      did you see the export operation listed on your Azure SQL DB?

    2. Hi Alex, in Import/Export history in SQL Server through Azure Portal, can you see any failed attempts?
      I had updated PowerShell script to include check export status and update if succeeded or failed, can you please try it and update us if you get notice any failure.


  12. Kapil Bhagchandani says:

    This tutorial is incomplete. Please add the step 8 to start “Update-ModulesInAutomationToLatestVersion” so that latest modules can be imported and available. Without this step users will get following error “New-AzureRmSqlDatabaseExport not recognized as the name of a cmdlet”

    1. Hello Kapil, no need to start “Update-ModulesInAutomationToLatestVersion” runbook, you need to make it published, how to publish this module already mentioned in this article, if you face any problem please submit a service request so we can assist you.


  13. Rishi says:

    Script has been executed successfully however I coudn’t see my database has been copied to blob container. I repeatedly executed script but i coudnt see anything under container.

    1. try to review the import-export history at the server level to confirm if the export has been initiated successfully or not.

      1. Rishi says:

        Thank you Yochanan , Import/export history it was failing because of wrong Blob storage endpoint. Now it has been corrected and executed successfully.

        1. happy to hear that. Thank you for sharing

          1. Shahid1990 says:

            Hi Yochanan,

            I am stuck while exporting DB to storage account using above script. script actually work for me with Demo DB (30MB size)

            When script tried to export prd DB (300GB) it gives below error and on the same azure SQL server other DB exported successfully. I have validated the credentials and tried my times but still failed.

            Error in Azure SQL import\Export:
            Error encountered during the service operation.
            Could not extract package from specified database.
            Unable to reconnect to database: Cannot open database “abc_copy” requested by the login. The login failed.

            Thanks in advance

          2. Hi, based on the exception message it seems like this is only login failed error, maybe you have typo with the password?
            if you need more help I encourage you to open new support request and out team will be happy to help you export the database.


Skip to main content