ソースを参照

Fix stderr capture and check return code while running pg_dump/pg_dumpall commands

Emmanuel Bouthenot 1 年間 前
コミット
0b3081df05
2 ファイル変更12 行追加7 行削除
  1. 2 1
      Changelog.md
  2. 10 6
      autopostgresqlbackup

+ 2 - 1
Changelog.md

@@ -2,7 +2,8 @@
 
 ## Version 2.1
 
-Variable `OPT` (used with pg_dump) is renamed to `PGDUMP_OPTS` and a new variable `PGDUMPALL_OPTS` is available (used for dump globals with pg_dumpall) (Closes: [#12](https://github.com/k0lter/autopostgresqlbackup/issues/12))
+* Variable `OPT` (used with pg_dump) is renamed to `PGDUMP_OPTS` and a new variable `PGDUMPALL_OPTS` is available (used for dump globals with pg_dumpall) (Closes: [#12](https://github.com/k0lter/autopostgresqlbackup/issues/12))
+* Fix stderr capture and check return code while running pg_dump/pg_dumpall commands
 
 ## Version 2.0
 

+ 10 - 6
autopostgresqlbackup

@@ -301,9 +301,11 @@ dblist () {
     log_debug "Running command: ${cmd_prog} ${cmd_args[*]}"
     raw_dblist=$(
         if [ -n "${SU_USERNAME}" ]; then
-            su - "${SU_USERNAME}" -l -c "${cmd_prog} ${cmd_args[*]}"
-        else
-            "${cmd_prog}" "${cmd_args[@]}"
+            if ! su - "${SU_USERNAME}" -c "${cmd_prog} ${cmd_args[*]}" 2> >(logger "err" "error"); then
+                log_error "Running (as user '${SU_USERNAME}' command '${cmd_prog} ${cmd_args[*]}' has failed"
+            fi
+        elif ! "${cmd_prog}" "${cmd_args[@]}" 2> >(logger "err" "error"); then
+            log_error "Running command '${cmd_prog} ${cmd_args[*]}' has failed"
         fi
     )
 
@@ -362,9 +364,11 @@ dbdump () {
 
     log_debug "Running command: ${cmd_prog} ${cmd_args[*]}"
     if [ -n "${SU_USERNAME}" ]; then
-        su - "${SU_USERNAME}" -l -c "${cmd_prog} ${cmd_args[*]}"
-    else
-        "${cmd_prog}" "${cmd_args[@]}"
+        if ! su - "${SU_USERNAME}" -c "${cmd_prog} ${cmd_args[*]}" 2> >(logger "err" "error"); then
+            log_error "Running (as user '${SU_USERNAME}' command '${cmd_prog} ${cmd_args[*]}' has failed"
+        fi
+    elif ! "${cmd_prog}" "${cmd_args[@]}" 2> >(logger "err" "error"); then
+        log_error "Running command '${cmd_prog} ${cmd_args[*]}' has failed"
     fi
 }
 # }}}