Page 1 of 1

[Solved] error with a db script

Posted: 2019/12/13 10:14:07
by Kl!nk

I try to make an automatic backup from my database. I take a script from my debian server ( It turn very well on debian)

I adapt it from the configuration but I have two error

line 49: Premature end of file character (EOF) when searching for the corresponding " " "
line 54: Syntax error: premature end of file

I don't understand why I search on google Itry a lot of thing but nothing..
Here is the script :

Code: Select all

# 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
dump_databases () {
    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
        $mysqldump_command --defaults-file=/etc/mysql/debian.cnf "$database" | $compress_command  > "
        echo "Backing up database: ${database}..."

    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
    if [ ! -d "$backup_folder" ] ; then
        mkdir -p "$backup_folder"


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

Re: error with a db script

Posted: 2019/12/13 11:57:33
by lightman47
$mysqldump_command --defaults-file=/etc/mysql/debian.cnf "$database" | $compress_command > "
I don't really know, but might the mis-matched quotes be a problem?

Re: error with a db script

Posted: 2019/12/13 12:03:34
by Kl!nk
Yes you have wright I add an " before $compress_command and it works.

Code: Select all

$mysqldump_command --defaults-file=/etc/mysql/debian.cnf "$database" |" $compress_command > " 
thank you !

Re: [Solved] error with a db script

Posted: 2019/12/13 12:41:27
by lightman47
It was saying there was an ODD number of quotes when the script ended. I just read the script backwards looking for pairs of them.


Re: [Solved] error with a db script

Posted: 2019/12/17 15:26:22
by KernelOops
just a quick suggestion, when using bash variables within a string, its a good idea to enclose them in brackets, for example:


Code: Select all

echo this is my $database

Code: Select all

echo this is my ${database}
this method allows you to squeeze the variable within the string without spaces, like:

Code: Select all

echo something${database}else