Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Possible Duplicate:
How to repeatedly call rsync until files are sucessfully transferred

I've configured a nightly rsync to mirror one server to a standby offsite backup server. The total datastore on the primary is 1.5TB. In the course of getting this working, I ran into numerous instabilities with the environment, which I seem to have sorted out, but even though it's now working, I am still nervous. This is intended to be a disaster-scenario standby server, and if disaster strikes and the standby does not have all the proper data synchronized, I'm out of a job.

Thus, I want to script a system that will confirm, after each nightly sync, that the destination data matches the source. I realize that rsync does this, but if rsync doesn't complete fully (which was happening during the setup troubleshooting), I need to know.

Any suggestions? I'm best with Ruby, if that is relevant for the solution.

share|improve this question

marked as duplicate by womble, Scott Pack, Ward, kubanczyk, MadHatter Dec 16 '12 at 15:19

This question was marked as an exact duplicate of an existing question.

Just check the exit code of rsync? – EEAA Jul 6 '12 at 6:28

I would just setup an MTA on the machine (sSMTP is great if you've got a smarthost available) so that any output from the cronjob is mailed to you. Running rsync with --quiet should be sufficient (i.e. it should not output anything if it was successful, but output an error message if not), but you could also explicitly check its exit code in a script to make sure that there's some output.

rsync [...]
if [ "$CODE" -ne 0 ]; then
    echo "rsync exited with code $CODE"
share|improve this answer
This is a really bad idea; eventually you get bored looking at innocuous errors and you don't notice the one that actually means something. – womble Jul 6 '12 at 7:09
@womble Then get rid of the innocuous errors ;-) If it fails often then add retries for example. – mgorven Jul 6 '12 at 7:22
@womble I'm not suggesting that this is appropriate for monitoring hundreds of tasks, at that point one definitely needs a proper monitoring system. The OP wants to monitor a single task however, and cron mails are a quick and simple solution. It's certainly not perfect, but it's often good enough. – mgorven Jul 6 '12 at 7:34
Even monitoring a single task via e-mail is not good enough when your job's on the line. What happens if it starts e-mailing while you're on holidays, and because it didn't e-mail for the past two years you didn't think to add it to the "stuff to forward to my newly hired colleague" six months earlier? Nope, you do this, it's going to bite you in the arse sooner or later and then you're cactus. – womble Jul 6 '12 at 7:45
@womble Well, this should go to a root@ address which is delivered to more than one person, but I see your point. – mgorven Jul 6 '12 at 7:58

Take a look at the hosted solution PushMon. First you create a PushMon URL. Then in your script, when the exit code is 0, call your PushMon URL. As long as you keep calling your PushMon URL, no alerts will be sent. When your script does not run or hangs, and thus does not call the PushMon URL, you will get alerted.

Note I'm associated with PushMon.

share|improve this answer

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