From 6bad6d8d654d864d5735ecb072cc66a85774ff2c Mon Sep 17 00:00:00 2001 From: Alwyn Pan Date: Mon, 30 Oct 2023 12:45:49 +1100 Subject: [PATCH] fix: #262 Add option for DB_AUTH in PGSQL --- README.md | 4 ++-- install/assets/functions/10-db-backup | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 81bf7e7..5e408f1 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ Be sure to view the following repositories to understand all the customizable op | Parameter | Description | Default | `_FILE` | | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------- | -| `DB_AUTH` | (Mongo Only - Optional) Authentication Database | | | +| `DB_AUTH` | (Mongo/PGSQL Only - Optional) Authentication Database | | | | `DB_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `mssql` `pgsql` `mongo` `redis` `sqlite3` | | | | `DB_HOST` | Server Hostname e.g. `mariadb`. For `sqlite3`, full path to DB file e.g. `/backup/db.sqlite3` | | x | | `DB_NAME` | Schema Name e.g. `database` or `ALL` to backup all databases the user has access to. Backup multiple by separating with commas eg `db1,db2` | | x | @@ -205,7 +205,7 @@ Your Organization will be mapped to `DB_USER` and your root token will need to b | `MYSQL_SINGLE_TRANSACTION` | Backup in a single transaction with MySQL / MariaDB | `TRUE` | | | `MYSQL_STORED_PROCEDURES` | Backup stored procedures with MySQL / MariaDB | `TRUE` | | | `MYSQL_ENABLE_TLS` | Enable TLS functionality for MySQL client | `FALSE` | | -| `MYSQL_TLS_VERIFY` | (optional) If using TLS (by means of MYSQL*TLS*\* variables) verify remote host | `FALSE` | | +| `MYSQL_TLS_VERIFY` | (optional) If using TLS (by means of MYSQL_TLS_* variables) verify remote host | `FALSE` | | | `MYSQL_TLS_VERSION` | What TLS `v1.1` `v1.2` `v1.3` version to utilize | `TLSv1.1,TLSv1.2,TLSv1.3` | | | `MYSQL_TLS_CA_FILE` | Filename to load custom CA certificate for connecting via TLS | `/etc/ssl/cert.pem` | x | | `MYSQL_TLS_CERT_FILE` | Filename to load client certificate for connecting via TLS | | x | diff --git a/install/assets/functions/10-db-backup b/install/assets/functions/10-db-backup index 47892e8..afd0af8 100644 --- a/install/assets/functions/10-db-backup +++ b/install/assets/functions/10-db-backup @@ -298,8 +298,12 @@ backup_mysql() { } backup_pgsql() { - export PGPASSWORD=${DB_PASS} - authdb=${DB_USER} + export PGPASSWORD=${DB_PASS} + if [ -n "${DB_AUTH}" ] ; then + authdb=${DB_AUTH} + else + authdb=${DB_USER} + fi if [ "${DB_NAME,,}" = "all" ] ; then print_debug "Preparing to back up all databases" db_names=$(psql -h ${DB_HOST} -U ${DB_USER} -p ${DB_PORT} -d ${authdb} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' ) @@ -341,7 +345,7 @@ backup_pgsql() { pre_dbbackup all print_notice "Dumping all PostgreSQL databases: '$(echo ${db_names} | xargs | tr ' ' ',')' ${compression_string}" tmp_db_names=$(psql -h ${DB_HOST} -U ${DB_USER} -p ${DB_PORT} -d ${authdb} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' ) - for r_db_name in $(echo $db_names | xargs); do + for r_db_name in $(echo $db_names | xargs); do tmp_db_names=$(echo "$tmp_db_names" | xargs | sed "s|${r_db_name}||g" ) done sleep 5