Hooks in Syncrify
Hooks is a mechanism used on Syncrify server to spawn an external script when a new backup job start and/or end. Hooks are supported in Syncrify after build 563.
Follow the steps below to register a hook in Syncrify.
- Make sure the server is running build 563 or above
- Stop Syncrify if it is running
- Locate C:\Syncrify\config\AppConfig.xml file and open it in any editor. Path on Linux is /opt/Syncrify/config/AppConfig.xml
- Add a new parameter line with the following value
<parameter name="jobHookScript" type="1" value="path/for/your/script arg1 arg2 arg3"></parameter>
After modification the file should look something like:
- Save the file
- Restart Syncrify
The value for this parameter line takes a script that should be run whenever a new client initiates backup. It contain variables starting with a dollar sign ($). Following table describes the meaning of each variable:
||This value can either be true or false It will be true when the script is called when a job is started and false when the script is called when job is complete.
||IP address of the client
||Build number of the client
||Name of the profile. If the profile name contains a space, it will be replaced by an underscore.
||User's email address
||Total files. This value is always 0 when $EVENT is true.
||Total bytes. This value is always 0 when $EVENT is true
||An integer representing the job. This number is repeated after Syncrify server is rebooted
Syncrify is a multi-threaded server. Meaning more than one client can send backup jobs simultaneously. Therefore, you should write your script considering that it can be called simultaneously.
Following examples assume the value for jobHookScript parameter is set to:
<parameter name="jobHookScript" type="1" value="C:/temp/testHook.bat $EVENT $CLIENT_IP $CLIENT_BUILD_NO $PROFILE $USER $FILE_COUNT $BYTE_COUNT"></parameter>
echo %1 %2 %3 %4 %5 %6 %7 %8 %9 >> c:\temp\hookResult.txt
This script will write space separated data to C:\temp\hookResult.txt
if "%1"=="false" goto finish
This example runs JobStarted.exe when a job starts and JobCompleted.exe when a job ends. In both cases, the .EXE file is passed 3 parameters: Client's IP address, Profile name and user's login.
start c:\Data\JobStarted.exe %2 %4 %5
start c:\Data\JobCompleted.exe %2 %4 %5