2BrightSparks

Introduction to Scripting in SyncBackPro

Author: Swapna Naraharisetty, 2BrightSparks Pte. Ltd.

Scripting provides a flexible and easy way to automate tasks and extend the functionality of an application.

A script is a small program that enables you to customize and control your backup jobs. For example, you can write a script to copy, rename or delete a specific file, customize the user interface or change the profile settings. SyncBackPro’s scripting is like the macro support in Microsoft Office, JavaScript in web pages or plug-ins in other software.

With SyncBackPro V11, you can use the built-in script editor to create and edit your scripts. SyncBackPro can use scripts written in the Basic or Pascal script languages. The Basic script language syntax is like VBScript and the Pascal script language syntax is similar to Delphi. When creating a script file, you need to use the .pas filename extension for Pascal and .bas for Basic.

Although, for backwards compatibility reasons, SyncBackPro 32-bit supports VBScript (.vbs), we do not recommend using it. You cannot use the built-in script editor or debugger with VBScript.

Scripting is only supported in SyncBackPro. It is not available in SyncBackSE and SyncBackFree.

Types of Scripts

There are four different types of scripts:

  • Main Interface scripts: these are scripts that can be used with the main user interface in SyncBackPro. For example, you could write a script that adds a new column to the main window showing the duration of the profile run.
  • Profile Configuration scripts: these are scripts that can be used when configuring a profile. For example, your script may need settings provided by the user, e.g. a password.
  • Location scripts: these are scripts that are used to change the way the files are stored and retrieved. For example, you could write a location script that copies files to and from a database.
  • Runtime scripts: these are scripts that are used to change the functionality of a profile run. For example, you could stop a profile run if a certain condition is satisfied or perform an action when a file is copied.

A single script file can use more than one type of script. For example, you could write a script that is both a Profile configuration and Runtime script. SyncBackPro knows what type of script is being used from the Description function inside the script.

For example: the following is a profile configuration and runtime Pascal script:

Function Description(var ScriptType); begin Result:='Description of the script goes here'; ScriptType:=SCRIPTTYPE_RUN + SCRIPTTYPE_CONFIG; End;

Script Objects

SyncBackPro provides helper objects (e.g. SBSystem) for the scripts to easily communicate with the program. Based on the script type, one or more of the following helper objects will be available to the script:

  • SBLocation: This object is only accessible from Location scripts.
  • SBProfile: This object is only accessible from Profile Configuration scripts.
  • SBProfiles: This object is accessible from all scripts and was introduced in SyncBackPro V11.
  • SBRunning: This object is only accessible from Runtime scripts.
  • SBSystem: This object is accessible from any type of script.
  • SBVariables: This object is accessible from any type of script.
  • SBHistory: This object is accessible from Main Interface, Runtime and Profile Configuration scripts.

The SyncBackPro Help File explains in detail all of the objects, functions and constants available to scripts.

How does scripting work in SyncBackPro?

1. First, you write a script that contains functions. The function will perform tasks when certain events occur. To do this: Go to the burger menu Burger Menu (on the top-left of SyncBackPro main window) > select Scripts and click the New button. By default a Pascal script is created.

2. When you create a new script, you can import (install) it once it is saved (you will be prompted). Alternatively, you can install an existing script by going to the burger menu Burger Menu (on the top-left of SyncBackPro main window) > select Scripts, clicking on the Install button and then selecting the script you would like to use.

Install Script

You can also install (or import) a script via the command line interface by simply passing the filename of the script, but the extension must be .SBS, i.e. it must have been exported previously from SyncBackPro (see below).

e.g. "C:\Program Files\2BrightSparks\SyncBackPro\SyncBackPro.exe" "C:\Scripts\AllDrives.sbs"

If you want to import multiple scripts using wildcards, then you can use the -importscript command line parameter.

e.g. "C:\Program Files\2BrightSparks\SyncBackPro\SyncBackPro.exe" -importscript "C:\Scripts\*.sbs"

For security reasons scripts are always imported interactively and with the users consent.

3. After installing a script you should compile it to check for errors. Select the script from Scripts page and click on the Edit button. The Script Editor Window will appear. Click on the Compile button, or right click on the script and choose Compile from the pop-up menu to compile the script. You can also edit the script and save the changes using Apply option on the Script Editor.

Script Editor

4. You then need to activate the script. If it's a Main Interface or Profile Configuration script, you can immediately activate it after installation. Simply click on the Yes button when prompted.

Activate Script

Alternatively, go to the relevant tab on the Scripts page and tick the checkbox next to the script to activate it.

Activate Script

To use a Runtime script, modify your profile > go to the Scripts page and tick the check box next to the script. For Location script, you must create a profile with that script, so that the backup or restore is done using that script.

5. When SyncBackPro performs an action, it will check to see if there are any installed scripts that can be called for that event. For example, you have installed a main interface script that adds a new column to display the duration of a profile run. Whenever SyncBackPro refreshes the main window, it checks to see if there are any main interface scripts installed that can be called. If so, it calls the appropriate function in the script to perform the task.

Exporting Scripts

To export a script, go to the burger menu Burger Menu > Scripts page > select the script and click on Export button. The exported script file is saved with the .SBS extension.

Debugging Scripts

SyncBackPro V11 introduced the ability to debug scripts both at runtime and while editing a script. See the help file for more details.

Conclusion

With Scripting, you can easily automate repeated tasks and control your backup operations. You can also save time by automating complex processes using scripts. The SyncBackPro installation folder includes example scripts and there are more listed on our Scripting page, so you can find a script that performs the task you want and modify it to suit your needs.

Noted Customers

© 2003-2024 2BrightSparks Pte. Ltd.  | Home | Support | Privacy | Terms | Affiliate Program

Home | Support | Privacy | Terms
© 2003-2024 2BrightSparks Pte. Ltd.

Back to top