Additional Function: Synchronize two file folders

FAB Subtitler Server supports many additional functions. This page describes the function “Synchronize two file folders”.

In short: the function copies the files of a source folder to a destination folder and repeats this every IntervalSecs seconds. It works exactly like the task “Copy files” of the scheduler of FAB Subtitler: new and changed files are copied, and on request the files that are no longer in the source folder are deleted from the destination folder. The function does not need a license.

How it works

  • Every entry synchronizes one source folder with one destination folder. The first copy starts when the service starts. After a copy has ended the function waits IntervalSecs seconds, then it copies again. Copies of one entry never overlap. When the service is stopped, a copy that is running is stopped.
  • Several source folders. SourceDir can contain a list of folders, for example a main server and a backup server that hold the same files. The folders are tried in the order of the list: the first folder that can be copied from is used. If a folder is not available or the copy from it fails, the next folder is tried. The state of the entry is an error only when no folder could be copied.
  • Network folders. A shared folder on another computer must be connected with the additional function “Map network drive” first. The function itself does not connect network folders and has no user name or password.
  • The destination folder must exist. If it does not, an error is logged and nothing is copied.

Configuration

  • Open FAB Subtitler Server Configuration and click on the page “Additional Functions”.
  • Add the function “Synchronize two file folders” and fill in the fields below.
  • Add one entry for every pair of folders that has to be synchronized.

The fields of an entry are:

  • Field: Enabled
    Meaning: Y to run this entry (the default for a new entry), N to ignore it.
  • Field: Description
    Meaning: Free text which identifies the entry in the list of additional functions and in the web interface.
  • Field: Filemask
    Meaning: Which files are copied, for example *.* (all files, the default) or *.stl. Required.
  • Field: SourceDir
    Meaning: The folder to copy from. Required. Several folders: write every folder in double quotes and separate them by commas, for example "\\server1\share\dir1","\\server2\share\dir1","\\server3\share\dir1". A single folder does not need quotes.
  • Field: DestDir
    Meaning: The folder to copy to. Required and it must exist.
  • Field: Recurse
    Meaning: Y to also copy the files in the subfolders (the default), N to copy only the files in the folder itself.
  • Field: Sync
    Meaning: Y to delete the files and the empty subfolders in the destination folder that are not in the source folder, so that the destination folder is the same as the source folder. N to keep them (the default).
  • Field: CopyAll
    Meaning: Y to copy all files in every run. N to copy only the files that are new or different (the default).
  • Field: DeleteSource
    Meaning: Y to delete every file from the source folder after it was copied, so the files are moved. N to keep them (the default).
  • Field: IntervalSecs
    Meaning: The number of seconds after which the synchronization is repeated. The default is 60. The minimum is 1: a smaller value is replaced by 1.

Combinations that are not allowed

The entry is not started and an error is written to its log file in these cases:

  • Sync=Y together with DeleteSource=Y. The files are deleted from the source after they were copied, so the next run finds an empty source folder and Sync would delete everything from the destination folder.
  • The source folder and the destination folder are the same folder, or one is inside the other (when Recurse=Y). With Sync=Y the files of one folder would be deleted, otherwise the files would be copied into themselves again and again. The folders are compared by their names only: two different names for the same folder (a drive letter that is mapped to the share, and the share itself) are not recognized.
  • Filemask, SourceDir or DestDir is empty.

DeleteSource=Y with CopyAll=N works, but a warning is written to the log: a file that is already in the destination folder (same date and size) is not copied again and therefore not deleted from the source folder. Use CopyAll=Y to move all files.

Example configuration

The following copies all .stl files, including the subfolders, from the first of two servers to the folder D:\Subtitles\Archive every 30 seconds. If the first server is not available, the second server is used.

Enabled=Y
Description=Subtitle archive
Filemask=*.stl
SourceDir="\\server1\subtitles\out","\\server2\subtitles\out"
DestDir=D:\Subtitles\Archive
Recurse=Y
Sync=N
CopyAll=N
DeleteSource=N
IntervalSecs=30

Web interface

The page /status of the web interface shows a table for every entry:

  • the source folder (the folder that is used; as long as no copy was successful, all source folders),
  • the destination folder,
  • the number of files in the source folder and in the destination folder, written as source/destination, for example 12/12,
  • the time of the last successful synchronization,
  • the time of the last error (“Last error time”).

The state of the entry is shown above the table: Synchronizing, OK or Error: followed by the error. The number of files is counted at the end of every successful synchronization and only for the files that match Filemask. The error time stays after the entry has recovered, so it shows when the last problem was.

Notes

  • Every entry writes its own log file to the folder c:\ProgramData\FAB\FAB Subtitler Server\Log. The name of the file starts with AddFunc_ followed by the number of the entry (for example AddFunc_00012). When the entry is started, the log contains the line Initializing folder synchronization ... and, when the configuration is accepted, Folder synchronization initialized ..., so you can see when it was started. The log contains the start of the entry, the first successful synchronization, and every error with the Windows error code and message, for example a folder that does not exist, a network connection that is broken, or a file that cannot be copied.
  • An error that stays the same is written to the log once and then again after an hour, not at every interval. When the synchronization works again, this is logged once.

This page was last updated on 2026-10-12