答案较晚,但可能有助于吸引访问者
我试图在不同服务器之间分配数据并使用第三方工具(用于模式更改的Diff和用于数据更改同步的DataDiff)并遵循使该过程自动化所需的PowerShell脚本解决了类似的难题:
#check for the existence of the Outputs folder
function CheckAndCreateFolder($rootFolder, [switch]$Outputs)
{
$location = $rootFolder
#setting up location
if($Outputs -eq $true)
{
$location += "\Outputs"
}
#if the folder doesn't exist it will be created
if(-not (Test-Path $location))
{ mkdir $location -Force:$true -Confirm:$false | Out-Null }
return $location
}
#root folder for the schema sync process
$rootFolder = "SchemaSync"
#schema output summaries location
$outsLoc = CheckAndCreateFolder $rootFolder -Outputs
#ApexSQL Diff location, date stamp variable is defined, along with tool’s parameters
$diffLoc = "ApexSQLDiff"
$stamp = (Get-Date -Format "MMddyyyy_HHMMss")
$Params = "/pr:""MyProject.axds"" /out:""$outsLoc\SchemaOutput_$stamp.txt"" /sync /v /f"
$returnCode = $LASTEXITCODE
#initiate the schema comparison and synchronization process
(Invoke-Expression ("& `"" + $diffLoc +"`" " +$Params))
#write output to file
"$outsLoc\SchemaOutput_$dateStamp.txt"
#schema changes are detected
if($returnCode -eq 0)
{
"`r`n $returnCode - Schema changes were successfully synchronized" >>
}
else
{
#there are no schema changes
if($returnCode -eq 102)
{
"`r`n $returnCode - There are no schema changes. Job aborted" >>
}
#an error is encountered
else
{
"`r`n $returnCode - An error is encountered" >>
#output file is opened when an error is encountered
Invoke-Item "$outsLoc\SchemaOutput_$stamp.txt"
}
}
此方法可安排两个数据库之间的比较,并实时同步发现的更改。以下是一些提供逐步说明的文章:
https://solutioncenter.apexsql.com/automatically-compare-and-synchronize-sql-server-data/
https://solutioncenter.apexsql.com/how-to-automatically-keep-two-sql-server-database-同步模式/