From ff61fd20191d4656245d4ac48aac03e73016f547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Pennewi=C3=9F?= Date: Thu, 19 Mar 2026 17:50:44 +0100 Subject: [PATCH] Use mariadb binaries when detecting mariadb instead of mysql --- README | 3 +++ README.md | 2 +- automysqlbackup | 40 ++++++++++++++++++++++++++++++++-------- automysqlbackup.conf | 6 ++++++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/README b/README index d4f5030..e8be477 100644 --- a/README +++ b/README @@ -141,6 +141,9 @@ CONFIG_do_weekly="5" CONFIG_rotation_daily=6 CONFIG_rotation_weekly=35 CONFIG_rotation_monthly=150 +CONFIG_mysql_bin='' +CONFIG_mysqldump_bin='' +CONFIG_mysqlshow_bin='' CONFIG_mysql_dump_usessl='yes' CONFIG_mysql_dump_username='root' CONFIG_mysql_dump_password='' diff --git a/README.md b/README.md index 51aa871..bf3e79c 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Adjustments ----------- You can find some original files from the sourceforge package. Some files are adjusted to my needs: -- support for MySQL 5.6 and MySQL 5.7 +- support for MySQL 5.6, MySQL 5.7 and MariaDB - support for login path (since MySQL 5.6.x a secure way to save your mysql credentials was implemented) - adjusted the use of --ssl because it became depreated in MySQL 5.7. The parameter --ssl-mode=REQUIRED is used instead. diff --git a/automysqlbackup b/automysqlbackup index 389ac5f..28cc313 100755 --- a/automysqlbackup +++ b/automysqlbackup @@ -75,6 +75,9 @@ load_default_config() { CONFIG_rotation_daily=6 CONFIG_rotation_weekly=35 CONFIG_rotation_monthly=150 + CONFIG_mysql_bin='' + CONFIG_mysqldump_bin='' + CONFIG_mysqlshow_bin='' CONFIG_mysql_dump_port=3306 CONFIG_mysql_dump_usessl='no' CONFIG_mysql_dump_username='root' @@ -118,19 +121,30 @@ load_default_config() { } mysql_commands() { - VERSION=`mysql -V | grep -oE "[0-9]+\.[0-9]+\.[0-9]+" | head -1` + # Detect MariaDB or use MySQL + if isMariaDB; then + [[ -z "${CONFIG_mysql_bin}" ]] && CONFIG_mysql_bin='mariadb' + [[ -z "${CONFIG_mysqldump_bin}" ]] && CONFIG_mysqldump_bin='mariadb-dump' + [[ -z "${CONFIG_mysqlshow_bin}" ]] && CONFIG_mysqlshow_bin='mariadb-show' + else + [[ -z "${CONFIG_mysql_bin}" ]] && CONFIG_mysql_bin='mysql' + [[ -z "${CONFIG_mysqldump_bin}" ]] && CONFIG_mysqldump_bin='mysqldump' + [[ -z "${CONFIG_mysqlshow_bin}" ]] && CONFIG_mysqlshow_bin='mysqlshow' + fi + + VERSION=`${CONFIG_mysql_bin} -V | grep -oE "[0-9]+\.[0-9]+\.[0-9]+" | head -1` NODOT_VER=`echo $VERSION | sed -${sed_Regex} 's/\.//g'` if [ "${CONFIG_mysql_dump_encrypted_login}" = "yes" ]; then - export MYSQLDUMP="mysqldump --login-path=$CONFIG_mysql_dump_login_path" - export MYSQLSHOW="mysqlshow --login-path=$CONFIG_mysql_dump_login_path" - export MYSQL="mysql --login-path=$CONFIG_mysql_dump_login_path" + export MYSQLDUMP="${CONFIG_mysqldump_bin} --login-path=$CONFIG_mysql_dump_login_path" + export MYSQLSHOW="${CONFIG_mysqlshow_bin} --login-path=$CONFIG_mysql_dump_login_path" + export MYSQL="${CONFIG_mysql_bin} --login-path=$CONFIG_mysql_dump_login_path" if [ -n "${CONFIG_mysql_dump_login_path_file}" ]; then export MYSQL_TEST_LOGIN_FILE=$CONFIG_mysql_dump_login_path_file fi else - export MYSQLDUMP="mysqldump --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host}"; - export MYSQLSHOW="mysqlshow --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host}"; - export MYSQL="mysql --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host}"; + export MYSQLDUMP="${CONFIG_mysqldump_bin} --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host}"; + export MYSQLSHOW="${CONFIG_mysqlshow_bin} --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host}"; + export MYSQL="${CONFIG_mysql_bin} --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host}"; fi } @@ -144,6 +158,12 @@ isEmpty() { if [[ ${!1} ]]; then return 1; else return 0; fi } +# @return: true, if mariadb is installed; else false +isMariaDB() { + type mariadb &>/dev/null + return $? +} + # @info: Called when one of the signals EXIT, SIGHUP, SIGINT, SIGQUIT or SIGTERM is emitted. # It removes the IO redirection, mails any log file information and cleans up any temporary files. # @args: (none) @@ -1210,7 +1230,11 @@ cleanup_latest () { check_dependencies () { echo echo "# Testing for installed programs" - dependencies=( 'mysql' 'mysqldump' ) + if isMariaDB; then + dependencies=( 'mariadb' 'mariadb-dump' ) + else + dependencies=( 'mysql' 'mysqldump' ) + fi if [[ "x$CONFIG_multicore" = 'xyes' ]]; then diff --git a/automysqlbackup.conf b/automysqlbackup.conf index bcf3e78..01c19db 100644 --- a/automysqlbackup.conf +++ b/automysqlbackup.conf @@ -14,6 +14,12 @@ # Basic Settings +# Override the client binary names if auto-detection produces wrong results. +# When unset, the script auto-detects binaries for MariaDB and MySQL. +#CONFIG_mysql_bin='' +#CONFIG_mysqldump_bin='' +#CONFIG_mysqlshow_bin='' + # use encrypted authentication credentials # yes: through login path # no: through username and password