summaryrefslogtreecommitdiff
path: root/backup-pg
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2011-05-02 14:38:40 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2011-05-02 14:38:40 +0000
commita442d694fb1dc61e4aafab9b0321e5fef42f1760 (patch)
treeb8b1ea8c2bc38570abf2fdd27ceafd53d23ca1b7 /backup-pg
parentaafd6e4900f798d0342c77441ee8f39236baf4dc (diff)
handle PGHOST/PGUSER being set
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@478 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'backup-pg')
-rwxr-xr-xbackup-pg15
1 files changed, 13 insertions, 2 deletions
diff --git a/backup-pg b/backup-pg
index 07a6896..79274c2 100755
--- a/backup-pg
+++ b/backup-pg
@@ -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}'`