Ver Fonte

Support options SU_USERNAME to make dump from another user like postgres system user on Debian (Debian patch 05_debian_specifics)

Emmanuel Bouthenot há 5 anos atrás
pai
commit
190018c4aa
1 ficheiros alterados com 10 adições e 2 exclusões
  1. 10 2
      autopostgresqlbackup

+ 10 - 2
autopostgresqlbackup

@@ -321,7 +321,11 @@ exec 2> $LOGERR     # stderr replaced with file $LOGERR.
 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
 }
 
@@ -382,7 +386,11 @@ fi
 
 # 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