You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
996 B

#!/usr/bin/env sh
# CONFIG
### Example Config File ############
###
### PORT=5432
### DIR=/var/lib/pgsql/backup
### COMPRESSION=zstd
### COMP_LEVEL=14
### THREADS=2
###
####################################
source ${HOME}/.postgres_backup.conf
# END CONFIG
## Check if automated, set appropriate directory
[ "$1" = "auto" ] && DIR=${DIR}/auto || DIR=${DIR}/manual
## Set date for timestamp
DATE=$(date +%Y%m%d-%H%M)
## Get list of DBs
list_db=$(psql -p${PORT} -U postgres -t -c 'select datname from pg_database;' | grep -v 'template0\|template1\|postgres' | sed '/^$/d')
for db in $list_db; do
case $COMPRESSION in
xz)
pg_dump -O $db | xz -T${THREADS} -${COMP_LEVEL} - > ${DIR}/${db}-${DATE}.dmp.xz
;;
zstd)
pg_dump -O $db | zstd -T${THREADS} -${COMP_LEVEL} -z - > ${DIR}/${db}-${DATE}.dmp.zst
;;
*)
echo "ERROR 11: Compression not configured correctly!"
exit 11
;;
esac
done
## Dump Globals
pg_dumpall -p${PORT} -g > ${DIR}/globals_${DATE}.dmp
exit 0