Skip to content

Commit

Permalink
feat: allow overriding database executable and fail on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Oct 1, 2023
1 parent 5f4719f commit 435f7d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## v1.1.0 (2023-09-30)

- Adds `SRVINFRA_DATABASE_EXECUTABLE` as an env var which can be set to `mariadb` to override the default `mysql` allowing users to change the database executable used with srvinfra
- Sets `set -e` flag to ensure srvinfra fails on any error where previously it could fail silently

## v1.0.0 (2023-08-25)

- Now uses `-md sha512 -pbkdf2` flags for openssl commands when encrypting and decrypting databases to fix deprecation warning
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Once you have `srvinfra` installed, you'll need to setup an environment variable
echo 'export SRVINFRA_SERVICES_DIR=path/to/dir' >> ~/.zshrc
```

You can change the database executable used from `mysql` to `mariadb` by setting it via the `SRVINFRA_DATABASE_EXECUTABLE` env var:

```bash
echo 'export SRVINFRA_DATABASE_EXECUTABLE=mariadb' >> ~/.zshrc
```

## Usage

```bash
Expand Down
16 changes: 13 additions & 3 deletions src/srvinfra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

# srvinfra is a tool to deploy and update services on a server hosted by Docker

set -e

### Databases

SRVINFRA_DATABASE_EXECUTABLE=${SRVINFRA_DATABASE_EXECUTABLE:-"mysql"}

if [[ "$SRVINFRA_DATABASE_EXECUTABLE" == "mariadb" ]]; then
SRVINFRA_DATABASE_BACKUP_EXECUTABLE="mariadb-dump"
else
SRVINFRA_DATABASE_BACKUP_EXECUTABLE="mysqldump"
fi

decrypt_database_backup() {
# Parameters
# 1. sql file path
Expand All @@ -23,7 +33,7 @@ export_database() {
local sql_filename
sql_filename=${4:-"database.sql"}

docker exec -i "$1" mysqldump -uroot -p"$2" "$3" >"$sql_filename"
docker exec -i "$1" "$SRVINFRA_DATABASE_BACKUP_EXECUTABLE" -uroot -p"$2" "$3" >"$sql_filename"
}

export_database_secure() {
Expand All @@ -35,7 +45,7 @@ export_database_secure() {
local sql_filename
sql_filename=${4:-"database.enc.gz"}

docker exec -i "$1" mysqldump -uroot -p"$2" "$3" | gzip -c | openssl enc -aes-256-cbc -md sha512 -pbkdf2 -k "$2" >"$sql_filename"
docker exec -i "$1" "$SRVINFRA_DATABASE_BACKUP_EXECUTABLE" -uroot -p"$2" "$3" | gzip -c | openssl enc -aes-256-cbc -md sha512 -pbkdf2 -k "$2" >"$sql_filename"
}

import_database() {
Expand All @@ -45,7 +55,7 @@ import_database() {
# 3. database name
# 4. sql file path

docker exec -i "$1" mysql -uroot -p"$2" "$3" <"$4"
docker exec -i "$1" "$SRVINFRA_DATABASE_EXECUTABLE" -uroot -p"$2" "$3" <"$4"
}

import_encrypted_database() {
Expand Down

0 comments on commit 435f7d4

Please sign in to comment.