Skip to content
This repository

check_rsnapshot.php is a script for verifying backups made via the rsnapshot utility through Nagios.

First, as with all BSD licensed files, heed the following:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

It has a number of tests:

  • minfiles - checks the number of files in a snapshot against a minimum expected number;
  • minsize - checks the size of a snapshot against a minimum expected size;
  • log - parses the rsnapshot log to ensure the most recent runs for each retention period completed successfully;
  • timestamp - checks for files created server side containing a timestamp and thus ensuring snapshots are succeedin;
  • rotation - checks that retention directories are being rotated; and
  • dir-creation - checks that retention directories are being created.

Standard usage is:

check_rsnapshot.php -c /etc/rsnapshot/cc-office.conf

Some of the checks require embedded additional configuration to be added to the rsnapshot configuration file. Take the following example:

backup  rsync://rsnapshot@1.2.3.4/root/        srv1/
#NAGIOS rsync://rsnapshot@1.2.3.4/root/        ALIAS            srv1
#NAGIOS rsync://rsnapshot@1.2.3.4/root/        TIMESTAMP        var/cache/rsnapshot-timestamp.txt
#NAGIOS rsync://rsnapshot@1.2.3.4/root/        MINFILES         22000        210000
#NAGIOS rsync://rsnapshot@1.2.3.4/root/        MINSIZE          22G          21G
  • ALIAS sets an alias for the backup key (rsync://rsnapshot@1.2.3.4/root/) for reporting in logs and debugging information.

  • TIMESTAMP sets the relative location to the timestamp file to check. It is checked to ensure it is not older than now minus twice the first (shortest) retention period. For example, if you define retention periods of daily, weekly, monthly in that order, then daily.0 will be checked for the timestamp file. The script will also try daily.1 in case a backup is in progress - hence twice the retention period. For the above example, you might have a crontab entry on 1.2.3.4 such as:

    5 * * * * root echo date +%s >/var/cache/rsnapshot-timestamp.txt

  • MINFILES and MINSIZE set the warning and critical minimum number of files / snapshot size respectively. Beware that if you are backing up multiple mount points with one_fs, checking a higher level mount point will include all sub-points in the calculation. MINSIZE accepts a plain integer as bytes or an integer with K, M or G affixed for Kilobytes, Megabytes or Gigabytes respectively.

Retention Periods

The script defines the following default retention period time intervals:

$periods = array(
    "hourly"  => 3600,
    "daily"   => 86400,
    "weekly"  => 604800,
    "monthly" => 2678400
);

You can override these (or add additional ones) on a pr configuration basis by adding a line such as the following to the configuration file:

#NAGIOS TPERIOD      daily        32000

Nagios Configuration

On the server where you require this script to run, install Nagios NRPE and then add a line such as the following to /etc/nagios/nrpe_local.cfg (or as appropriate on your installation):

command[check_rsnapshot]=/usr/local/nagios-plugins/check_rsnapshot.php -c $ARG1$

Then, on your Nagios server, you need a command configuration such as:

define command {
    command_name                    check_nrpe_rsnapshot
    command_line                    /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -p 5666 -c check_rsnapshot -a $ARG1$
}

and then, per rsnapshot configuration, a service such as:

define service {
    use                             service-daily
    host_name                       bacula
    service_description             rsnapshot - rsnapshot.conf
    check_command                   check_nrpe_rsnapshot!/etc/rsnapshot.conf
}
Something went wrong with that request. Please try again.