#!/bin/bash
# /usr/local/bin/rsnapshot-postexec
# http://crystalfaeries.net/posix/bin/rsnapshot-postexec
# invoked by /etc/rsnapshot.conf
# celeste:crystalfaery 2015-11-20 15:09:49+00:00
# The only accepted argument is "-du" to specify to run a disk useage analysis at the end of the run.
# NOTE: we are NOT reporting the size of the excluded-from-rsnapshot-backups directories:
# /home/dar/
# /home/public/ (which contains /home/public/downloads)
# as we will never consider them for inclusion in rsnapshots
# we handle either hourly or daily as maximum frequency of backups
file_system="$( grep snapshot_root /etc/rsnapshot.conf | head -n 1 | cut -f 2 | sed 's/\/$//' )"
cd $file_system || exit 1 # nothing to do if no root file system?
cd $file_system/daily.0/`hostname` > /dev/null 2>&1
cd $file_system/hourly.0/`hostname` > /dev/null 2>&1
if [ "$file_system" = "`pwd`" ]
then
exit 1 # we could not find any backups inside root file system?
fi
# CALCULATE DISK SPACE USED #
if [ "$#" != 0 ]
then
if [ "$1" == "-du" ]
then
rsnapshot du 2> /dev/null > /var/log/`hostname`.rsnapshot.du.txt
du -a -x 2> /dev/null | sed 's/ \./ /' | sort -k2 >> /var/log/`hostname`.rsnapshot.du.txt
du -s -x $( grep '^exclude' /etc/rsnapshot.conf | cut -f 2 | grep -v /home/dar | grep -v /home/public | grep -v /home/raid) 2> /dev/null | sed 's/ \./ /' | sort -k2 > /var/log/`hostname`.rsnapshot.excluded.txt
else
echo "$0 argument $1 unacceptable." 1>&2
exit -1
fi
shift # consume the argument
fi
exit $?
syntax highlighted by Code2HTML, v. 0.9.1