Comments (22)

  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) https://azure.microsoft.com/en-us/pricing/details/automation/

  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?
    https://github.com/thdeltei/azure-content/blob/master/articles/sql-database/sql-database-export-powershell.md

    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
    }

    $exportStatus
    $Status= $exportStatus.Status
    if($Status -eq “Succeeded”)
    {
    Write-Output “Azure SQL DB Export $Status for $DatabaseName”
    }
    else
    {
    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.

      Thanks
      Mohamed

  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.

      Regards,
      Mohamed

Skip to main content