Created
August 24, 2018 20:33
-
-
Save nvarscar/5efdb01fb4e4916886559896d660bd84 to your computer and use it in GitHub Desktop.
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
[Cmdletbinding()] | |
Param ( | |
$SourceServer, | |
$TargetServer = $SourceServer, | |
$SourceDatabaseName, | |
$TargetDatabaseName, | |
$Path, | |
$PublishXml = '.\publish.xml', | |
[switch]$IncludeData | |
) | |
#Stop on any error by default | |
$ErrorActionPreference = 'Stop' | |
# Construct export parameters | |
$exportProperties = "/p:IgnorePermissions=True /p:IgnoreUserLoginMappings=True" | |
if ($IncludeData) { | |
$exportProperties += " /p:ExtractAllTableData=True" | |
} | |
#Export database to path | |
Write-Verbose "Starting the export from $SourceServer.$SourceDatabaseName to $Path" | |
$exportFile = Export-DbaDacpac -SqlInstance $SourceServer -Database $SourceDatabaseName -Path $Path -ExtendedProperties $exportProperties -EnableException | |
Write-Verbose "Export completed`: $exportFile" | |
#publish dacpac with defined publish xml file | |
Write-Verbose "Starting the publication from $($exportFile.Path) to $TargetServer.$TargetDatabaseName" | |
$xml = (Get-Item $PublishXml).FullName | |
Publish-DbaDacpac -SqlInstance $TargetServer -Database $TargetDatabaseName -PublishXml $xml -Path $exportFile.Path -EnableException | |
#remove dacpac file | |
if (Test-Path $exportFile.Path) { | |
Write-Verbose "Removing dacpac file $($exportFile.Path)" | |
Remove-Item $exportFile.Path | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment