Cloud sync task - email log

HeMaN68

Dabbler
Joined
May 12, 2020
Messages
16
Hi,

I have setup a cloud credential and a cloud sync task in my TrueNAS CORE 12.0 system to run once a day.
It is possible to see the results and view/download the log on the "Cloud Sync Tasks" page. There is also the possibility to set up an alert for a failed cloud sync task on the "system - Alert settings", but I did not find an option to always email the results of a cloud sync task.

What I would like is to have the results/log send to me after completion of the sync task.
I was thinking of using the "post-script option of the sync task to do so.

I am not very familiar with scripting, so I started searching for similar scripts.
I came across this topic A script to run rclone on the FreeNAS server to backup NAS data to Backblaze B2 cloud storage that pointed to this script on github.
Preferrably I would not use the script to do the sync task but just use the GUI to set this up, so I mainly focussing on the e-mail reporting part of this script.
I think I can modify this (extract the part that is formatting and sending the email), but am lost as where to get the log/output that the cloud sync task produces so it can be processed.

  • Can anybody help me by pointing out where a script can retrieve the content of a cloud sync task log?
 

HeMaN68

Dabbler
Joined
May 12, 2020
Messages
16
Ok, I have found the log files for the script tasks. They are in </tmp/middlewared/jobs>

The log files are numbered and numbers change every time a task is run.
  • Is there a way I can pass the number given to a task to the "post-script" of that task?
 

BossyBear

Dabbler
Joined
Mar 27, 2013
Messages
48
This is a pretty old thread but I don't see a built-in solution for this so I came up with a bit of a kludge that works.

For example. let's say you have a weekly sync task that runs Mondays at 00:00.

In the Pre-script section of your Cloud Sync Task put an email notification for the start of the task...
echo 'task name started' | /usr/bin/mail -s 'TrueNAS task name started' email@domain.com

In the Post-script section put the email to send you the log file.
/bin/cat /tmp/middlewared/jobs/*.log | /usr/bin/mail -s 'TrueNAS task name completed' email@domain.com

To ensure there is only one log file that will be included in the email, add a Cron Job task that runs Sunday at 23:59 (1 minute prior to the Cloud Sync Task) to clear out the logs folder.
/bin/rm /tmp/middlewared/jobs/*.log

For each Cloud Sync Task schedule you add a Cron Job task just prior, to purge the log files, so that only one file exists at the end of your Cloud Sync Task and then the individual log filename doesn't matter as long as it ends in .log.

Am I missing some other information in the jobs folder that I might need? Maybe, but I'll deal with that if and when I actually have a problem.

Danny
 
Top