瀏覽代碼

fix: add backward compatibility for pd_dump <= 15 (specify output format method compression is not supported)

Emmanuel Bouthenot 1 周之前
父節點
當前提交
c73cf40f50
共有 2 個文件被更改,包括 21 次插入5 次删除
  1. 3 1
      Documentation.md
  2. 18 4
      autopostgresqlbackup

+ 3 - 1
Documentation.md

@@ -296,7 +296,9 @@ Output format:
 
 Compression method to use when `PGDUMP_FORMAT` is `custom` or `directory`. Supported values are `gzip`, `lz4`, `zstd`, and `none`.
 
-**default**: `gzip`
+Ignored with `pg_dump` ≤ 15 (not supported). Falling back to the built-in compression method (e.g. gzip).
+
+**default**: `gzip` (built-in)
 
 *Only while using PostgreSQL database engine*
 

+ 18 - 4
autopostgresqlbackup

@@ -165,6 +165,9 @@ GPG_HOMEDIR=
 # Database connection arguments
 CONN_ARGS=()
 
+# pg_dump major version
+PGDUMP_VERSION_MAJOR=
+
 # Hostname
 HOSTNAME="$(uname -n)"
 if [[ "${HOSTNAME}" != *.* ]]; then
@@ -323,6 +326,9 @@ postgresqldb_init () {
     if [ -z "${PGDUMPALL}" ]; then
         PGDUMPALL="pg_dumpall"
     fi
+
+    PGDUMP_VERSION_MAJOR=$("${PGDUMP}" --version 2>/dev/null | cut -d' ' -f3 | cut -d'.' -f1 || true)
+
     case "${PGDUMP_FORMAT}" in
         tar)
             EXT="tar"
@@ -434,10 +440,18 @@ postgresqldb_dump () {
             else
                 PGDUMP_ARGS+=(-Fc)
             fi
-        
-            FORMAT_COMP="${PGDUMP_FORMAT_COMP}"
-            if [ -n "${PGDUMP_FORMAT_COMP_LEVEL}" ] ; then
-                FORMAT_COMP+=":${PGDUMP_FORMAT_COMP_LEVEL}"
+
+            if [ -n "${PGDUMP_VERSION_MAJOR}" ] && [ "${PGDUMP_VERSION_MAJOR}" -gt 15 ]; then
+                log_info "VERS=${PGDUMP_VERSION_MAJOR}"
+                FORMAT_COMP="${PGDUMP_FORMAT_COMP}"
+                if [ -n "${PGDUMP_FORMAT_COMP_LEVEL}" ] ; then
+                    FORMAT_COMP+=":${PGDUMP_FORMAT_COMP_LEVEL}"
+                fi
+            else
+                log_debug "Falling back to built-in compression (e.g. gzip) for pg_dump <= 15"
+                if [ -n "${PGDUMP_FORMAT_COMP_LEVEL}" ] ; then
+                    FORMAT_COMP="${PGDUMP_FORMAT_COMP_LEVEL}"
+                fi
             fi
             if [ -n "${FORMAT_COMP}" ]; then
                 PGDUMP_ARGS+=(--compress "${FORMAT_COMP}")