|
@@ -104,7 +104,10 @@ COMP="gzip"
|
|
|
COMP_OPTS=
|
|
|
|
|
|
# Options string for use with pg_dump (see pg_dump manual page).
|
|
|
-OPT=
|
|
|
+PGDUMP_OPTS=
|
|
|
+
|
|
|
+# Options string for use with pg_dumpall (see pg_dumpall manual page).
|
|
|
+PGDUMPALL_OPTS=
|
|
|
|
|
|
# Backup files extension
|
|
|
EXT="sql"
|
|
@@ -112,6 +115,10 @@ EXT="sql"
|
|
|
# Backup files permission
|
|
|
PERM=600
|
|
|
|
|
|
+# Minimum size (in bytes) for a dump/file (compressed or not).
|
|
|
+# File size below this limit will raise an warning.
|
|
|
+MIN_DUMP_SIZE=256
|
|
|
+
|
|
|
# Enable encryption (asymmetric) with GnuPG.
|
|
|
ENCRYPTION="no"
|
|
|
|
|
@@ -171,10 +178,17 @@ DEBUG="no"
|
|
|
GPG_HOMEDIR=
|
|
|
|
|
|
# pg_dump options
|
|
|
-if [ -n "${OPT}" ]; then
|
|
|
- IFS=" " read -r -a PG_OPTIONS <<< "${OPT}"
|
|
|
+if [ -n "${PGDUMP_OPTS}" ]; then
|
|
|
+ IFS=" " read -r -a PGDUMP_ARGS <<< "${PGDUMP_OPTS}"
|
|
|
+else
|
|
|
+ PGDUMP_ARGS=()
|
|
|
+fi
|
|
|
+
|
|
|
+# pg_dumpall options
|
|
|
+if [ -n "${PGDUMPALL_OPTS}" ]; then
|
|
|
+ IFS=" " read -r -a PGDUMPALL_ARGS <<< "${PGDUMPALL_OPTS}"
|
|
|
else
|
|
|
- PG_OPTIONS=()
|
|
|
+ PGDUMPALL_ARGS=()
|
|
|
fi
|
|
|
|
|
|
# Create required directories
|
|
@@ -291,9 +305,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
|
|
|
)
|
|
|
|
|
@@ -329,14 +345,15 @@ dbdump () {
|
|
|
local db_name cmd_prog cmd_args pg_args
|
|
|
|
|
|
db_name="${1}"
|
|
|
- pg_args="${PG_OPTIONS[*]}"
|
|
|
|
|
|
if [ "${db_name}" = "${GLOBALS_OBJECTS}" ]; then
|
|
|
cmd_prog="pg_dumpall"
|
|
|
cmd_args=(--globals-only)
|
|
|
+ pg_args="${PGDUMPALL_ARGS[*]}"
|
|
|
else
|
|
|
cmd_prog="pg_dump"
|
|
|
cmd_args=("${db_name}")
|
|
|
+ pg_args="${PGDUMP_ARGS[*]}"
|
|
|
if [ "${CREATE_DATABASE}" = "yes" ]; then
|
|
|
pg_args+=(--create)
|
|
|
fi
|
|
@@ -351,9 +368,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
|
|
|
}
|
|
|
# }}}
|
|
@@ -425,8 +444,11 @@ dump() {
|
|
|
if [ -f "${dump_file}" ]; then
|
|
|
log_debug "Fixing permissions (${PERM}) on '${dump_file}'"
|
|
|
chmod "${PERM}" "${dump_file}"
|
|
|
+ fsize=$(stat -c '%s' "${dump_file}")
|
|
|
if [ ! -s "${dump_file}" ]; then
|
|
|
- log_error "Something went wrong '${dump_file}' is empty (no space left on device?)"
|
|
|
+ log_error "Something went wrong '${dump_file}' is empty"
|
|
|
+ elif [ "${fsize}" -lt "${MIN_DUMP_SIZE}" ]; then
|
|
|
+ log_warn "'${dump_file}' (${fsize} bytes) is below the minimum required size (${MIN_DUMP_SIZE} bytes)"
|
|
|
fi
|
|
|
else
|
|
|
log_error "Something went wrong '${dump_file}' does not exists (error during dump?)"
|