diff options
author | Peter Palfrader <peter@palfrader.org> | 2011-05-02 14:38:40 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2011-05-02 14:38:40 +0000 |
commit | a442d694fb1dc61e4aafab9b0321e5fef42f1760 (patch) | |
tree | b8b1ea8c2bc38570abf2fdd27ceafd53d23ca1b7 | |
parent | aafd6e4900f798d0342c77441ee8f39236baf4dc (diff) |
handle PGHOST/PGUSER being set
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@478 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
-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}'` |