Suggestions for the manual - scheduling batch jobs

Discuss new features and functions
Posts: 3
Joined: 10 Oct 2019

Retne

Hi there.

I'm a long term user of FreeFileSync (who has recently noticed his contribution ended a little while ago, but anyway...) and I have a few suggestions for the Scheduled Task help page [https://freefilesync.org/manual.php?topic=schedule-batch-jobs].

They're mostly quite small things (tiny in some cases!), but things I think might need to be highlighted to be that bit more helpful. I did troubleshooting on my own, but these extra notes or changes could have saved me looking a bunch of things up.

Oh, and I looked for a way to submit this to git / other repo knowing this is OSS, but couldn't find anything. Have I missed that?

I'll put these here as a list and I'm aware they are my own experiences etc... This is a mix of small quick things and slightly bigger issues

----
The help page shows the following

"By default, FreeFileSync will show a progress dialog during synchronization and will wait while the summary dialog is shown. If the progress dialog is not needed, enable checkbox Run minimized and also set Auto-Close if you want to skip the summary dialog at the end.
Note
Even if the progress dialog is not shown at the beginning, you can make it visible at any time during synchronization by double-clicking the FreeFileSync icon in the notification area."

First up for scheduled tasks you *want* to make this choice, don't you? If you don't hide the errors and the UI the scheduled task doesn't finish. I'd make this much stronger here (given we're talking scheduled tasks here not just batch jobs). For scheduled tasks, you likely don’t want the progress dialogue.

And please note there that the UI might not show up anywhere a user can see – you might need to open the notification area icons on the taskbar - not all folks will know to look there.
---
It would be useful to keep the numbering going - the W10 bullets would become 5-8, Mac 5-10. It might remind folks like me who knew how to create batch jobs that the stuff above that line was important (the notes on ignore errors), and wouldn't hurt anyone, I suspect.
---
I think it would be great to say what results might be expected (and even what to do with them).
I ignore errors so the task might run and have an error or two still showing. That's fine, but I then want a way to monitor it.

In my instance that was an extra job to check the status of two different batch files and email me if there was an issue (I'll post it below, and happy to add extra comments - just showing it here in case it's of interest to others). I was going to use the Scheduled task email command, but that's depreciated.

Of course, there is then the issue of that batch job failing, so it might be worth adding a final job to email weekly to say there's no problems as opposed to that one that reports problems.
---
On Windows it might be worth suggesting the task isn't allowed to run for three days, in most cases. At least have people think about that.
---
I haven't created any jobs on Mac, but might add an extra post here about that or I'm happy for someone to beat me to it!
---
Oh, and what are the output codes from running a batch job? I might just have missed seeing them.
---

Cheers all,

R
Posts: 3
Joined: 10 Oct 2019

Retne

Edit: out of date, and not as nicely formatted as my post two posts down:

# Here's the powershell I created to monitor those tasks and let me know if there was a problem:

# List of tasks to check. Can just do one - remove the "," and 2nd name, or add a "," and third name
$ScheduledTaskNames = "FolderName[ifUsed]FromScheduledTasks\TheScheduledTaskName", "FolderName[ifUsed]FromScheduledTasks\TheScheduledTaskName"

foreach($ScheduledTaskName in $ScheduledTaskNames) {
$Result = (schtasks /query /FO LIST /V /TN $ScheduledTaskName | findstr "Result")
$Result = $Result.substring(12)
$Code = $Result.trim()

If ($Code -ne 0) {
# Handy debugging line below for checking this PowerShell script. When the task is running normally as a scheduled task, comment out the line below with a #, as here
# Write-Output ($ScheduledTaskName + ' : ' + $result.ToString())

$User = "your@email.com"
$Pass = ConvertTo-SecureString -String "YourReallySecurePassword" -AsPlainText -Force

$Credentials = New-Object System.Management.Automation.PSCredential $User, $Pass

$From = "Alert - Scheduled Sync Task Fail <your@email.com>"
$To = "Your name probably <your@email.com>"
$Subject = "Scheduled task 'Backup' failed"
$Body = $ScheduledTaskName + ' : ' + "Error code: $Code"
$SMTPServer = "smtp.gmail.com" # for example...
$SMTPPort = "587"

Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Credentials
}
}

# This send one email per failed task (or one that worked but has a clash, perhaps)
# I can add the scheduled task xml for this too if that would be useful. Perhaps an "Advanced" page with a link to that in the Note column?
Last edited by Retne on 04 Dec 2019, 14:35, edited 1 time in total.
User avatar
Site Admin
Posts: 7042
Joined: 9 Dec 2007

Zenju

Great feedback! I've integrated most of your suggestions. Email OTOH might be a great feature for FFS to offer directly (viewtopic.php?t=3842), ideally one would just enter his email address without any configuration.
Posts: 3
Joined: 10 Oct 2019

Retne

Happy to contribute rather than just complain :)

Oh, and for completeness and anyone else interested I've updated my script that may be useful until email is added so here's the slightly updated version:
#Source: https://freefilesync.org/forum/viewtopic.php?t=4286
#0 - Synchronization completed successfully
#1 - Synchronization completed with warnings
#2 - Synchronization completed with errors
#3 - Synchronization was aborted

#(Note: I sometimes get the error #-2147020576 - but I'm not sure what that is (searching suggests a number of possibilities). It's transient, to make that more fun to debug... ;)

# Here's the PowerShell I created to monitor those tasks and let me know if there was a problem other than a warning:
# First, the list of tasks to check. Can just do one - remove the "," and 2nd name, or add a "," and third name
$ScheduledTaskNames = "Quietboy\Daily misc backup sync jobs", "Quietboy\One way sync job for game files"


foreach($ScheduledTaskName in $ScheduledTaskNames) {
    $Result = (schtasks /query /FO LIST /V /TN $ScheduledTaskName  | findstr "Result")
    $Result = $Result.substring(12)
    $Code = $Result.trim()

    If (-not($Code -eq 0 -Or $Code -eq 1)) {
        # Handy debugging line below for checking this PowerShell script. When the task is running normally as a scheduled task, comment out the line below with a #, as here
        # Write-Output ($ScheduledTaskName + ' : ' + $result.ToString())
       
        $User = "r.randell@outlinedesign.com"
        $Pass = ConvertTo-SecureString -String "46327bd542d35a#03af2]d39e4b82387d411232f9cfb16fd6ebe341cf28425cb" -AsPlainText -Force

        $Credentials = New-Object System.Management.Automation.PSCredential $User, $Pass
       
        $From = "Alert Scheduled Task <r.randell@outlinedesign.com>"
        $To = "Rob Randell <r.randell@outlinedesign.com>"
        $Subject = "Scheduled task 'Backup' failed"
        $Body = $ScheduledTaskName + ' : ' + "Error code: $Code"
        $SMTPServer = "smtp.office365.com"
        $SMTPPort = "587"

        #[System.Windows.MessageBox]::Show(": " + $Code + " asdf")
        #Write-Host ": " + $Code + " " + $ScheduledTaskName
        #Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Credentials
    }
}

# This sends one email per failed task (or one that worked but has a clash, perhaps)
# I can add the scheduled task xml for this too if that would be useful, but it just runs once a day with a reasonable delay after the sync batch jobs. Perhaps an "Advanced" page with a link to that in the Note column?