summaryrefslogtreecommitdiff
path: root/backup-pg
diff options
context:
space:
mode:
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}'`