Rdiff-backup Monitoring Plugin
rdiff-backup creates simple and efficient backups under Linux. With a Monitoring-plugin, for example for Icinga, which is introduced in this article, allows you to keep track of changes in the rdiff-backup-data directory. It warns you if the backup has not been run for a long time or if too much data has suddenly changed in the mirror.

The plugin offers the following features:
- whether the backup is still running at a specific time (and, for example, has stalled)
- if the source directory suddenly becomes smaller than a certain value (e.g., data was accidentally deleted from the source)
- whether the mirror has grown by more than a specified value (e.g., data that should not have been backed up was backed up by mistake).
Installation of plugin
The plugin check_rdiff is available for download at nagios-exchange:
- check check_rdiff details (exchange.nagios.org)
$ sudo cp check_rdiff /usr/lib/nagios/plugins/check_rdiff $ sudo chown root:root /usr/lib/nagios/plugins/check_rdiff
Configuration of plugin
check_rdiff is executed with root privileges. It is therefore best to set up a sudo configuration for the nagios user:
$ sudo vi /etc/sudoers.d/rdiff nagios ALL=(root)NOPASSWD:/usr/lib/nagios/plugins/check_rdiff $ sudo chmod 440 /etc/sudoers.d/rdiff
As a nagios user, you can test whether the configuration is working:
$ sudo su nagios --shell=/bin/bash nagios@trusty:/home/tktest$ sudo /usr/lib/nagios/plugins/check_rdiff Usage: rdiff_check2.pl [OPTIONS] [...]
When calling the plugin with sudo, no password prompt should appear!
A configuration is also created for the command definition:
$ sudo vi /etc/nagios-plugins/config/rdiff.cfg
# check rdiff-backup
define command{
command_name check_rdiff
command_line sudo $USER1$/check_rdiff -r $ARG1$ -w $ARG2$ -c $ARG3$ -l $ARG4$ -s $ARG5$ -p $ARG6$
}
This command can be used in a service definition:
define service{
use generic-service
host_name localhost
service_description rdiff-backup
check_command check_rdiff!/home/tktest/etc-backup!8!10!100!50!24
}
The check command:
- issues a warning if the backup is still running after 8:00 a.m.
- returns a critical if the backup is still running after 10:00
- These time settings assume that a normal backup should already be completed by 8:00 a.m.!
- A warning, when more than 100MB have been changed in the mirror (TotalDestinationSizeChange)
- A critical, when source got smaller than 50MB (SourceFileSize)
On the command line, perform the plugin as follows:
$ sudo /usr/lib/nagios/plugins/check_rdiff -r etc-backup/ -w 8 -c 10 -l 100 -s 50 -p 24 OK: Last backup finished Mon Mar 9 21:58:31 2015. Size change 0 MB
-
The backup has not run for more than 9 hours.
-
Too much data has changed in the mirror.
-
The source directory has fallen below the specified limit value.
Evaluations
The plugin evaluates the following fields of session.statistics. These are explained in the Analyse von rdiff-backup Statistiken article:
- SourceFileSize -> Source directory is smaller than the specified limit value
- TotalDestinationSizeChange -> Mirror directory (including rdiff-backup-data) increased by more than the given value
Performance data

The original plugin does not output any performance data at the moment. A patch shows, if the backup has been successful, performance data on:
- SourceFileSize
- TotalDestinationSizeChange
- new, deleted und changed files
If the backup failed, no performance data will be output.
--- check_rdiff.orig 2015-03-11 09:23:08.531400084 +0100
+++ check_rdiff 2015-03-11 09:42:22.247409429 +0100
@@ -61,6 +61,9 @@
my $pid_2;
my $size_now;
my $size_change;
+my $new_files;
+my $deleted_files;
+my $changed_files;
my $script;
my $err = 0;
#r=repository
@@ -162,28 +165,32 @@
print "ERROR: Could not open stat file\n";
exit(3);
}
-
- <FILE>;<FILE>;<FILE>;<FILE>;
- $size_now = <FILE>;
- ($size_now) = $size_now =~ /SourceFileSize (.*) \(.*\)$/;
-
- if($size_now <= $s_thresh)
+ while(my $line = <FILE>){
+ $size_now = $1 if $line =~ /SourceFileSize (.*) \(.*\)$/;
+ $new_files = $1 if $line =~ /NewFiles (.*)$/;
+ $deleted_files = $1 if $line =~ /DeletedFiles (.*)$/;
+ $changed_files = $1 if $line =~ /ChangedFiles (.*)$/;
+ $size_change = $1 if $line =~ /TotalDestinationSizeChange (.*) \(.*\)$/;
+ }
+ close FILE;
+ $size_now /= 1048576;
+ $size_change /= 1048576;
+ if($size_now*1048576 <= $s_thresh)
{
$s_thresh /= 1048576;
- print "CRITICAL: Source repository size dropped under $s_thresh megabyte(s)\n";
- exit(2);
+ print "CRITICAL: Source repository size dropped under $s_thresh megabyte(s)";
+ printf("|source_size=%.3fM; size_change=%.3fM; new_files=%d; deleted_files=%d; changed_files=%d;",$size_now, $size_change, $new_files, $deleted_files, $changed_files);
+ exit(2);
}
-
- <FILE>;<FILE>;<FILE>;<FILE>;<FILE>;<FILE>;<FILE>;<FILE>;<FILE>;<FILE>;<FILE>;
- ($size_change) = <FILE> =~ /TotalDestinationSizeChange (.*) \(.*\)$/;
- if($size_change >= $l_thresh)
+ if($size_change*1048576 >= $l_thresh)
{
- $size_change /= 1048576;
- printf("WARNING: Transferred more than threshold(%dMB)\n", $size_change);
+ printf("WARNING: Transferred more than threshold (%dMB)", $size_change);
+ printf("|source_size=%.3fM; size_change=%.3fM; new_files=%d; deleted_files=%d; changed_files=%d;",$size_now, $size_change, $new_files, $deleted_files, $changed_files);
exit(1);
}
$elapsed = localtime(stat($stats_fn)->mtime);
- printf("OK: Last backup finished %s. Size change %d MB\n", $elapsed, $size_change / 1048576);
+ printf("OK: Last backup finished %s. Size change %d MB", $elapsed, $size_change);
+ printf("|source_size=%.3fM; size_change=%.3fM; new_files=%d; deleted_files=%d; changed_files=%d;",$size_now, $size_change, $new_files, $deleted_files, $changed_files);
exit(0);
}Author: Georg Schönberger
|
Translator: Alina Ranzinger Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.
|

