pgsql: postgres user UID is now the one from inside the vserver if necessary
[matthijs/upstream/backupninja.git] / handlers / pgsql
index 2b6f25a421d67892c1c7218c68e66472ae7f3ddd..0c72c82ec04294ee6a0f610a1e196aa9f9be2c0a 100644 (file)
@@ -15,7 +15,7 @@ localhost=`hostname`
 local usevserver=no
 local vroot
 if [ $vservers_are_available = yes ]; then
-   if [ -z "$vsname" ]; then
+   if [ -n "$vsname" ]; then
       # does it exist ?
       if ! vservers_exist "$vsname" ; then
          fatal "The vserver given in vsname ($vsname) does not exist."
@@ -61,7 +61,11 @@ fi
 
 # give backup dir the good uid and permissions
 # (in respect to the vserver, if $usevserver = yes)
-pguid=`getent passwd postgres | awk -F: '{print $3}'`
+if [ $usevserver = yes ]; then
+   pguid=`$VSERVER $vsname exec getent passwd postgres | awk -F: '{print $3}'`
+else
+   pguid=`getent passwd postgres | awk -F: '{print $3}'`
+fi
 [ -n "$pguid" ] || \
     fatal "No user called postgres`[ $usevserver = no ] || echo \" on vserver $vsname\"`."
 debug "chown $pguid $vroot$backupdir"
@@ -72,13 +76,13 @@ chmod 700 $vroot$backupdir
 # if $databases = all, use pg_dumpall
 if [ "$databases" == "all" ]; then
     if [ $usevserver = yes ]; then
-       execstr="$VSERVER $vsname exec su - postgres -c $PGSQLDUMPALL > $backupdir/${vsname}.sql"
+       execstr="$VSERVER $vsname exec su - postgres -c \"$PGSQLDUMPALL > $backupdir/${vsname}.sql\""
     else
-       execstr="su - postgres -c $PGSQLDUMPALL > $backupdir/${localhost}-all.sql"
+       execstr="su - postgres -c \"$PGSQLDUMPALL > $backupdir/${localhost}-all.sql\""
     fi
     debug "$execstr"
     if [ ! $test ]; then
-       output=`$execstr 2>&1`
+       output=`eval $execstr 2>&1`
        code=$?
        if [ "$code" == "0" ]; then
            debug $output
@@ -94,13 +98,13 @@ else
     for db in $databases; do
        if [ $usevserver = yes ]
            then
-           execstr="$VSERVER $vsname exec su - postgres -c $PGSQLDUMP $db > $backupdir/${db}.sql"
+           execstr="$VSERVER $vsname exec su - postgres -c \"$PGSQLDUMP $db > $backupdir/${db}.sql\""
        else
-           execstr="su - postgres -c $PGSQLDUMP $db > $backupdir/${db}.sql"
+           execstr="su - postgres -c \"$PGSQLDUMP $db > $backupdir/${db}.sql\""
        fi
        debug "$execstr"
        if [ ! $test ]; then
-           output=`$execstr 2>&1`
+           output=`eval $execstr 2>&1`
            code=$?
            if [ "$code" == "0" ]; then
                debug $output