Forráskód Böngészése

feat: Default configuration file /etc/default/autopostgresqlbackup is now deprecated in favor of /etc/autodbbackup.d

Emmanuel Bouthenot 10 hónapja
szülő
commit
6b870d49ca
6 módosított fájl, 28 hozzáadás és 6 törlés
  1. 1 0
      Changelog.md
  2. 5 1
      Documentation.md
  3. 19 2
      autopostgresqlbackup
  4. 1 1
      examples/mariadb.conf
  5. 1 1
      examples/mysql.conf
  6. 1 1
      examples/postgresql.conf

+ 1 - 0
Changelog.md

@@ -2,6 +2,7 @@
 
 ## Version 2.1
 
+* Default configuration file /etc/default/autopostgresqlbackup is now deprecated in favor of /etc/autodbbackup.d
 * Add support for MySQL/MariaDB (using the `DBENGINE` configuration parameter).
 * Add a command line option `-c` to specify an alternate config file or directory (see [Documentation](/Documentation.md)).
 * Add manpage

+ 5 - 1
Documentation.md

@@ -24,7 +24,7 @@ by now).
 
 `-d` Run in debug mode (no mail sent)
 
-`-c` Configuration file or directory (default: `/etc/default/autopostgresqlbackup`)
+`-c` Configuration file or directory (default: `/etc/autodbbackup.d/`)
 
   When a directory is used, the `*.conf` files will be processed sequentially.
   It allows one to backup multiple databases servers with distinct settings :
@@ -32,6 +32,10 @@ by now).
    - database servers with distinct engines
    - PostgreSQL cluster with instances running on multiple ports
 
+  Note: if no configuration file or directory is passed as argument but
+  `/etc/default/autopostgresqlbackup` exists, it will be used for backward
+  compatibility.
+
 ## ENCRYPTION
 
 Encryption (asymmetric) is now done with GnuPG, you just need to add the public

+ 19 - 2
autopostgresqlbackup

@@ -34,7 +34,10 @@ DNOM="$(date '+%d')"                # Date of the Month e.g. 27
 # {{{ Variables
 
 # Configuration file or directory
-CONFIG="/etc/default/autopostgresqlbackup"
+CONFIG="/etc/autodbbackup.d"
+
+# Legacy configuration file path (for backward compatibility)
+CONFIG_COMPAT="/etc/default/autopostgresqlbackup"
 
 # Email Address to send errors to. If empty errors are displayed on stdout.
 MAILADDR="root"
@@ -734,6 +737,9 @@ Options:
     -h  Shows this help
     -d  Run in debug mode (no mail sent)
     -c  Configuration file or directory (default: ${CONFIG})
+        Note: if ${CONFIG} file or directory does not exists
+        but ${CONFIG_COMPAT} exists, it will be used
+        for backward compatibility.
 EOH
 }
 # }}}
@@ -750,6 +756,7 @@ while getopts "hdc:" OPTION ; do
             ;;
         c)
             CONFIG="${OPTARG}"
+            CONFIG_COMPAT=
             ;;
         *)
             printf "Try \`%s -h\` to check the command line arguments\n" "${NAME}" >&2
@@ -767,7 +774,17 @@ setup
 # }}}
 
 # {{{ Config file loading
+CONFIG_N=0
 if [ -d "${CONFIG}" ]; then
+    CONFIG_N=$(find "${CONFIG}" -type f -iname '*.conf' | wc -l)
+fi
+
+if [ -f "${CONFIG_COMPAT}" ]; then
+    log_debug "Loading config '${CONFIG}' (for backward compatibility)"
+    # shellcheck source=/dev/null
+    . "${CONFIG_COMPAT}"
+    setup
+elif [ "${CONFIG_N}" -gt 0 ]; then
     CMD="$(readlink -f "${0}")"
     CMD_ARGS=()
 
@@ -787,7 +804,7 @@ elif [ -f "${CONFIG}" ]; then
     . "${CONFIG}"
     setup
 else
-    log_error "${NAME}: config file or directory '${CONFIG}' not found"
+    log_error "${NAME}: config file or directory '${CONFIG}' does not exists or directory '${CONFIG}' does not contains any configuration files."
     cleanup_io
     cleanup
     exit 1

+ 1 - 1
examples/mariadb.conf

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

+ 1 - 1
examples/mysql.conf

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

+ 1 - 1
examples/postgresql.conf

@@ -6,7 +6,7 @@ DBENGINE="postgresql"
 SU_USERNAME="postgres"
 
 # Backup directory
-BACKUPDIR="/var/lib/autodbbackup/${DBENGINE}"
+BACKUPDIR="/var/backups/autodbbackup/${DBENGINE}"
 
 # Include CREATE DATABASE in backups?
 CREATE_DATABASE="no"