2015-05-28 11:32:57 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ -f /etc/default/pg_backup ] ; then
|
|
|
|
. /etc/default/pg_backup
|
|
|
|
else
|
2016-01-11 17:43:50 +01:00
|
|
|
PG_BACKUP_ENABLED=True
|
2015-05-28 11:32:57 +02:00
|
|
|
PG_SERVICE=postgresql
|
|
|
|
USE_NAGIOS=no
|
|
|
|
LOG_DIR=/var/log/postgresql
|
|
|
|
LOG_FILE=$LOG_DIR/postgresql-backup.log
|
|
|
|
PG_BCK_BIN=/usr/local/sbin/postgresql-backup
|
|
|
|
fi
|
|
|
|
|
2016-03-21 14:40:56 +01:00
|
|
|
# Remote backup performed by duplicity. When active, do not run via cron
|
|
|
|
if [ -x /etc/cron.daily/duplicity_backup ] ; then
|
|
|
|
echo "duplicity backups active. Exiting" > $LOG_FILE
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Remote backup performed by BackupPC. If it is active, do not run via cron
|
|
|
|
if [ -f /var/log/backuppc.log ] ; then
|
|
|
|
TMSTMP=$( date +%s )
|
|
|
|
. /var/log/backuppc.log
|
|
|
|
LAST_BACKUP_TIME=$( expr $TMSTMP - $BACKUP_TIMESTAMP )
|
2016-11-28 17:58:23 +01:00
|
|
|
if [ $LAST_BACKUP_TIME -lt 86400 -a $BACKUP_RESULT == 'OK' ] ; then
|
2016-03-21 14:40:56 +01:00
|
|
|
echo "BackupPC is active, doing nothing" > $LOG_FILE
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-05-28 11:32:57 +02:00
|
|
|
export PATH="/sbin:/usr/sbin:/usr/local/sbin:$PATH"
|
|
|
|
PG_SVC=$( service $PG_SERVICE status >/dev/null )
|
|
|
|
PG_RUNNING=$?
|
|
|
|
|
2016-01-18 09:49:46 +01:00
|
|
|
if [ $PG_BACKUP_ENABLED == 'True' ] ; then
|
2016-01-11 17:43:50 +01:00
|
|
|
if [ "$PG_RUNNING" -ne "0" -a "$PG_RUNNING" -ne "3" ] ; then
|
|
|
|
echo "The postgresql service is not running" > $LOG_FILE
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
if [ ! -d $LOG_DIR ] ; then
|
|
|
|
mkdir -p $LOG_DIR
|
|
|
|
fi
|
2016-11-28 18:40:06 +01:00
|
|
|
DATE_START=$( date )
|
|
|
|
echo "$DATE_START: Starting the backup procedure" > $LOG_FILE
|
2016-11-28 18:38:54 +01:00
|
|
|
$PG_BCK_BIN >> $LOG_FILE 2>&1
|
2016-11-28 18:40:06 +01:00
|
|
|
DATE_END=$( date )
|
|
|
|
echo "$DATE_END: Backup procedure finished" >> $LOG_FILE
|
2016-01-11 17:43:50 +01:00
|
|
|
fi
|
2015-05-28 11:32:57 +02:00
|
|
|
else
|
2016-01-11 17:43:50 +01:00
|
|
|
echo "Postgresql backups administratively disabled" > $LOG_FILE
|
2015-05-28 11:32:57 +02:00
|
|
|
fi
|
2016-01-11 17:43:50 +01:00
|
|
|
|
2015-05-28 11:32:57 +02:00
|
|
|
if [ "${USE_NAGIOS}" == "yes" ] ; then
|
|
|
|
N_LOGDIR=/var/log/nagios-checks
|
|
|
|
if [ ! -d $N_LOGDIR ] ; then
|
|
|
|
mkdir -p $N_LOGDIR
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
|