35 lines
903 B
Bash
35 lines
903 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
if [ "$(id -u)" != "0" ]; then
|
||
|
echo -e "\033[31mThis script requires superuser rights\033[0m"
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
SECRETS_PATH=/data/secrets/$SERVER_DOMAIN/$SERVER_DOMAIN.env
|
||
|
|
||
|
trap 'echo -e "\033[31mmariadb-all: Something went wrong\033[0m"; exit 1' ERR
|
||
|
set -e
|
||
|
|
||
|
export DEBIAN_FRONTEND=noninteractive
|
||
|
|
||
|
source $SECRETS_PATH
|
||
|
|
||
|
if [ -z "$MARIADB_ROOT_PASSWORD" ]; then
|
||
|
echo "Error: MARIADB_ROOT_PASSWORD is not set or is empty"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
DOCKER_SERVICE_NAME=mariadb
|
||
|
MYSQL_USER=root
|
||
|
MYSQL_DATABASE=mysql
|
||
|
|
||
|
docker exec -i $DOCKER_SERVICE_NAME mariadb -u$MYSQL_USER -p$MARIADB_ROOT_PASSWORD $MYSQL_DATABASE -N -e "
|
||
|
SELECT s.SCHEMA_NAME
|
||
|
FROM information_schema.SCHEMATA s
|
||
|
WHERE SCHEMA_NAME NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys');
|
||
|
" | while IFS= read -r dbname; do
|
||
|
bash mariadb.sh $dbname
|
||
|
done
|
||
|
|
||
|
trap - ERR
|
||
|
echo "All mariadb databases backuped successfully"
|