Created
September 5, 2012 21:36
-
-
Save sandrinodimattia/3645264 to your computer and use it in GitHub Desktop.
Backup-SQLAzureDB.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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