#!/bin/bash

set -e

DESC="Exportation des bases MySQL"

. /usr/share/eole/schedule/config.sh

MYSQLSAVDIR=$SAVDIR/sql
OPTION="--lock-tables"

rm -f $MYSQLSAVDIR/*.sql
mkdir -p $MYSQLSAVDIR

CMD="mysql --defaults-file=/etc/mysql/mariadb.cnf -e 'show databases' | grep -v '^Database$'"
DATABASES=$(CreoleRun "$CMD" mysql)
for databasename in $DATABASES; do
    case "$databasename" in
        information_schema|performance_schema|bareos)
            continue
            ;;
        *)
            CMD="mysqldump --defaults-file=/etc/mysql/mariadb.cnf --databases $databasename --flush-privileges --create-options -Q -c $OPTION 2>/dev/null"
            CreoleRun "$CMD" mysql > $MYSQLSAVDIR/$databasename.sql
            ;;
    esac
done