checking rsync run status

7,915

Solution 1

I usually write my rsync backup scripts (and several other kinds of cron jobs) so that they have code like the folowing at the start of the script, immediately after the #! line.

BNAME=$(basename "$0" .sh)
mkdir -p /var/log/cronjobs
LOGFILE="/var/log/cronjobs/$BNAME.log"
savelog $LOGFILE
exec &> $LOGFILE
date

Combined with rsync --verbose --stats ---progress it works well to log everything that the rsync job does.

You can monitor progress with tail -f or tail -F but if you want to view the log file with less you'll have to use less -r or less -R

Solution 2

What do you mean by "monitoring rsync run"? Do you mean the duration, the end time, memory usage or something else?

Anyway, you or your IT may already have some monitoring system in place, so answering this depends on if this is the case or not.

Assuming there's no monitoring system, then just send an email to yourself if the exit status is != 0. There are various ways to do this, which I consider beyond the scope of this answer.

Share:
7,915

Related videos on Youtube

user3744406
Author by

user3744406

Updated on September 18, 2022

Comments

  • user3744406
    user3744406 over 1 year

    We have a cron job running to rsync files from one server to a different host. The cron runs daily at midnight. The file copy is critical for us so we want to monitor the backup runs. We want to monitor two things...

    1. rsync run
    2. Also would like to check whether it failed in the middle of the run . 
    

    Please suggest .

    • roaima
      roaima over 8 years
      Look at the output it produces?
  • user3744406
    user3744406 over 8 years
    It copies around MBs of data . Want to check whether it is successful in copying all the data or failed in the middle while copying the data
  • Jan
    Jan over 8 years
    OK, so checking the exit status is the way to go.