dump all Postgres databases (and send a report to the monitoring system)
This commit is contained in:
parent
dff386e49e
commit
9dd0cb98f8
2 changed files with 32 additions and 0 deletions
|
@ -10,6 +10,7 @@ Scripts
|
|||
* [cleanmaildir.sh](https://forge.tourmentine.com/n/scripts/src/master/cleanmaildir.sh) => delete old mail in maildirs
|
||||
* [dodo.sh](https://forge.tourmentine.com/n/scripts/src/master/dodo.sh) => turn off screen using DPMS
|
||||
* [dump_mysql.sh](https://forge.tourmentine.com/n/scripts/src/master/dump_mysql.sh) => dump all mysql databases (and send a report to the monitoring system)
|
||||
* [dump_postgresql.sh](https://forge.tourmentine.com/n/scripts/src/master/dump_postgresql.sh) => dump all Postgres databases (and send a report to the monitoring system). based on [dump_mysql.sh](https://forge.tourmentine.com/n/scripts/src/master/dump_mysql.sh).
|
||||
* [opdsupdates.py](https://forge.tourmentine.com/n/scripts/src/master/opdsupdates.py) => look for OPDS catalog updates and send a mail if any
|
||||
* [randomwallpaper.sh](https://forge.tourmentine.com/n/scripts/src/master/randomwallpaper.sh) => display a random wallpaper
|
||||
* [secupdate](https://forge.tourmentine.com/n/scripts/src/master/secupdate) => apply security updates & recompile kernel (FreeBSD)
|
||||
|
|
31
dump_postgresql.sh
Executable file
31
dump_postgresql.sh
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/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
|
||||
echo -n " ---> backuping ${i}..." >> ${LOGFILE}
|
||||
pg_dump --port 6432 ${i} > ${i}.sql && rm -f ${i}.sql.bz2 && bzip2 ${i}.sql >> ${LOGFILE};
|
||||
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}
|
Loading…
Reference in a new issue