Automating a Synchronization
Writing the Beyond Compare Script
How can Beyond Compare be used for automated synchronization? The first step is creating a script text file (*.txt). Beyond Compare's help file includes specifics about creating scripts but here is an example of one that is useful for mirroring updates to an ftp site:
# Turn logging on
log normal "C:\Distrib\Synclog.txt"
# Set comparison criteria
criteria timestamp size
# Exclude certain file types
# Load the base folders
load "C:\Local" "ftp://jdoe:firstname.lastname@example.org/reports"
#Make the target identical to the source
#includes deleting files that only exist on the target side
This example uses a log and filters. Logs are very useful for keeping track of changes. In order to prevent copying of backup files, they are excluded.
Scheduling the task in Windows
The script file can be run from the the command prompt by passing the full filename for the script preceded by '@' as the parameter for Beyond Compare. For example:
"C:\Program Files\Beyond Compare 4\BCompare.exe" @C:\bcscript.txt
However, this is still slightly inconvenient. Instead, automate the process by creating a scheduled task. In the Windows Control Panel, look for System and Security | Administrative Tools | Scheduled Tasks. When you add a new task, Windows provides a wizard. Among other things, it asks you how often to perform this task. For example, you might chose update daily on weekdays at 1:00am. Before finishing, click on the checkbox to open advanced properties. Edit the Run: field to mimic the command prompt signature (ie add @scriptfilename). Edit Settings as you chose and make sure the task enabled box is checked.
Note: If you don't include the /silent switch and the task runs while it's not logged in the script will hang. If you have trouble, check out the Scheduled Tasks error log: "SchedLgU.txt" in your Windows folder.
Confirmation Prompts: During normal operation Beyond Compare prompts to confirm many file operations, such as deleting or over-writing read-only files. When you use the /silent switch, the GUI is completely suppressed, so Beyond Compare answers no to all file operation prompts. To override this, add the following command to the beginning of your script:
You're all set! Your computer will automatically mirror your data to the FTP site even if you are not logged in on the computer.
Scheduling the task in macOS
The script file can be run from the Terminal app by passing the full filename for the script preceded by '@' as the parameter for Beyond Compare. For example:
Before running the command above, you will need to ensure the command line tools have been installed. To do this, run Beyond Compare and then select Beyond Compare | Install Command Line Tools. You should see a prompt to enter your password for your user account then a confirmation dialog once the tools have been installed.
The next step will be creating an Automator workflow that will run the script. Open the Automator app and then either click the New Document button or select File > New. From the next dialog, select Application and then click the Choose button. In the search bar, type run and then double-click on or drag-and-drop Run Shell Script into the workflow pane. In the script text field enter the following:
You can test your workflow by clicking the Run button or by selecting Workflow | Run (Cmd+R). Once you have confirmed the script runs, save the script and exit Automator.
Finally, open the Calendar app. Select File | New to create a new event and then set: 1) the time you want the script to run and 2) how often you want the script to repeat. Last, add an Alert and select Custom from the drop-down menu. Change the Message with sound drop-down to Open File and then change the Calendar drop-down to Other. Once the file broswer dialog opens select the automator workflow file you created before. Finally, change the minutes before drop-down to At time of event and then click OK.
You should now have a scheduled task to run the script you created.
Scheduling the task in Linux
Scheduling scripts using
cron in Linux is not currently supported as a GUI session is required for Beyond Compare to run and execute the script.