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
@@ -90,12 +90,23 @@
 # Additionally keep a copy of the most recent backup in a seperate directory.
 LATEST=no
 
+# OPT string for use with pg_dump ( see man pg_dump )
+OPT=""
+
 # Command to run before backups (uncomment to use)
 #PREBACKUP="/etc/postgresql-backup-pre"
 
 # 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
 #=====================================================================
@@ -256,7 +267,6 @@
 LOGFILE=$BACKUPDIR/$DBHOST-`date +%N`.log			# Logfile Name
 LOGERR=$BACKUPDIR/ERRORS_$DBHOST-`date +%N`.log		# Logfile Name
 BACKUPFILES=""
-OPT=""						# OPT string for use with pg_dump ( see man pg_dump )
 
 # Add --compress pg_dump option to $OPT
 if [ "$COMMCOMP" -gt 0 ];
@@ -311,7 +321,11 @@
 dbdump () {
 	touch $2
 	chmod 600 $2
-	pg_dump --username=$USERNAME $PGHOST $OPT $1 > $2
+	if [ -n "$SU_USERNAME" ]; then
+		su $SU_USERNAME -c "pg_dump $PGHOST $OPT $1" > $2
+	else
+		pg_dump --username=$USERNAME $PGHOST $OPT $1 > $2
+	fi
 	return 0
 }
 
@@ -372,7 +386,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 $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
