Do not start a second copy if already running

Discuss new features and functions
Posts: 6
Joined: 19 Nov 2024

ertank

Hello,

I tried to search forum but could not find any similar question.

I setup an unattended mode mirror batch job. It will be run hourly and job may run longer than one hour. But it is not certain and job may finish earlier than one hour.

Is it possible to skip a batch job which is still running?

Thanks & Regards,
Ertan
User avatar
Posts: 2978
Joined: 22 Aug 2012

Plerry

Assuming Windows, try:
In the Windows Task Scheduler, use "Create task", not "Create Basic task".
Create your task as desired, and on the final task-tab "Settings", for "If the task is already running, the following rule applies:" select "Do not start a new instance".
Posts: 6
Joined: 19 Nov 2024

ertank

It is Windows. I forgot to mention that.
However, FreeFileSync is triggered from another script and not from the Task Scheduler.
User avatar
Posts: 2978
Joined: 22 Aug 2012

Plerry

If you did not disable the use of sync.ffs_lock files (by settings the LockDirectoriesDuringSync Flag to false), FFS writes a sync.ffs_lock file to your left and right base location when starting a Compare, and deletes it after the Synchronization has ended.
Your script that would start the next FFS session could check if a sync.ffs_lock file still exist in your left or right base location, and only if it does not, start that next FFS session.
Posts: 1222
Joined: 8 May 2006

therube

You could use tasklist.exe to see if FFS is already running, & then do or not do something after that.

(as a start, something like)

tasklist.exe /fi "imagename eq freefilesync.exe"

(& then you'd do something after that based upon whether FFS was found or not)

viewtopic.php?t=11554#p44657
viewtopic.php?t=7602#p25859

This says, if FFS is not found, run it:

tasklist.exe /fi "imagename eq freefilesync.exe" || freefilesync.exe

||, is the same as checking %errorlevel% NEQ 0
&&, would be the same as checking %errorlevel% EQU 0
Posts: 6
Joined: 19 Nov 2024

ertank

It is actually a PowerShell script and below seems to work for me
if (-not (Get-Process -Name 'FreeFileSync' -ErrorAction SilentlyContinue)) {
  & 'C:\Program Files\FreeFileSync\FreeFileSync.exe' "C:\BackupDB\remotebackup.ffs_batch"
}
Thanks.
User avatar
Posts: 2978
Joined: 22 Aug 2012

Plerry

The limitation of the solution of both therube and ertank is that it only works if no other/further FFS instances are active, running syncs on other, non-related left-right pairs.

Conversely, a check on the existence of a sync.ffs_lock file in the left or right base location is left-right pair specific; instances of FFS running syncs on other left-right pairs do not block the start of the specific FFS sync launched by the script.
Only if such specific sync is still running it prevents the start of a new instance of that specific sync.