diff options
-rwxr-xr-x | backup-pg | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -53,14 +53,25 @@ else exit 1 fi -sudo -u postgres psql $PORT -l -t | awk '$1 != "" {print $1}' | +if [ -z "${PGHOST:-}" ] && + [ -z "${PGUSER:-}" ]; then + SUDO="sudo -u postgres" +elif [ -n "${PGHOST:-}" ] && + [ -n "${PGUSER:-}" ]; then + SUDO="" +else + echo "Need to either set both or none of PGHOST, PGUSER" >&2 + exit 1 +fi + +$SUDO psql $PORT -l -t | awk '$1 != "" {print $1}' | while read db; do if [ "$db" = "template0" -o "$db" = "template1" ] ; then continue; fi file="$BASE/$DATE-$PREFIX$db.plain" - sudo -u postgres pg_dump $PORT --create --format=p "$db" > "$file" + $SUDO pg_dump $PORT --create --format=p "$db" > "$file" nice bzip2 -- "$file" md5=`md5sum -- "$file.bz2" | awk '{print $1}'` |