Description: Add Debian specific changes (use of /etc/defaults/autopostgresqlbackup and su)
Author: Emmanuel Bouthenot <kolter@debian.org>
Forwarded: not-needed
Last-Update: 2011-05-28
--- a/autopostgresqlbackup
+++ b/autopostgresqlbackup
@@ -96,6 +96,14 @@
 # Command run after backups (uncomment to use)
 #POSTBACKUP="/etc/postgresql-backup-post"
 
+# ===============================
+# === Debian specific options ===
+#================================
+
+if [ -f /etc/default/autopostgresqlbackup ]; then
+	. /etc/default/autopostgresqlbackup
+fi
+
 #=====================================================================
 # Options documentation
 #=====================================================================
@@ -311,7 +319,11 @@
 dbdump () {
 	touch $2
 	chmod 600 $2
-	pg_dump --username=$USERNAME $PGHOST $OPT $1 > $2
+	if [ -n "$SU_USERNAME" ]; then
+		su -l $SU_USERNAME -c "pg_dump $PGHOST $OPT $1" > $2
+	else
+		pg_dump --username=$USERNAME $PGHOST $OPT $1 > $2
+	fi
 	return 0
 }
 
@@ -372,7 +384,11 @@
 
 # If backing up all DBs on the server
 if [ "$DBNAMES" = "all" ]; then
-	DBNAMES="`psql -U $USERNAME $PGHOST -l -A -F: | sed -ne "/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }"`"
+	if [ -n "$SU_USERNAME" ]; then
+		DBNAMES="$(su -l $SU_USERNAME -c "LANG=C psql -U $USERNAME $PGHOST -l -A -F: | sed -ne '/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }'")"
+	else
+		DBNAMES="`LANG=C psql -U $USERNAME $PGHOST -l -A -F: | sed -ne "/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }"`"
+	fi
 	
 	# If DBs are excluded
 	for exclude in $DBEXCLUDE
