Skip to content

Instantly share code, notes, and snippets.

@sandrinodimattia
Created September 5, 2012 21:36
Show Gist options
  • Save sandrinodimattia/3645264 to your computer and use it in GitHub Desktop.
Save sandrinodimattia/3645264 to your computer and use it in GitHub Desktop.
Backup-SQLAzureDB.ps1
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment