Here is my postgres (pgsql) backup script:
Code:
#!/bin/sh
# Bak dump dir - Change me
BACKUP="/backup"
# get list of dbs
PGDBS=$(psql -h localhost -U postgres -q -c "\l" | sed -n 4,/\eof/p | grep -v rows\) | awk {'print $1'})
for d in $PGDBS; do
NOW=`date '+%T %x'`
vacuumdb -z -h localhost -U postgres $d
pg_dump $d -h localhost | gzip > "$BACKUP/postgresql-$d-$NOW.gz"
done
Run script as postgres or root user. Cron job:
Code:
03 05 * * * /path/to/pgsql.backup.sh > /dev/null 2>&1