mirror of https://github.com/pditzel/dbb.git

Patrick Ditzel
07.19.2022 5bbe9ac2ab8975efea6982747944416b607e9eb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
 
# MariaBD/MySQL remote
#
# The Information what MySQL/MariaDB - databases should be backuped are defined in ~/.my.cnf-dbname
#
# note: for each MySQL- or MariaDB-Database create a seperate configfile .my.cnf-dbname in the ~ of the backupuser:
# note: replace the suffixe -dbname with the name of the database. The seperating "-" can also be a ".".
#   [mysqldump]
# host=HOSTNAME
# user=DBUSERNAME
# password=PASSWORD
# database=DATABASENAME
 
function check-mariadb-deps {
    if [ ! -e /usr/bin/mysqldump ]; then
        debug "It seems that you dont have mysqldump installed. You may have problems to backup remote databases"
    fi
# TODO: Check for ~/.my.cnf-*
}
 
function mariadb_remote {
    for MARIADB in $(ls ~/.my.cnf-* | cut -d "-" -f2); do
        debug "Function mariadb_remote: Doing Database: $MARIADB"
        MARIADBHOSTNAME=$(cat ~/.my.cnf-"$MARIADB" | grep host | cut -d "=" -f2)
        /usr/bin/mysqldump --defaults-file=~/.my.cnf-"$MARIADB" --skip-dump-date "$MARIADB" > "$TMP_DIR"/"$MARIADBHOSTNAME"_"$MARIADB".mysql
        debug "Diff MySQLDump $MYSQLDB"
        diff "$TMP_DIR"/"$MARIADBHOSTNAME"_"$MARIADB".mysql "$BACKUP_DIR"/"$MARIADBHOSTNAME"_"$MARIADB".mysql > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        debug "Differences found -> moving to BACKUP_DIR"
        backup_file_handler "$TMP_DIR" "$BACKUP_DIR" "$MARIADBHOSTNAME"_"$MARIADB".mysql
    else
            debug "No differences found in Database $MARIADB"
    fi
    echo ""
    done
}
 
function mariadb-main {
    if [ "$MARIADB_BACKUP_REMOTE" = "TRUE" ]; then
        mariadb_remote
    fi
}