2019-12-03 21:30:20 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
BACKUPDIR=/home/backups/postgresql
|
|
|
|
LOGFILE=${BACKUPDIR}/my_dump_postgresql.log
|
|
|
|
SENDNSCA=/usr/local/sbin/send_nsca\ -H\ <nagios_host>\ -d\ ';;'\ -c\ /usr/local/etc/nagios/send_nsca.cfg
|
|
|
|
HOSTNAME=`/bin/hostname -f | /usr/bin/cut -d '.' -f 1,2`
|
|
|
|
backup_success=1
|
|
|
|
|
|
|
|
mkdir -p ${BACKUPDIR}
|
|
|
|
rm -f ${LOGFILE}
|
|
|
|
cd ${BACKUPDIR}
|
|
|
|
echo "start" >> ${LOGFILE}
|
|
|
|
for i in `psql --list --tuples-only --port 6432 | grep -v template0 | grep -v template1 | cut -f 2 -d " " | sed '/^$/d' | tr "\n" " "`;
|
|
|
|
do
|
2019-12-03 22:58:19 +01:00
|
|
|
echo -n " ---> backing up ${i}..." >> ${LOGFILE}
|
2019-12-03 22:58:47 +01:00
|
|
|
pg_dump --port 5432 ${i} > ${i}.sql && rm -f ${i}.sql.bz2 && bzip2 ${i}.sql >> ${LOGFILE};
|
2019-12-03 21:30:20 +01:00
|
|
|
if [ $? -eq 0 ];
|
|
|
|
then
|
|
|
|
echo " OK" >> ${LOGFILE};
|
|
|
|
else
|
|
|
|
backup_success=0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $backup_success -eq 1 ]
|
|
|
|
then
|
|
|
|
echo "${HOSTNAME};;postgresql_backups;;0;OK - backup succeeded at `date`" | ${SENDNSCA} >/dev/null
|
|
|
|
else
|
|
|
|
echo "${HOSTNAME};;postgresql_backups;;2;CRITICAL - backup failed at `date`, please check ${LOGFILE} for complete report." | ${SENDNSCA} >/dev/null
|
|
|
|
fi
|
|
|
|
echo "end" >> ${LOGFILE}
|