Automating (Scheduling) your UnitySync connections
Created: 2012-04-20 08:09:59Modified: 2024-02-15 09:47:43
Tags: Features UnitySync US Admin Guide
You may easily automate (schedule) your UnitySync connections.
Initial creation and run of connections is typically performed in the UnitySync User Interface (UI). Thereafter, your UnitySync connections may be run manually from the UI or via a command line program (shell.exe).
Using the command line shell.exe option, you may automate the your Sync runs via the use of any task scheduling program. The most commonly used is Windows Task Scheduler. Simply create a simple script using the syntax described below. Run the script manually first to confirm good results. Then set up a scheduled task to execute your Sync script as desired.
Note about log file cleanup
We strongly recommend that you also set up Log File Management to ensure your logs don’t accumulate beyond a reasonable amount of time (or take up too much disk space).
Scripting Connections to Run
There are just a few things to keep in mind when scripting your connections to run:
- Follow the guidelines below to create a batch script.
- Run the script manually to ensure desirable results.
- Create a scheduled task to execute the script on your chosen schedule.
Script file requirements:
- Change to the local drive where UnitySync is installed
- Change to the local directory of the Synchronization executable
- Be sure to put each command on a separate line
If you group your connections in Folders, you must specify the Folder name when calling the connection (i.e., …\Shell Folder\YourConnection)**
Note: For versions prior to v4.6, omit --conn
i.e. shell.exe “Paris-to-Master”
Example Script #1 - One command per connection
Here is an example of a script to kick off UnitySync connections. Remember, one command line per connection:
C:
cd \UnitySync\bin
shell.exe --conn "Paris-to-Master"
shell.exe --conn "Denver-to-Master"
shell.exe --conn "NY-to-Master"
shell.exe --conn "Master-to-Paris"
shell.exe --conn "Master-to-Denver"
shell.exe --conn "Master-to-NY"
Here is an example of the same connections if they are in two folders (In/Out) instead of using naming conventions
C:
cd \UnitySync\bin
shell.exe --conn "IN\Paris-to-Master"
shell.exe --conn "IN\Denver-to-Master"
shell.exe --conn "IN\NY-to-Master"
shell.exe --conn "OUT\Master-to-Paris"
shell.exe --conn "OUT\Master-to-Denver"
shell.exe --conn "OUT\Master-to-NY"
Example Script #2 - Multiple connections per command
Here is an example of a batch script to kick off a subset of UnitySync connections with a single command. This is useful as it allows the creation of new connections to be inserted into the automation automatically, simply by use of proper naming conventions. No need to edit your script to insert the shell.exe command for each individual connection.
C:
cd \UnitySync\connections
for /D %%D in (in*.) DO ..\bin\shell --conn "%%D"
for /D %%D in (out*.) DO ..\bin\shell --conn "%%D"
In the above example, naming conventions are used to group connections. All connections that load the master (hub) are prefixed with “in”. All connections that push from the master out to other directories, are prefixed with “out”. Using this two line batch script, any connection created with a prefix of “in” or “out” are automatically included in the execution of the scheduled batch.
Below is an example of the same connections if they are in folders, instead of using naming conventions:
C:
cd \UnitySync\connections
for /D %%D in (IN\*.) DO ..\bin\shell --conn "%%D"
for /D %%D in (OUT\*.) DO ..\bin\shell --conn "%%D"
IMPORTANT NOTE: If you want to test Advanced scripts from the command line, please note that you will need to substitute %D for %%D when running directly from the command line. Or, you may cd into the directory where the batch file exists and run that file from the command line for testing.
Example Script #3 - Automating Forcemods
As noted in the knowledge base article detailing Forcemods functionality, this feature may also be automated.
To run from the command line:
shell.exe --forcemods --forcestruct --conn "Connection Name"
Use the same format for batch scripts as previously shown:
C:
cd \UnitySync\connections
shell.exe --forcemods --forcestruct --conn "Connection Name"
Please note:
- Forcemods allows Delete/Modify of all Destination person objects.
- Forcestruct allows recreation of deleted structure.
Remember, you do not want to add Forcemods to your batch script that runs daily. Determine how often you want to run Forcemods and create an additional script and task for it to run only occasionally, say weekly or monthly.
Scheduling Batch Execution
Using Scheduled Task (recommended)
Create a Scheduled Task -
Programs > Control Panel > Scheduled Task > Add a Scheduled Task
.Select the script and configure run time and Run As properties. Be sure the Run As account has sufficient access/permissions to perform the operation.
IMPORTANT NOTE: Executing via Scheduled Task will pop up a CMD window. If you wish to run the Scheduled Task in the background, be sure to set the ‘Run As’ to an account other than the logged in account.
Using the AT command
Start the Scheduler Service - Start > Settings > Control Panel > Services
. Or, configure Startup to make the service start at boot up.
Let’s say that your batch file is called ...\UnitySync\runsync.bat
and you would like to have it run every day at 9:00 am. For syntax on the AT command type at /
from the CMD prompt. Example:
at \\MyServer 9:00 /EVERY:SU,M,T,W,TH,F,S "C:\UnitySync\runsync.bat"
To view the scheduled events type at
. Remember, a log file is generated with each run. Review these logs regularly to ensure your connection is running properly.
IMPORTANT NOTE: UnitySync is single thread so more than one occurrence of a program can run at a time. Take your bandwidth into consideration when attempting to run more than one sync.