Skip to content

Commit 6bad6d8

Browse files
committed
fix: #262 Add option for DB_AUTH in PGSQL
1 parent a922922 commit 6bad6d8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Be sure to view the following repositories to understand all the customizable op
156156

157157
| Parameter | Description | Default | `_FILE` |
158158
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------- |
159-
| `DB_AUTH` | (Mongo Only - Optional) Authentication Database | | |
159+
| `DB_AUTH` | (Mongo/PGSQL Only - Optional) Authentication Database | | |
160160
| `DB_TYPE` | Type of DB Server to backup `couch` `influx` `mysql` `mssql` `pgsql` `mongo` `redis` `sqlite3` | | |
161161
| `DB_HOST` | Server Hostname e.g. `mariadb`. For `sqlite3`, full path to DB file e.g. `/backup/db.sqlite3` | | x |
162162
| `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
205205
| `MYSQL_SINGLE_TRANSACTION` | Backup in a single transaction with MySQL / MariaDB | `TRUE` | |
206206
| `MYSQL_STORED_PROCEDURES` | Backup stored procedures with MySQL / MariaDB | `TRUE` | |
207207
| `MYSQL_ENABLE_TLS` | Enable TLS functionality for MySQL client | `FALSE` | |
208-
| `MYSQL_TLS_VERIFY` | (optional) If using TLS (by means of MYSQL*TLS*\* variables) verify remote host | `FALSE` | |
208+
| `MYSQL_TLS_VERIFY` | (optional) If using TLS (by means of MYSQL_TLS_* variables) verify remote host | `FALSE` | |
209209
| `MYSQL_TLS_VERSION` | What TLS `v1.1` `v1.2` `v1.3` version to utilize | `TLSv1.1,TLSv1.2,TLSv1.3` | |
210210
| `MYSQL_TLS_CA_FILE` | Filename to load custom CA certificate for connecting via TLS | `/etc/ssl/cert.pem` | x |
211211
| `MYSQL_TLS_CERT_FILE` | Filename to load client certificate for connecting via TLS | | x |

install/assets/functions/10-db-backup

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,12 @@ backup_mysql() {
298298
}
299299

300300
backup_pgsql() {
301-
export PGPASSWORD=${DB_PASS}
302-
authdb=${DB_USER}
301+
export PGPASSWORD=${DB_PASS}
302+
if [ -n "${DB_AUTH}" ] ; then
303+
authdb=${DB_AUTH}
304+
else
305+
authdb=${DB_USER}
306+
fi
303307
if [ "${DB_NAME,,}" = "all" ] ; then
304308
print_debug "Preparing to back up all databases"
305309
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() {
341345
pre_dbbackup all
342346
print_notice "Dumping all PostgreSQL databases: '$(echo ${db_names} | xargs | tr ' ' ',')' ${compression_string}"
343347
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;' )
344-
for r_db_name in $(echo $db_names | xargs); do
348+
for r_db_name in $(echo $db_names | xargs); do
345349
tmp_db_names=$(echo "$tmp_db_names" | xargs | sed "s|${r_db_name}||g" )
346350
done
347351
sleep 5

0 commit comments

Comments
 (0)