Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm backing up a remote server to another computer using rsync.

In cron.daily I have a file with this:

rsync -avz -e ssh /mybackup/

It uses a public / private key pair to login. This seems to work well most of the time however, I've (foolishly) only ever really checked it by looking at the dates on some important files (MySQL dumps) that I know change every day. Obviously, an error could occur after that file.

Sometimes it fails. When I run it manually, something like "client reset" sometimes happens.

What is the best way to log it so that I can check with certainty if it completed or not? The cron log doesn't indicate any errors. I haven't tried it but the rsync man page on the oldish version of CentOS on the backup machine doesn't show the --log-file option. I guess I could redirect stdout with > but I don't really want to know about every file. I just want to know if it all worked or not..


share|improve this question
up vote 11 down vote accepted

I think you've already solved your own question. If you redirect both stdout and stderr to a file, you won't get output for every file rsync transfers -- this is only produced if you're running in verbose (-v) mode. The default behavior of rsync is to only produce output in the event of an error. So you can do this...

rsync ... > /var/log/rsync.log 2>&1

...and inspect that file to see if the most recent rsync was successful or not. I'm explicitly using >, which will overwrite the log file each time rsync runs.

You could also take advantage of the fact that rsync exits with a non-zero code when the transfer fails, so you could so something like this:

rsync ... || echo "rsync failed" | mail -s 'rsync falied'
share|improve this answer
Thanks. I'll give it a go. I assumed I'd get every file in the log because that's what I see on the screen if I try it manually without verbose. The mail thing looks good. – tetranz Jan 6 '11 at 15:23
If you're running rsync manually without the -v flag and you're still seeing per-file output, there's something wrong. The rsync man page says, "By default, rsync works silently. A single -v will give you information about what files are being transferred and a brief summary at the end." – larsks Jan 6 '11 at 15:32
Well that's definitely what's happening. -v seems to be on by default. I just did the log redirection as you suggest and the log has a line for every file. I'm not saying you're wrong. CentOS must have compiled rsync differently. I've added excludes for /proc and /sys. – tetranz Jan 6 '11 at 16:15
I'm running CentOS, and rsync behaves as described. What does your command line actually look like? – larsks Jan 6 '11 at 16:26
I ran the file manually. It contains: #!/bin/sh rsync -avz --exclude "/proc/" --exclude "/sys/" -e ssh /mybackup/ >> /var/log/rsync.log 2>&1 – tetranz Jan 6 '11 at 16:29

Take out the -v option and add -q. This will only give the errors

share|improve this answer

Maybe you could use the syslog via the command: logger.

I run scripts this way:

rsync -v what user@host 2>&1 | logger -t backup

This will write to /var/log/messages by default.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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