Added database container
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
# ****************************************************************************************************
|
||||
# * ______ _ _ *
|
||||
# * | ____| /\ (_) | | *
|
||||
# * | |__ _ _ _ __ ___ _ __ ___ __ _ _ __ / \ _ _ __ _ __ ___ _ __| |_ ___ *
|
||||
# * | __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \ / /\ \ | | '__| '_ \ / _ \| '__| __/ __| *
|
||||
# * | |___| |_| | | | (_) | |_) | __/ (_| | | | | / ____ \| | | | |_) | (_) | | | |_\__ \ *
|
||||
# * |______\__,_|_| \___/| .__/ \___|\__,_|_| |_| /_/ \_\_|_| | .__/ \___/|_| \__|___/ *
|
||||
# * | | | | *
|
||||
# * |_| |_| *
|
||||
# * *
|
||||
# ****************************************************************************************************
|
||||
|
||||
# This file is part of the European Airports Project, a free, collaborative platform of airport data
|
||||
# extending beyond the official AIPs.
|
||||
|
||||
# Copyright (C) 2023
|
||||
|
||||
# Florian Meissner <florianmeissner@gmx.de>
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software Foundation, either
|
||||
# version 3 of the License, or (at your option) any later version. This program is distributed in the
|
||||
# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details. You should have received a copy of the GNU General Public License along with this program.
|
||||
# (license.md in the root folder of this project) If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
# *************************************************
|
||||
# * ___ _ *
|
||||
# * / (_) | | *
|
||||
# * | ,_ __ _ _ _|_ __, | | *
|
||||
# * | / | / \_/ |/ | | / | |/ \_ *
|
||||
# * \___/ |_/\__/ | |_/|_/\_/|_/\_/ *
|
||||
# * *
|
||||
# *************************************************
|
||||
|
||||
# This is the crontab file for user root. It will be loaded and installed during the build process
|
||||
# of the Docker image.
|
||||
|
||||
# In order for CheckMk to monitor the jobs, the sytax is enhenced a little bit. After the time
|
||||
# information the script `mk-job` is placed with a CHeckMk description of the Job as first argument.
|
||||
# The actual job's script or command is then followd as the second argument. For further
|
||||
# informations see `mk-job` in the `checkmk` folder.
|
||||
|
||||
# Remember that this file must end with a new line!
|
||||
|
||||
# How to install a cronjob in Docker:
|
||||
# https://github.com/edwardsamuel/Docker-Cron-Job-Sample/blob/master/README.md
|
||||
|
||||
# Florian Meissner, DL1MRV
|
||||
|
||||
# m h dom mon dow `mk-job` desc command [args]
|
||||
#* * * * * mkjob "Test-Job" echo "Hello world" `date` >> /var/log/cron.log 2>&1
|
||||
0 */4 * * * mk-job "DB Dump" /dbDump.sh
|
||||
15 */4 * * * mk-job "Borg Backup" /borg.sh
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ****************************************************************************************************
|
||||
# * ______ _ _ *
|
||||
# * | ____| /\ (_) | | *
|
||||
# * | |__ _ _ _ __ ___ _ __ ___ __ _ _ __ / \ _ _ __ _ __ ___ _ __| |_ ___ *
|
||||
# * | __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \ / /\ \ | | '__| '_ \ / _ \| '__| __/ __| *
|
||||
# * | |___| |_| | | | (_) | |_) | __/ (_| | | | | / ____ \| | | | |_) | (_) | | | |_\__ \ *
|
||||
# * |______\__,_|_| \___/| .__/ \___|\__,_|_| |_| /_/ \_\_|_| | .__/ \___/|_| \__|___/ *
|
||||
# * | | | | *
|
||||
# * |_| |_| *
|
||||
# * *
|
||||
# ****************************************************************************************************
|
||||
|
||||
# This file is part of the European Airports Project, a free, collaborative platform of airport data
|
||||
# extending beyond the official AIPs.
|
||||
|
||||
# Copyright (C) 2023
|
||||
|
||||
# Florian Meissner <florianmeissner@gmx.de>
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software Foundation, either
|
||||
# version 3 of the License, or (at your option) any later version. This program is distributed in the
|
||||
# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details. You should have received a copy of the GNU General Public License along with this program.
|
||||
# (license.md in the root folder of this project) If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
# ****************************************************************************************
|
||||
# * ,__ __ ____ , __ ____ *
|
||||
# * /| | | o (| \/|/ \ (| \ *
|
||||
# * | | | __, ,_ __, | || __/ | | _ _ _ _ *
|
||||
# * | | | / | / | | / | _| || \ _| || | / |/ |/ | |/ \_ *
|
||||
# * | | |_/\_/|_/ |_/|_/\_/|_/(/\___/ |(__/ (/\___/ \_/|_/ | | |_/|__/ *
|
||||
# * /| *
|
||||
# * \| *
|
||||
# ****************************************************************************************
|
||||
|
||||
# Dump database contents to be later backed up. The dump will not contain any DROP or CREATE
|
||||
# statements in order not to damage any existing data. This way `dbImport.sh` can use these files
|
||||
# and run them over an eventually existing DB during the Docker entryint script.
|
||||
|
||||
DUMP_DIR="/tmp/mariadb-dump"
|
||||
DB_USER=`cat /run/secrets/rootUser`
|
||||
DB_PW=`cat /run/secrets/rootPw`
|
||||
DB_NAMES=(
|
||||
#"example-db"
|
||||
"eaMain"
|
||||
)
|
||||
ERROR_LOG="/var/log/mysql/dump.log"
|
||||
|
||||
# Set excluded database tables here. Use an index for each database and separate tables by spaces.
|
||||
declare -A EXCLUDED_TABLES=(
|
||||
#[example-db]="table1 table2 table3"
|
||||
#[toplist]="cty"
|
||||
)
|
||||
|
||||
|
||||
###################################################################################################
|
||||
|
||||
|
||||
mkdir -p $DUMP_DIR
|
||||
|
||||
for db in ${DB_NAMES[@]}; do
|
||||
|
||||
# Assemble base command
|
||||
read -r -d '' cmd << EOF
|
||||
mariadb-dump
|
||||
--single-transaction
|
||||
--no-create-db
|
||||
--insert-ignore
|
||||
--user=$DB_USER
|
||||
--password=$DB_PW
|
||||
--databases $db
|
||||
--dump-date
|
||||
--log-error=$ERROR_LOG
|
||||
--skip-add-drop-table
|
||||
--skip-extended-insert
|
||||
--no-create-info
|
||||
EOF
|
||||
|
||||
# Append excluded tables
|
||||
for tbl in ${EXCLUDED_TABLES[$db]}; do
|
||||
cmd="${cmd} --ignore-table=${db}.${tbl}"
|
||||
done
|
||||
|
||||
$cmd > $DUMP_DIR/$db.sql
|
||||
done
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ****************************************************************************************************
|
||||
# * ______ _ _ *
|
||||
# * | ____| /\ (_) | | *
|
||||
# * | |__ _ _ _ __ ___ _ __ ___ __ _ _ __ / \ _ _ __ _ __ ___ _ __| |_ ___ *
|
||||
# * | __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \ / /\ \ | | '__| '_ \ / _ \| '__| __/ __| *
|
||||
# * | |___| |_| | | | (_) | |_) | __/ (_| | | | | / ____ \| | | | |_) | (_) | | | |_\__ \ *
|
||||
# * |______\__,_|_| \___/| .__/ \___|\__,_|_| |_| /_/ \_\_|_| | .__/ \___/|_| \__|___/ *
|
||||
# * | | | | *
|
||||
# * |_| |_| *
|
||||
# * *
|
||||
# ****************************************************************************************************
|
||||
|
||||
# This file is part of the European Airports Project, a free, collaborative platform of airport data
|
||||
# extending beyond the official AIPs.
|
||||
|
||||
# Copyright (C) 2023
|
||||
|
||||
# Florian Meissner <florianmeissner@gmx.de>
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software Foundation, either
|
||||
# version 3 of the License, or (at your option) any later version. This program is distributed in the
|
||||
# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details. You should have received a copy of the GNU General Public License along with this program.
|
||||
# (license.md in the root folder of this project) If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
# ********************************************************************************************
|
||||
# * ,__ __ ____ , __ _ *
|
||||
# * /| | | o (| \/|/ \ | | *
|
||||
# * | | | __, ,_ __, | || __/ | | _ _ _ _ __ ,_ _|_ *
|
||||
# * | | | / | / | | / | _| || \ _ |/ / |/ |/ | |/ \_/ \_/ | | *
|
||||
# * | | |_/\_/|_/ |_/|_/\_/|_/(/\___/ |(__/ \_/\/ | | |_/|__/ \__/ |_/|_/ *
|
||||
# * /| *
|
||||
# * \| *
|
||||
# ********************************************************************************************
|
||||
|
||||
# Import an existing dump back into the database. It is designed to used dump files created with
|
||||
# `dbDump.sh` and flush them over an existing DB. For that to work, `initDb.sh` should be run first
|
||||
# if no database exists.
|
||||
|
||||
|
||||
DUMP_DIR="/tmp/mariadb-dump"
|
||||
DB_USER=`cat /run/secrets/rootUser`
|
||||
DB_PW=`cat /run/secrets/rootPw`
|
||||
|
||||
for file in $DUMP_DIR/*.sql; do
|
||||
mariadb \
|
||||
--user=$DB_USER \
|
||||
--password=$DB_PW \
|
||||
< $file
|
||||
done
|
||||
Executable
+115
@@ -0,0 +1,115 @@
|
||||
# ****************************************************************************************************
|
||||
# * ______ _ _ *
|
||||
# * | ____| /\ (_) | | *
|
||||
# * | |__ _ _ _ __ ___ _ __ ___ __ _ _ __ / \ _ _ __ _ __ ___ _ __| |_ ___ *
|
||||
# * | __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \ / /\ \ | | '__| '_ \ / _ \| '__| __/ __| *
|
||||
# * | |___| |_| | | | (_) | |_) | __/ (_| | | | | / ____ \| | | | |_) | (_) | | | |_\__ \ *
|
||||
# * |______\__,_|_| \___/| .__/ \___|\__,_|_| |_| /_/ \_\_|_| | .__/ \___/|_| \__|___/ *
|
||||
# * | | | | *
|
||||
# * |_| |_| *
|
||||
# * *
|
||||
# ****************************************************************************************************
|
||||
|
||||
# This file is part of the European Airports Project, a free, collaborative platform of airport data
|
||||
# extending beyond the official AIPs.
|
||||
|
||||
# Copyright (C) 2023
|
||||
|
||||
# Florian Meissner <florianmeissner@gmx.de>
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software Foundation, either
|
||||
# version 3 of the License, or (at your option) any later version. This program is distributed in the
|
||||
# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details. You should have received a copy of the GNU General Public License along with this program.
|
||||
# (license.md in the root folder of this project) If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Initialize the database
|
||||
# =======================
|
||||
|
||||
# This script will process all *.sh, *.sql, *.sql.gz, *sql.xz and *.sql.zst found in in the init
|
||||
# directory recursively. They are processed in alphabetical order.
|
||||
|
||||
|
||||
# CONFIG
|
||||
LOG_FILE="/var/log/mysql/init.log"
|
||||
INIT_DIR="/docker-entrypoint-initdb.d"
|
||||
|
||||
|
||||
# Logging functions
|
||||
# Inspired by MariaDB's upstream docker-entrypoint.sh
|
||||
mysql_log() {
|
||||
local type="$1";
|
||||
shift
|
||||
printf '%s [%s] [Entrypoint]: %s\n' "$(date --rfc-3339=seconds)" "$type" "$*" &>> $LOG_FILE
|
||||
}
|
||||
mysql_note() {
|
||||
mysql_log Note "$@"
|
||||
}
|
||||
|
||||
mysql_warn() {
|
||||
mysql_log Warn "$@" >&2
|
||||
}
|
||||
|
||||
mysql_error() {
|
||||
mysql_log ERROR "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
docker_process_sql() {
|
||||
user=`cat /run/secrets/rootUser`
|
||||
pw=`cat /run/secrets/rootPw`
|
||||
|
||||
# echo "$user $pw"
|
||||
# echo "$@"
|
||||
mariadb \
|
||||
--user="${user}" \
|
||||
--password="${pw}" \
|
||||
"$@"
|
||||
}
|
||||
|
||||
|
||||
# check to see if this file is being run or sourced from another script
|
||||
_is_sourced() {
|
||||
# https://unix.stackexchange.com/a/215279
|
||||
local _top_of_stack=$(( ${#FUNCNAME[@]} - 1 ))
|
||||
|
||||
[ "${#FUNCNAME[@]}" -ge 2 ] \
|
||||
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
|
||||
&& [ "${FUNCNAME[${_top_of_stack}]}" = 'source' ]
|
||||
}
|
||||
|
||||
|
||||
# Main program start
|
||||
_main() {
|
||||
for f in $(find ${INIT_DIR} -name "*.sql*" -or -name "*.sh" | sort ); do
|
||||
case "$f" in
|
||||
*.sh)
|
||||
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
|
||||
# https://github.com/docker-library/postgres/pull/452
|
||||
if [ -x "$f" ]; then
|
||||
mysql_note "$0: running $f"
|
||||
"$f"
|
||||
else
|
||||
mysql_note "$0: sourcing $f"
|
||||
# ShellCheck can't follow non-constant source. Use a directive to specify location.
|
||||
# shellcheck disable=SC1090
|
||||
. "$f"
|
||||
fi
|
||||
;;
|
||||
*.sql) mysql_note "$0: running $f"; docker_process_sql < "$f"; echo ;;
|
||||
*.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;;
|
||||
*.sql.xz) mysql_note "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;;
|
||||
*.sql.zst) mysql_note "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;;
|
||||
*) mysql_warn "$0: ignoring $f" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
if ! _is_sourced
|
||||
then
|
||||
_main
|
||||
fi
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ****************************************************************************************************
|
||||
# * ______ _ _ *
|
||||
# * | ____| /\ (_) | | *
|
||||
# * | |__ _ _ _ __ ___ _ __ ___ __ _ _ __ / \ _ _ __ _ __ ___ _ __| |_ ___ *
|
||||
# * | __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \ / /\ \ | | '__| '_ \ / _ \| '__| __/ __| *
|
||||
# * | |___| |_| | | | (_) | |_) | __/ (_| | | | | / ____ \| | | | |_) | (_) | | | |_\__ \ *
|
||||
# * |______\__,_|_| \___/| .__/ \___|\__,_|_| |_| /_/ \_\_|_| | .__/ \___/|_| \__|___/ *
|
||||
# * | | | | *
|
||||
# * |_| |_| *
|
||||
# * *
|
||||
# ****************************************************************************************************
|
||||
|
||||
# This file is part of the European Airports Project, a free, collaborative platform of airport data
|
||||
# extending beyond the official AIPs.
|
||||
|
||||
# Copyright (C) 2023
|
||||
|
||||
# Florian Meissner <florianmeissner@gmx.de>
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software Foundation, either
|
||||
# version 3 of the License, or (at your option) any later version. This program is distributed in the
|
||||
# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details. You should have received a copy of the GNU General Public License along with this program.
|
||||
# (license.md in the root folder of this project) If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
# Update script for Ubuntu based OS's.
|
||||
# Florian Meissner, DL1MRV
|
||||
# 03/2023
|
||||
|
||||
apt -y -qq update
|
||||
echo "Hostname: ${HOSTNAME_HR}"
|
||||
apt list --upgradable
|
||||
read
|
||||
apt -y -qq upgrade
|
||||
apt -y -qq autoremove
|
||||
apt-get clean
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
Reference in New Issue
Block a user