Sfoglia il codice sorgente

feat: Support DBDEFAULT to override PostgreSQL default database (Closes #51)

Emmanuel Bouthenot 6 ore fa
parent
commit
88b9fcf078
2 ha cambiato i file con 19 aggiunte e 0 eliminazioni
  1. 9 0
      Documentation.md
  2. 10 0
      autopostgresqlbackup

+ 9 - 0
Documentation.md

@@ -148,6 +148,15 @@ While using PostgreSQL database engine, it is also used if `DBHOST` is
 
 **default**: `""` (empty, the port to use is automatically defined depending on `DBENGINE`: `5432` for PostgreSQL and `3306` for MySQL)
 
+### DBDEFAULT
+
+Default database to connect to (psql defaults to `postgres`). Override it only
+if the default `postgres` database does not exists.
+
+**default** : `""` (empty)
+
+*Only while using PostgreSQL database engine*
+
 ### DBNAMES
 
 Explicit list of database(s) names(s) to backup

+ 10 - 0
autopostgresqlbackup

@@ -63,6 +63,9 @@ DBHOST="localhost"
 # Port of Database server.
 DBPORT=""
 
+# Default database to connect to
+DBDEFAULT=""
+
 # List of database(s) names(s) to backup.
 DBNAMES="all"
 
@@ -325,6 +328,10 @@ postgresqldb_list () {
         cmd_args+=("${CONN_ARGS[@]}")
     fi
 
+    if [ -n "${DBDEFAULT}" ] ; then
+	    cmd_args+=(-d "${DBDEFAULT}")
+    fi
+
     log_debug "Running command: ${cmd_prog} ${cmd_args[*]}"
     raw_dblist=$(
         if [ -n "${SU_USERNAME}" ]; then
@@ -387,6 +394,9 @@ postgresqldb_dump () {
         cmd_prog="${PGDUMPALL}"
         cmd_args=(--globals-only)
         pg_args=("${PGDUMPALL_ARGS[@]}")
+        if [ -n "${DBDEFAULT}" ] ; then
+            pg_args+=(-l "${DBDEFAULT}")
+        fi
     else
         cmd_prog="${PGDUMP}"
         if [ -n "${SU_USERNAME}" ]; then