Automating (Scheduling) your UnitySync connections2021-02-23 11:51:57
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 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.
IMPORTANT NOTE: UnitySync System Server Requirements indicate that minimum Hard Disk Space needed is 500Mb for a sync to run successfully. We further recommend that you ensure >10Gb Hard Disk Space is available depending on the number of connections you regularly run, the number of objects you are syncing, and your logging levels. If you choose to automate your syncs, we strongly recommend that you also set up Log File Management to ensure your logs don’t accumulate beyond a reasonable amount of time, and also ensure that you are running the latest version of UnitySync (v2.8 and later) for active disk space checking enhancements. Without the latest version and processes in place to prevent low disk space conditions, you could run the risk of mass deletions on one or more connections.
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 insure 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)
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 "Paris-to-Master" shell.exe "Denver-to-Master" shell.exe "NY-to-Master" shell.exe "Master-to-Paris" shell.exe "Master-to-Denver" shell.exe "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 "IN\Paris-to-Master" shell.exe "IN\Denver-to-Master" shell.exe "IN\NY-to-Master" shell.exe "OUT\Master-to-Paris" shell.exe "OUT\Master-to-Denver" shell.exe "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 "%%D" for /D %%D in (out*.) DO ..\bin\shell "%%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 "%%D" for /D %%D in (OUT\*.) DO ..\bin\shell "%%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 "Connection Name"
Use the same format for batch scripts as previously shown:
C: cd \UnitySync\connections shell.exe --forcemods --forcestruct "Connection Name"
- Forcemods allows Delete/Modify of all Destination person objects.
- Forcestruct allows recreation of deleted structure.
Remember, you do not want to add Forcemods directly into 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
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.