2
votes

SQL Azure allows for the Automated Export on a scheduled basis to Azure blob storage. This can be configured in the Azure Management Portal on a per database basis.

Is there a way to script this via powershell, REST API or the Windows Azure Management Libraries?

We are developing a sharded database solution with more than 60 shards per environment, which means 100s of databases to configure, doing this manually isn't really an option.

2

2 Answers

1
votes

You have a PowerShell Cmdlet - Start-AzureSqlDatabaseExport - Ref, using that you can start an export of SQL Azure Data to Blob Storage.

You can use that cmdlet in PowerShell Scheduled Job - Ref

You can create a VM Role and run your custom PS script in it. So that All your PS operations will be fast enough.

0
votes

I haven't tried it yet but Sandrino Di Mattia wrote about this here -

param([string]$ConnectionString = $(throw "The ConnectionString parameter is required."), 
      [string]$DatabaseName = $(throw "The DatabaseName parameter is required."),
      [string]$OutputFile = $(throw "The OutputFile parameter is required."), 
      [string]$SqlInstallationFolder = "C:\Program Files (x86)\Microsoft SQL Server")

# Load DAC assembly.
$DacAssembly = "$SqlInstallationFolder\110\DAC\bin\Microsoft.SqlServer.Dac.dll"
Write-Host "Loading Dac Assembly: $DacAssembly"
Add-Type -Path $DacAssembly
Write-Host "Dac Assembly loaded."

# Initialize Dac service.
$now = $(Get-Date).ToString("HH:mm:ss")
$Services = new-object Microsoft.SqlServer.Dac.DacServices $ConnectionString
if ($Services -eq $null)
{
    exit
}

# Start the actual export.
Write-Host "Starting backup at $DatabaseName at $now"
$Watch = New-Object System.Diagnostics.StopWatch
$Watch.Start()
$Services.ExportBacpac($OutputFile, $DatabaseName)
$Watch.Stop()
Write-Host "Backup completed in" $Watch.Elapsed.ToString()