Skip to content

Commit

Permalink
Added MariaDB support, sukria#144
Browse files Browse the repository at this point in the history
  • Loading branch information
fabmars committed Oct 29, 2024
1 parent 62dcacc commit 06fc37d
Show file tree
Hide file tree
Showing 18 changed files with 3,398 additions and 1,889 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Backup Manager 0.7.17
[ Fabien Marsaud ]
* Add MariaDB support

Backup Manager 0.7.16
[ doekia ]
* Add MongoDB support
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.16
0.7.17
7 changes: 4 additions & 3 deletions backup-manager.conf.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export BM_ARCHIVE_NICE_LEVEL="10"
# - tarball
# - tarball-incremental
# - mysql
# - mariadb
# - pgsql
# - mongodb
# - svn
Expand Down Expand Up @@ -189,10 +190,10 @@ export BM_TARBALLINC_MASTERDATEVALUE="1"
# BM_TARBALLINC_MASTERDATEVALUE="1"

##############################################################
# Backup method: MYSQL
# Backup method: MYSQL / MARIADB
#############################################################

# This method is dedicated to MySQL databases.
# This method is dedicated to MySQL and MariaDB databases.
# You should not use the tarball method for backing up database
# directories or you may have corrupted archives.
# Enter here the list of databases to backup.
Expand All @@ -215,7 +216,7 @@ export BM_MYSQL_ADMINPASS=""
# the host where the database is
export BM_MYSQL_HOST="localhost"

# the port where MySQL listen to on the host
# the port where MySQL listen to on the host. Leave empty if you're using unix_socket auth.
export BM_MYSQL_PORT="3306"

# which compression format to use? (gzip, bzip2 or zstd)
Expand Down
3 changes: 3 additions & 0 deletions lib/actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function make_archives()
mysql)
backup_method_mysql "$method"
;;
mariadb)
backup_method_mariadb "$method"
;;
pgsql)
backup_method_pgsql "$method"
;;
Expand Down
33 changes: 24 additions & 9 deletions lib/backup-methods.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1029,13 +1029,27 @@ function backup_method_pgsql()
function backup_method_mysql()
{
method="$1"
backup_method_mysql_mariadb $method $mysqldump $mysql
}

function backup_method_mariadb() {
method="$1"
backup_method_mysql_mariadb $method $mariadbdump $mariadb
}


function backup_method_mysql_mariadb()
{
method="$1"
dump_bin="$2"
client_bin="$3"
mysql_conffile="$HOME/.backup-manager_my.cnf"

debug "backup_method_mysql ($method)"

info "Using method \"\$method\"."
if [[ ! -x $mysqldump ]]; then
error "The \"mysql\" method is chosen, but \$mysqldump is not found."
if [[ ! -x $dump_bin ]]; then
error "The \"\$method\" method is chosen, but \$dump_bin is not found."
fi

opt=""
Expand All @@ -1045,28 +1059,29 @@ function backup_method_mysql()

# if a MySQL Client conffile exists, the password must be inside
if [[ -f $mysql_conffile ]]; then
info "Using existing MySQL client configuration file: \$mysql_conffile"
info "Using existing MySQL/MariaDB client configuration file: \$mysql_conffile"
BM_SHOULD_PURGE_MYCNF="false"
# we create a default one, just with the password
else
warning "Creating a default MySQL client configuration file: \$mysql_conffile"
warning "Creating a default MySQL/MariaDB client configuration file: \$mysql_conffile"
echo "[client]" > $mysql_conffile
echo "# The following password will be sent to all standard MySQL clients" >> $mysql_conffile
echo "# The following password will be sent to all standard MySQL/MariaDB clients" >> $mysql_conffile
chmod 600 $mysql_conffile
echo "password=\"$BM_MYSQL_ADMINPASS\"" >> $mysql_conffile
BM_SHOULD_PURGE_MYCNF="true"
fi
base_command="$mysqldump --defaults-extra-file=$mysql_conffile $opt -u$BM_MYSQL_ADMINLOGIN -h$BM_MYSQL_HOST -P$BM_MYSQL_PORT $BM_MYSQL_EXTRA_OPTIONS"
if [ -n "$BM_MYSQL_PORT" ]; then BM_MYSQL_PORT_OPT="-P$BM_MYSQL_PORT"; else BM_MYSQL_PORT_OPT=""; fi
base_command="$dump_bin --defaults-extra-file=$mysql_conffile $opt -u$BM_MYSQL_ADMINLOGIN -h$BM_MYSQL_HOST $BM_MYSQL_PORT_OPT $BM_MYSQL_EXTRA_OPTIONS"
compress="$BM_MYSQL_FILETYPE"

# get each DB name if backing up separately
if [ "$BM_MYSQL_DATABASES" = "__ALL__" ]; then
if [ "$BM_MYSQL_SEPARATELY" = "true" ]; then
if [[ ! -x $mysql ]]; then
error "Can't find "$mysql" but this is needed when backing up databases separately."
if [[ ! -x $client_bin ]]; then
error "Can't find \"\$client_bin\" but this is needed when backing up databases separately."
fi

DBNAMES=$($mysql --defaults-extra-file=$mysql_conffile -u $BM_MYSQL_ADMINLOGIN -h $BM_MYSQL_HOST -P $BM_MYSQL_PORT -B -N -e "show databases" | sed 's/ /%/g')
DBNAMES=$($client_bin --defaults-extra-file=$mysql_conffile -u $BM_MYSQL_ADMINLOGIN -h $BM_MYSQL_HOST $BM_MYSQL_PORT_OPT -B -N -e "show databases" | sed 's/ /%/g')

# if DBs are excluded
for exclude in $BM_MYSQL_DBEXCLUDE
Expand Down
2 changes: 2 additions & 0 deletions lib/externals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ md5sum=$(which md5sum 2> /dev/null) || true
bc=$(which bc 2> /dev/null) || true
mysqldump=$(which mysqldump 2> /dev/null) || true
mysql=$(which mysql 2> /dev/null) || true
mariadbdump=$(which mariadb-dump 2> /dev/null) || true
mariadb=$(which mariadb 2> /dev/null) || true
pgdump=$(which pg_dump 2>/dev/null) || true
svnadmin=$(which svnadmin 2> /dev/null) || true
logger=$(which logger 2> /dev/null) || true
Expand Down
9 changes: 8 additions & 1 deletion lib/sanitize.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env bash
# Copyright © 2005-2018 The Backup Manager Authors
# Copyright 2005-2018 The Backup Manager Authors
#
# See the AUTHORS file for details.
#
Expand Down Expand Up @@ -248,6 +248,13 @@ if [[ "$BM_ARCHIVE_METHOD" = "mysql" ]]; then
confkey_require "BM_MYSQL_FILETYPE" "tar.gz"
fi

if [[ "$BM_ARCHIVE_METHOD" = "mariadb" ]]; then
confkey_require "BM_MYSQL_ADMINLOGIN" "root"
confkey_require "BM_MYSQL_HOST" "localhost"
confkey_require "BM_MYSQL_PORT" ""
confkey_require "BM_MYSQL_FILETYPE" "tar.gz"
fi

if [[ "$BM_ARCHIVE_METHOD" = "pgsql" ]]; then
confkey_require "BM_PGSQL_ADMINLOGIN" "root"
confkey_require "BM_PGSQL_HOST" "localhost"
Expand Down
Loading

0 comments on commit 06fc37d

Please sign in to comment.