Le script a pour but de générer un rapport quotidien listant l’ensemble des fichiers ajoutés et modifiés suite au précédent job de sauvegarde d’un client BackupPC. L’exécution de ce script est évidemment à planifier quotidiennement.

# more BackupPC_auditReport
#!/bin/bash
#
# Boris HUISGEN
#
# This script will send a audit report log of the last client backup
#

BACKUPPC_CLIENT="server.my.domain"         # client hostname/IP address
BACKUPPC_LOGDIR=/home/backuppc/pc/server   # BackupPC log directory
BACKUPPC_BINDIR=/usr/local/BackupPC/bin    # BackupPC bin directory
MAIL=1                                     # enable/disable mail report
MAIL_TO="admin@my.domain"                  # mail to address
MAIL_CC="toto@my.domain"                   # mail cc addresses (comma list)

#
# script
#

XFER_PID="$1"                        # custom XFER PID

if [ ! -d $BACKUPPC_LOGDIR ]; then
   exit;
fi

CURRENT_DIR=$(pwd)

cd $BACKUPPC_LOGDIR

if [ -z "$XFER_PID" ]; then
   XFER_PID=$(find . -mindepth 1  -maxdepth 1 -type d | cut -d'/' -f2 | sort -nr | head -1)
fi

XFERLOG="$BACKUPPC_LOGDIR/XferLOG.$XFER_PID.z"

echo "Checking $XFERLOG..." > /tmp/report_$BACKUPPC_CLIENT
echo "" >> /tmp/report_$BACKUPPC_CLIENT

$BACKUPPC_BINDIR/BackupPC_zcat $XFERLOG | \
grep -e 'create  ' | grep -e '.*\.php' -e '.*\.html' | \
grep -v -i -e '.*/cache/.*' -e '.*templates_c/.*' \
>> /tmp/report_$BACKUPPC_CLIENT

if [ $MAIL -eq "1" ] ; then
   if [ -z $MAIL_CC ]; then
      cat /tmp/report_$BACKUPPC_CLIENT | mail -s '[backuppc] Audit report for '$BACKUPPC_CLIENT $MAIL_TO
   else
      cat /tmp/report_$BACKUPPC_CLIENT | mail -s '[backuppc] Audit report for '$BACKUPPC_CLIENT -c $MAIL_CC $MAIL_TO
   fi
else
   cat /tmp/report_$BACKUPPC_CLIENT
fi

rm /tmp/report_$BACKUPPC_CLIENT
cd $CURRENT_DIR