2019-12-03 21:30:20 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
BACKUPDIR=/home/backups/postgresql
|
|
|
|
LOGFILE=${BACKUPDIR}/my_dump_postgresql.log
|
2023-08-10 21:47:21 +02:00
|
|
|
SENDZABBIX="zabbix_sender --config /usr/local/etc/zabbix6/zabbix_agentd.conf --key pgsql.backups"
|
|
|
|
HOSTNAME=$(/bin/hostname -f | /usr/bin/cut -d '.' -f 1,2)
|
2019-12-03 21:30:20 +01:00
|
|
|
backup_success=1
|
|
|
|
|
|
|
|
mkdir -p ${BACKUPDIR}
|
|
|
|
rm -f ${LOGFILE}
|
2023-08-10 21:47:21 +02:00
|
|
|
cd ${BACKUPDIR} || backup_success=0
|
2019-12-03 21:30:20 +01:00
|
|
|
echo "start" >> ${LOGFILE}
|
2023-08-10 21:47:21 +02:00
|
|
|
for i in $(psql --list --tuples-only --port 6432 | grep -v template0 | grep -v template1 | cut -f 2 -d " " | sed '/^$/d' | tr "\n" " ");
|
2019-12-03 21:30:20 +01:00
|
|
|
do
|
2023-08-10 21:47:21 +02:00
|
|
|
printf " ---> backing up %s..." "$i" >> ${LOGFILE}
|
|
|
|
pg_dump --port 6432 --format c "${i}" > "${i}".dump 2>> ${LOGFILE} 2>&1;
|
|
|
|
if [ $? ];
|
2019-12-03 21:30:20 +01:00
|
|
|
then
|
|
|
|
echo " OK" >> ${LOGFILE};
|
|
|
|
else
|
|
|
|
backup_success=0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $backup_success -eq 1 ]
|
|
|
|
then
|
2023-08-10 21:47:21 +02:00
|
|
|
${SENDZABBIX} --value 0 >/dev/null
|
2019-12-03 21:30:20 +01:00
|
|
|
else
|
2023-08-10 21:47:21 +02:00
|
|
|
${SENDZABBIX} --value 1 >/dev/null
|
2019-12-03 21:30:20 +01:00
|
|
|
fi
|
|
|
|
echo "end" >> ${LOGFILE}
|