notification on cron job completions

Status
Not open for further replies.

Dotty

Contributor
Joined
Dec 10, 2016
Messages
125
Hi guys
I have this crontab that rsycnc one dataset to another box, running every night.
I need to know if they are completing successfully or not,, so far I enabled syslog on freenas, on "debug" level, but I still dont see any indication on syslog that the crontab fails or not.
The command Im using on the crontab is:
rsync -avH

The syslog shows this when the rsync jobs starts:
cronjob: sending incremental file list
and shows the folders, etc,, but I cant find anything that shows "success" or "failure" etc.

Thansk
 
Joined
Jan 7, 2015
Messages
1,155
Im no pro at scripting but what I think you want to do is run the task from a bash script, and have the script email you the terminal output, or "echo task completed" or when it finishes, or have it prints that to the terminal 50 times so you can see it easily everyday. This is how I have it and is as simple as I can make it. It first backs up my config, then mirrors my jail drive to my media drive, then mirrors everything on the media drive (less my 30TB of video) to a different 2nd backup. If done frequently, there isnt a ton it actually does. Its not perfect, but it works. Then I simply get an email that says "Task completed sucessfully". Run the rsync once or twice using --dry-run to be sure it is doing what you want.. then commit it to the script and run it from a cron task.

Here is my script file, that works. You can edit it up (poolnames and paths, email) and use it, or you can use it to write your own. I am not a script expert, at all, but it does work this way. I used to run verbose output into the email, but it isnt necessary if you know the rsync command is doing what you want.

Code:
#!/bin/sh
cp /data/freenas-v1.db "/mnt/zfs1/backup/`date \+%Y\%m\%d`.db"
echo "Database Backup Complete"
rsync -ahWe --no-compress --exclude=*/media/* --exclude=*/mnt/* --exclude=*/proc/* --exclude='*.vmdk' --delete /mnt/zfs0/jails/* /mnt/zfs1/backup/zfs0/jails/
rsync -ahWel --no-compress --exclude=video --delete /mnt/zfs1/* /mnt/zfs2/
echo "Jail and Database Backup Complete"
echo "The scheduled RSync Task completed sucessfully" | sendmail root@domain.org
echo "Email Report Sent"


Make a script file with something similar in it then call that script from the FreeNAS cron gui.
 

Dotty

Contributor
Joined
Dec 10, 2016
Messages
125
Im no pro at scripting but what I think you want to do is run the task from a bash script, and have the script email you the terminal output, or "echo task completed" or when it finishes, or have it prints that to the terminal 50 times so you can see it easily everyday. This is how I have it and is as simple as I can make it. It first backs up my config, then mirrors my jail drive to my media drive, then mirrors everything on the media drive (less my 30TB of video) to a different 2nd backup. If done frequently, there isnt a ton it actually does. Its not perfect, but it works. Then I simply get an email that says "Task completed sucessfully". Run the rsync once or twice using --dry-run to be sure it is doing what you want.. then commit it to the script and run it from a cron task.

Here is my script file, that works. You can edit it up (poolnames and paths, email) and use it, or you can use it to write your own. I am not a script expert, at all, but it does work this way. I used to run verbose output into the email, but it isnt necessary if you know the rsync command is doing what you want.

Code:
#!/bin/sh
cp /data/freenas-v1.db "/mnt/zfs1/backup/`date \+%Y\%m\%d`.db"
echo "Database Backup Complete"
rsync -ahWe --no-compress --exclude=*/media/* --exclude=*/mnt/* --exclude=*/proc/* --exclude='*.vmdk' --delete /mnt/zfs0/jails/* /mnt/zfs1/backup/zfs0/jails/
rsync -ahWel --no-compress --exclude=video --delete /mnt/zfs1/* /mnt/zfs2/
echo "Jail and Database Backup Complete"
echo "The scheduled RSync Task completed sucessfully" | sendmail root@domain.org
echo "Email Report Sent"


Make a script file with something similar in it then call that script from the FreeNAS cron gui.
This is a great suggestion!
Ill try to test it tonight.
Thanks!
 
Joined
Jan 7, 2015
Messages
1,155
This along with my replication tasks, ensures that nothing will ever go bad enough to lose everything. Mainly what I care about are my jails, I have lots of databases and a webserver that is critical to keep working for a client. This gets it done!

Good luck!
 
Status
Not open for further replies.
Top