Automating a Synchronization


I wanted to sync our Dev Web site with our Prod Web site.
The idea was to move new files into the Prod site and delete any old or extra files.
Rather than write a POSH script I decided to use Beyond Compare 3. Great product, I highly recommend it.
http://www.scootersoftware.com/moreinfo.php
With some help from the folks at Scooter Software, I came up with this:


###### Start Posh Script ########

Function Show-Inputbox {
 Param([string]$message=$(Throw "You must enter a prompt message"),
       [string]$title="Input",
       [string]$default
       )

 [reflection.assembly]::loadwithpartialname("microsoft.visualbasic") | Out-Null
 [microsoft.visualbasic.interaction]::InputBox($message,$title,$default)

}

$Dev = Show-Inputbox -message "The New Web files location" `
-title "Path" -default "E:\DevSite\0000\"

$Prod = Show-Inputbox -message "The Prod Web files location" `
-title "Path" -default "E:\inetpub\0000\"

$left = $Dev
$right = $Prod

$exe = "E:\Tools\BEYOND~1\BCompare.exe"
$p = [diagnostics.process]::Start("cmd.exe", "/c start /wait " + $exe + " @E:\Scripts\PS1\IISProject\SyncWebSite.txt $left $right")

############# End POSH Script ###############


You also need to write a simple text file up that includes the parameters for BeyondCompare like this:

# Keeping a web site in sync
# This script keeps a web site in sync with development files.
######
# Turn verbose logging on.
log verbose append: “E:\WebSyncLog\%date%.txt”

# be carefull with the Quote marks, You may need to change them
# Set the comparison criteria.
criteria binary size
# Load source and target folders.
load %1 %2
# Filter to only include source files, ignore CVS subfolders.
# filter “*.htm;*.html;*.php;*.jpg;*.gif;-CVS\”
# Sync the local files to the web site, creating empty folders.
sync create-empty mirror:left->right
#######
I called it SyncWebSite.txt

Be very carefull with your left and right directories.
Once it’s synced there is no going back.