4 Komitmen 8db37ef237 ... 3f78894e0b

Pembuat SHA1 Pesan Tanggal
  Emmanuel Bouthenot 3f78894e0b chore(doc): Improve examples 6 jam lalu
  Emmanuel Bouthenot ff352ec533 fix: fix linter issues 6 jam lalu
  Emmanuel Bouthenot f5abc90d7d chore(doc): Update changelog 6 jam lalu
  Emmanuel Bouthenot 88b9fcf078 feat: Support DBDEFAULT to override PostgreSQL default database (Closes #51) 6 jam lalu
4 mengubah file dengan 29 tambahan dan 3 penghapusan
  1. 4 0
      Changelog.md
  2. 9 0
      Documentation.md
  3. 15 2
      autopostgresqlbackup
  4. 1 1
      examples/mariadb.conf

+ 4 - 0
Changelog.md

@@ -1,5 +1,9 @@
 # Changelog
 
+## Version 2.7
+
+* Add a `DBDEFAULT` configuration variable (currently PostgreSQL only) to override the default database (postgres) used when connecting to the server (Closes: [#51](https://github.com/k0lter/autopostgresqlbackup/pull/51)
+
 ## Version 2.6
 
 * Fix the day and month comparison so that it is always done using two digits (Closes: [#48](https://github.com/k0lter/autopostgresqlbackup/pull/48)

+ 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

+ 15 - 2
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
@@ -563,8 +573,11 @@ db_list () {
 # {{{ db_dump()
 db_dump () {
     case ${DBENGINE} in
-        postgresql|mysql)
-            ${DBENGINE}db_dump "${1}"
+        postgresql)
+            postgresqldb_dump "${1}"
+            ;;
+        mysql)
+            mysqldb_dump "${1}"
             ;;
         *)
             log_error "Unsupported database engine ${DBENGINE}, check DBENGINE configuration parameter"

+ 1 - 1
examples/mariadb.conf

@@ -3,7 +3,7 @@
 DBENGINE="mysql"
 
 # Backup directory
-BACKUPDIR="/var/backups/autodbbackup/mariadb"
+BACKUPDIR="/var/backups/autodbbackup/${DBENGINE}"
 
 # Include CREATE DATABASE in backups?
 CREATE_DATABASE="no"