Skip to content

Commit 3c53f9a

Browse files
committed
Added MariaDB support, sukria#144
1 parent 62dcacc commit 3c53f9a

18 files changed

+3400
-1891
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Backup Manager 0.7.17
2+
[ Fabien Marsaud ]
3+
* Add MariaDB support
4+
15
Backup Manager 0.7.16
26
[ doekia ]
37
* Add MongoDB support

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.16
1+
0.7.17

backup-manager.conf.tpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export BM_ARCHIVE_NICE_LEVEL="10"
7272
# - tarball
7373
# - tarball-incremental
7474
# - mysql
75+
# - mariadb
7576
# - pgsql
7677
# - mongodb
7778
# - svn
@@ -189,10 +190,10 @@ export BM_TARBALLINC_MASTERDATEVALUE="1"
189190
# BM_TARBALLINC_MASTERDATEVALUE="1"
190191

191192
##############################################################
192-
# Backup method: MYSQL
193+
# Backup method: MYSQL / MARIADB
193194
#############################################################
194195

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

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

221222
# which compression format to use? (gzip, bzip2 or zstd)

lib/actions.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ function make_archives()
3131
mysql)
3232
backup_method_mysql "$method"
3333
;;
34+
mariadb)
35+
backup_method_mariadb "$method"
36+
;;
3437
pgsql)
3538
backup_method_pgsql "$method"
3639
;;

lib/backup-methods.sh

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,13 +1029,27 @@ function backup_method_pgsql()
10291029
function backup_method_mysql()
10301030
{
10311031
method="$1"
1032+
backup_method_mysql_mariadb $method $mysqldump $mysql
1033+
}
1034+
1035+
function backup_method_mariadb() {
1036+
method="$1"
1037+
backup_method_mysql_mariadb $method $mariadbdump $mariadb
1038+
}
1039+
1040+
1041+
function backup_method_mysql_mariadb()
1042+
{
1043+
method="$1"
1044+
dump_bin="$2"
1045+
client_bin="$3"
10321046
mysql_conffile="$HOME/.backup-manager_my.cnf"
10331047

10341048
debug "backup_method_mysql ($method)"
10351049

10361050
info "Using method \"\$method\"."
1037-
if [[ ! -x $mysqldump ]]; then
1038-
error "The \"mysql\" method is chosen, but \$mysqldump is not found."
1051+
if [[ ! -x $dump_bin ]]; then
1052+
error "The \"\$method\" method is chosen, but \$dump_bin is not found."
10391053
fi
10401054

10411055
opt=""
@@ -1045,28 +1059,29 @@ function backup_method_mysql()
10451059

10461060
# if a MySQL Client conffile exists, the password must be inside
10471061
if [[ -f $mysql_conffile ]]; then
1048-
info "Using existing MySQL client configuration file: \$mysql_conffile"
1062+
info "Using existing MySQL/MariaDB client configuration file: \$mysql_conffile"
10491063
BM_SHOULD_PURGE_MYCNF="false"
10501064
# we create a default one, just with the password
10511065
else
1052-
warning "Creating a default MySQL client configuration file: \$mysql_conffile"
1066+
warning "Creating a default MySQL/MariaDB client configuration file: \$mysql_conffile"
10531067
echo "[client]" > $mysql_conffile
1054-
echo "# The following password will be sent to all standard MySQL clients" >> $mysql_conffile
1068+
echo "# The following password will be sent to all standard MySQL/MariaDB clients" >> $mysql_conffile
10551069
chmod 600 $mysql_conffile
10561070
echo "password=\"$BM_MYSQL_ADMINPASS\"" >> $mysql_conffile
10571071
BM_SHOULD_PURGE_MYCNF="true"
10581072
fi
1059-
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"
1073+
if [ -n "$BM_MYSQL_PORT" ]; then BM_MYSQL_PORT_OPT="-P$BM_MYSQL_PORT"; else BM_MYSQL_PORT_OPT=""; fi
1074+
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"
10601075
compress="$BM_MYSQL_FILETYPE"
10611076

10621077
# get each DB name if backing up separately
10631078
if [ "$BM_MYSQL_DATABASES" = "__ALL__" ]; then
10641079
if [ "$BM_MYSQL_SEPARATELY" = "true" ]; then
1065-
if [[ ! -x $mysql ]]; then
1066-
error "Can't find "$mysql" but this is needed when backing up databases separately."
1080+
if [[ ! -x $client_bin ]]; then
1081+
error "Can't find \"\$client_bin\" but this is needed when backing up databases separately."
10671082
fi
10681083

1069-
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')
1084+
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')
10701085

10711086
# if DBs are excluded
10721087
for exclude in $BM_MYSQL_DBEXCLUDE
@@ -1081,10 +1096,10 @@ function backup_method_mysql()
10811096
for database in $BM_MYSQL_DATABASES
10821097
do
10831098
if [[ "$database" = "__ALL__" ]]; then
1084-
file_to_create="$BM_REPOSITORY_ROOT/${BM_ARCHIVE_PREFIX}-all-mysql-databases.$TODAY.sql"
1099+
file_to_create="$BM_REPOSITORY_ROOT/${BM_ARCHIVE_PREFIX}-all-${method}-databases.$TODAY.sql"
10851100
command="$base_command --all-databases"
10861101
else
1087-
file_to_create="$BM_REPOSITORY_ROOT/${BM_ARCHIVE_PREFIX}-mysql-${database}.$TODAY.sql"
1102+
file_to_create="$BM_REPOSITORY_ROOT/${BM_ARCHIVE_PREFIX}-${method}-${database}.$TODAY.sql"
10881103
command="$base_command $database"
10891104
fi
10901105
__create_file_with_meta_command

lib/externals.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ md5sum=$(which md5sum 2> /dev/null) || true
1818
bc=$(which bc 2> /dev/null) || true
1919
mysqldump=$(which mysqldump 2> /dev/null) || true
2020
mysql=$(which mysql 2> /dev/null) || true
21+
mariadbdump=$(which mariadb-dump 2> /dev/null) || true
22+
mariadb=$(which mariadb 2> /dev/null) || true
2123
pgdump=$(which pg_dump 2>/dev/null) || true
2224
svnadmin=$(which svnadmin 2> /dev/null) || true
2325
logger=$(which logger 2> /dev/null) || true

lib/sanitize.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /usr/bin/env bash
2-
# Copyright © 2005-2018 The Backup Manager Authors
2+
# Copyright 2005-2018 The Backup Manager Authors
33
#
44
# See the AUTHORS file for details.
55
#
@@ -248,6 +248,13 @@ if [[ "$BM_ARCHIVE_METHOD" = "mysql" ]]; then
248248
confkey_require "BM_MYSQL_FILETYPE" "tar.gz"
249249
fi
250250

251+
if [[ "$BM_ARCHIVE_METHOD" = "mariadb" ]]; then
252+
confkey_require "BM_MYSQL_ADMINLOGIN" "root"
253+
confkey_require "BM_MYSQL_HOST" "localhost"
254+
confkey_require "BM_MYSQL_PORT" ""
255+
confkey_require "BM_MYSQL_FILETYPE" "tar.gz"
256+
fi
257+
251258
if [[ "$BM_ARCHIVE_METHOD" = "pgsql" ]]; then
252259
confkey_require "BM_PGSQL_ADMINLOGIN" "root"
253260
confkey_require "BM_PGSQL_HOST" "localhost"

0 commit comments

Comments
 (0)