I'm busy setting up a back-up script to run on my Pi using rsync.

I see that a number of people use the -v option in their cron jobs. Why? It's going to be run as root, and not in a terminal where someone will see it.

I understand that maybe if something happens you can tail /var/logs/syslog, but the chance of that happening is negligible.

As I'm running the backup between 2 external hard drives on the same system, I can see the benefit of using -za. The -z for compression because why not, the CPU is barely taxed at the best of times. The -a to preserve permissions, time-stamps, symlinks and owners and groups and to make it recursive.

I might remove the -z and replace it with -W to write whole files in stead of blocks, but I don't want it to run for too many hours.

Is there a way to output any encountered errors to an error log file? In that case, the -v option might make sense - unless I'm missing something here.

  • The -z option of rsync is effective only for network transfers, so it is ignored when both source and destinations are on the same machine. – Marki555 Jun 15 '16 at 7:48
  • Good to know. I'm using it to back up partitions on the same computer. so it's pointless there. However, I am planning on using it to replicate to a separate network device at some point in the future, I'll keep this in mind. – Jim Jun 17 '16 at 7:48
  • For backups you can consider rdiff-backup which actually backs up the data (stores compressed binary differences between actual and old files), not just copies them. It is based on rsync. – Marki555 Jun 17 '16 at 13:35
  • @Marki555 Thanks for the extra info. I've done a bit of reading up on it. I don't really need incremental backups, only a single back-up if my primary HDD fails. One comparative review on rsync vs rdiff-backup indicates that generating those SHA-1 hashes uses quite a bit of CPU. (all the cores on an core-i7 CPU). As I'm running it on a RPI2, I don't really want to overtax it too much. So I think I'll stick with rsync for now. I appreciate your feedback though, and I'm sure that someone will find it useful. (once again, I'd +1 if I could). – Jim Jun 20 '16 at 9:15

Usually, cron sends the output of the jobs it runs to the relevant user; so -v is useful there because you get an email with the full output of the rsync command. On a correctly-configured system, even mail to root goes to the appropriate user.

For this to work you need mail to be setup appropriately on the system running cron; that used to be common on Unix-type systems, not so much nowadays... cron uses sendmail by default to send email; this can be overridden with the -m option to crond. Alternatively, you can configure crond to log job output using syslog, with the -s option.

You can also redirect individual cron jobs' output using shell redirection, so > somelog.log 2> errorlog.log would log standard output to somelog.log, and standard error to errorlog.log (you can of course add paths).

| improve this answer | |
  • Usually I just redirect stdout to a logfile (so I can look later) and leave stderr unredirected, so when error occurs I receive an email from cron. – Marki555 Jun 15 '16 at 7:46
  • 1
    @Marki555 yup, that works well; I tend to use moreutils' chronic (but that doesn't leave any trace at all when everything appears to go well). – Stephen Kitt Jun 15 '16 at 7:51
  • Very cool! love the moreutils! going to be re-doing a lot of things with that chronic now! Would +1 if i could on that! Thanks! – Jim Jun 17 '16 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.