add: backup scripts and docker image

This commit is contained in:
2024-10-17 19:38:31 -03:00
parent 3a2d6f32f0
commit 604a514632
7 changed files with 200 additions and 0 deletions

40
scripts/dburl-parser.sh Executable file
View File

@@ -0,0 +1,40 @@
#! /bin/sh
#
# Parses a database URL in the format schema://user:
#
DB_URL="$1";
SCHEMA="${DB_URL%//*}";
SCHEMALESS_URL=${DB_URL#*//};
LEFT_HAND=${SCHEMALESS_URL%@*};
if test ! ${LEFT_HAND} = ${SCHEMALESS_URL}; then
USERNAME=$(echo ${LEFT_HAND} | cut -d ':' -f 1);
if test ! ${USERNAME} = ${LEFT_HAND}; then
PASSWORD=$(echo ${LEFT_HAND} | cut -d ':' -f 2);
fi
fi
RIGHT_HAND=${SCHEMALESS_URL#*@};
HOST=$(echo ${RIGHT_HAND} | cut -d ':' -f 1 | cut -d '/' -f 1);
if test -n "$(echo ${RIGHT_HAND} | grep -o ':')"; then
PORT=$(echo ${RIGHT_HAND} | cut -d ':' -f 2 | cut -d '/' -f 1);
fi
if test -n "$(echo ${RIGHT_HAND} | grep -o '/')"; then
DATABASE=$(echo ${RIGHT_HAND} | cut -d ':' -f 2 | cut -d '/' -f 2);
fi
# throw an error if DB_URL does not contains at least a HOST
if test -z "${HOST}"; then
echo "database URL providen was invalid" && exit 1;
fi
cat << HEREDOC
DB_SCHEMA=${SCHEMA%:}
DB_USERNAME=${USERNAME}
DB_PASSWORD=${PASSWORD}
DB_HOST=${HOST}
DB_PORT=${PORT}
DB_NAME=${DATABASE}
HEREDOC