Postgres Cron Backups
So, I found myself with the need to make automatic backups of my postgres databases...
After some Google'ing and reading of some peoples recipes, here's mine.
#!/bin/bash
PG_USER="postgres"
SUDO_CMD=
SUDO=" -u "
PSQL_CMD=
PSQL=" "
GREP=
AWK=
PGDUMP_CMD=
PGDUMP=" "
VACUUM_CMD=
VACUUM=" "
FIND=
# Bellow is how old, in days, a backup will need to be deleted.
# This helps cleaning up and don't keep piling backups
MAX_DAYS=3
# Backups destination directory
BACKUPS_DIR="/var/backups/postgresql"
# To get a list of all databases uncomment the following 3 lines
#DBS=$($PSQL -q -c "\l" | sed -n 4,/\eof/p | grep -v rows\) | grep -v template0 | grep -v template1 | awk {'print $1'} | grep -v :)
#echo $DBS
#exit
# Uncomment bellow to backup all databases
#DBS=$($PSQL -q -c "\l" | sed -n 4,/\eof/p | grep -v rows\) | grep -v template0 | grep -v template1 | awk {'print $1'} | grep -v :)
# Uncomment bellow and add the database names you wish to back separated with a white-space
#DBS=""
for
do
BACKUP_NAME=" / -backup- .sql.tar"
done