Skip to content

check_rsnapshot.php

barryo edited this page Sep 28, 2012 · 4 revisions

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://[email protected]/root/        srv1/
#NAGIOS rsync://[email protected]/root/        ALIAS            srv1
#NAGIOS rsync://[email protected]/root/        TIMESTAMP        var/cache/rsnapshot-timestamp.txt
#NAGIOS rsync://[email protected]/root/        MINFILES         22000        210000
#NAGIOS rsync://[email protected]/root/        MINSIZE          22G          21G
  • ALIAS sets an alias for the backup key (rsync://[email protected]/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
Clone this wiki locally