bash for back up bdd didn't work

General support questions
Post Reply
Kl!nk
Posts: 1
Joined: 2019/11/22 07:22:39

bash for back up bdd didn't work

Post by Kl!nk » 2019/11/22 09:19:24

Hello
I try to backup my database with mysqldump
this script work fine on debian, but in cent os when I launch it I have two error

line 49 : End-of-file (EOF) character when searching for the corresponding "
line 55 : Syntax error: premature end of file

this is my script :

Code: Select all

#!/bin/bash
# Script de sauvegarde des bases de données mysql/mariadb
# Les valeurs à paramétrer sont en fin de script dans la fonction main()

get_databases_to_backup() {
    mysql_command=$(command -v mysql)
    databases_list=$($mysql_command --defaults-file=/etc/my.cnf -Bse 'show databases')

    for exclude in $databases_exclude_list
    do
       databases_list=${databases_list//$exclude/}
    done
}
dump_databases () {
    ext=".sql.gz"
    mysqldump_command=$(command -v mysqldump)
    compress_command=$(command -v gzip)
    current_date=$(date +%F_%Hh%M)
    cd "${backup_folder}" || exit
    for database in $databases_list
    do
        $mysqldump_command --defaults-file=/etc/mysql/debian.cnf "$database" | $compress_command  > "
        echo "Backing up database: ${database}..."
    done

    echo "$(date +%c): Backup complete!"
}
delete_old_backups() {
    find_command=$(command -v find)
    cd "${backup_folder}" || exit
    $find_command ./ -mtime +"${delete_backups_older_than_days}" -type f -exec rm -v {}  \;
}

main() {
    # toujours exclure information_schema performance_schema de la sauvegarde sinon le script générera$
    databases_exclude_list="mysql phpmyadmin information_schema performance_schema"

    # choix du dossier de destination des sauvegardes à ajuster à vos besoins
    backup_folder="/home/dumpbdd/matin"
    if [ ! -d "$backup_folder" ] ; then
        mkdir -p "$backup_folder"
    fi

    get_databases_to_backup
    dump_databases

    # nombre de jours pendant lesquels il faut conserver les sauvegardes, -1 si illimité
    delete_backups_older_than_days=1
    if [ $delete_backups_older_than_days != "-1" ] ; then
        delete_old_backups
    fi
}

main
I search a few hours but nothing. All syntax seems good
did you have an idea

Thank's in advance

User avatar
TrevorH
Forum Moderator
Posts: 27156
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: bash for back up bdd didn't work

Post by TrevorH » 2019/11/22 09:40:45

Despite the error appearing to be on line 49 according to that, I think it's actually line 22 has been truncated and is missing a closing quote. That then cascades down the file looking for the next closing quote and pushing it all out of sync until it falls off the bottom.
CentOS 6 will die in November 2020 - migrate sooner rather than later!
CentOS 5 has been EOL for nearly 3 years and should no longer be used for anything!
Full time Geek, part time moderator. Use the FAQ Luke

Post Reply

Return to “CentOS 6 - General Support”