2
0

Ubuntu 24.04 LTS conformance mods

* docker-compose-v2 compatibility
* MySQL/MariaDB dual comaptibility
ACME client minor upgrade
This commit is contained in:
2024-08-24 19:46:03 +02:00
parent 47211a6ea8
commit 005d0503e2
7 changed files with 612 additions and 431 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
#! /bin/bash
#
# Dumps a MySQL database from a native or dockerized MySQL instance running
# on this box. This is a wrapper script to the mysqldump tool.
# Dumps a MySQL or MariaDB database from a native or dockerized instance running
# on this box. This is a wrapper script to the mysqldump or mariadb-dump tool.
#
# If the MySQL is dockerized you need call as a Docker manager user
# If the DB engine is dockerized you need call as a Docker manager user
# (member of the docker Linux group).
#
# Accepts few mysql_dump options as well as the optional database password
# Accepts few mysql/mariadb-dump options as well as the optional database password
# and the optional output pathname:
#
# $0 [-u dbuser] [-p dbpass] [-h dbhost] [-P dbport]
@ -16,6 +16,9 @@
# Author: Kovács Zoltán <kovacs.zoltan@smartfront.hu>
# Kovács Zoltán <kovacsz@marcusconsulting.hu>
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
# 2024-08-24 v1.1
# mod: MariaDB and MySQL dual compatibility (native and dockerized).
# Tested with Ubuntu 24.04 LTS.
# 2023-06-18 v1.0
# new: forked from the "SMARTERP_skeleton" repository.
# 2023-02-15 v0.3
@ -47,7 +50,7 @@ MYOPTIONS=""
# Other initialisations.
#
MYDUMPFORCED="" # Dumps despite failed checks
# Our default parameters for the mysqldump.
# Our default parameters for the mysql/mariadb-dump
# Content of the MYOPTIONS will also appended during the actual dump.
dumpparameters="--comments --events --routines --triggers "
dumpparameters+="--complete-insert --dump-date --force --no-create-db "
@ -127,10 +130,16 @@ done; shift $((OPTIND -1))
# Checks the dependencies.
#
# Conditional dependencies (according to native or dockerized environment).
[[ -z "$MYCONTAINER" ]] \
&& additem="mysql mysqldump" \
|| additem="docker"
# Conditional dependencies.
if [ -n "$MYCONTAINER" ]; then
# Dockerized
additem="docker"
else
# Native - MySQL or MariaDB CLI?
if [ -n "$(which mysql)" ]
then additem="mysql mysqldump"
else additem="mariadb mariadb-dump"; fi
fi
# Common dependencies.
TR=$(which tr 2>/dev/null)
if [ -z "$TR" ]; then echo "$MSG_MISSINGDEP tr."; exit 1 ; fi
@ -142,6 +151,12 @@ do
done
# All dependencies are available via "$THECOMMAND" (upper case) call.
#
# Unifies the call of the clients in a native environment.
if [ -z "$MYCONTAINER" ]; then
if [ -z "$MYSQL" -a -n "$MARIADB" ]; then MYSQL="$MARIADB"; fi
if [ -z "$MYSQLDUMP" -a -n "$MARIADB_DUMP" ]; then MYSQLDUMP="$MARIADB_DUMP"; fi
fi
#
# An additional bugfix (use "$(which gzip)" instead of "$GZIP"):
# https://www.gnu.org/software/gzip/manual/html_node/Environment.html
GZIP=""
@ -205,10 +220,20 @@ my_connect=""
# Checks credentials and existence of the database given.
#
[[ -n "$MYCONTAINER" ]] \
&& databases=$("$DOCKER" exec $MYCONTAINER sh -c "mysql -N --batch $my_connect --execute='show databases;'" 2>/dev/null) \
|| databases=$("$MYSQL" -N --batch $my_connect --execute='show databases;' 2>/dev/null )
# Credentials?
if [ -z "$MYCONTAINER" ]; then
databases=$("$MYSQL" -N --batch $my_connect --execute='show databases;' 2>/dev/null )
else
# In a containerized environment we've to find out which CLIs are inside.
# Try the mysql first:
MYSQL="mysql"; MYSQLDUMP="mysqldump"
databases=$("$DOCKER" exec $MYCONTAINER sh -c "$MYSQL -N --batch $my_connect --execute='show databases;'" 2>/dev/null)
# On failure try the mariadb:
if [ -z "$databases" ]; then
MYSQL="mariadb"; MYSQLDUMP="mariadb-dump"
databases=$("$DOCKER" exec $MYCONTAINER sh -c "$MYSQL -N --batch $my_connect --execute='show databases;'" 2>/dev/null)
fi
fi
# CLI and Credentials are OK?
[[ -z "$databases" ]] \
&& echo "$MSG_BADCRED ($MYUSER@$([[ -n "$MYCONTAINER" ]] && echo "$MYCONTAINER:")$MYHOST)." >&2 && exit 1
# Existence?
@ -228,7 +253,7 @@ if [ -n "$MYDUMP" ]; then
SQLVERB+="GROUP BY table_schema;"
if [ -n "$MYCONTAINER" ]; then
# Dockerized database.
dbsize=$("$DOCKER" exec $MYCONTAINER sh -c "echo \"$SQLVERB\" | mysql -N --batch $my_connect" 2>/dev/null | \
dbsize=$("$DOCKER" exec $MYCONTAINER sh -c "echo \"$SQLVERB\" | "$MYSQL" -N --batch $my_connect" 2>/dev/null | \
"$CUT" -d$'\t' -f2)
else
# Self-hosted database.
@ -281,7 +306,7 @@ if [ -n "$MYDUMP" ]; then
# Dumps into a file (then optionally compresses). Writes a separate log too.
# TODO: pipelined compress - doesn't work with Docker yet(?).
[[ -n "$MYCONTAINER" ]] \
&& "$DOCKER" exec $MYCONTAINER sh -c "mysqldump $my_connect $dumpparameters $MYOPTIONS $MYDATABASE" \
&& "$DOCKER" exec $MYCONTAINER sh -c "$MYSQLDUMP $my_connect $dumpparameters $MYOPTIONS $MYDATABASE" \
>"$MYDUMP" 2>>"$logfile" \
|| "$MYSQLDUMP" $my_connect $dumpparameters $MYOPTIONS $MYDATABASE \
>"$MYDUMP" 2>>"$logfile"
@ -290,7 +315,7 @@ if [ -n "$MYDUMP" ]; then
else
# Dumps to STDOUT without logging.
[[ -n "$MYCONTAINER" ]] \
&& "$DOCKER" exec $MYCONTAINER sh -c "mysqldump $my_connect $dumpparameters $MYOPTIONS $MYDATABASE" \
&& "$DOCKER" exec $MYCONTAINER sh -c "$MYSQLDUMP $my_connect $dumpparameters $MYOPTIONS $MYDATABASE" \
2>/dev/null \
|| "$MYSQLDUMP" $my_connect $dumpparameters $MYOPTIONS $MYDATABASE \
2>>/dev/null