[Solved] error with a db script
Posted: 2019/12/13 10:14:07
Hello
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 " " "
and
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 :
thank in advance
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 " " "
and
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
#!/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