#!/bin/bash read -e -p "Type host for backup, followed by [ENTER]: " -i "127.0.0.1" host read -e -p "Type username for $host, followed by [ENTER]: " -i "root" user read -e -p "Type password for $user, followed by [ENTER]: " -i "" passwd read -e -p "Database which should be backuped [ENTER]: " -i "all" db DB_BACKUP=mysql_dump_$(date +%F) mkdir $DB_BACKUP cd $DB_BACKUP if [ $db == "all" ] then for db in $(mysql -h $host --user=$user --password=$passwd -e 'show databases' -s --skip-column-names|grep -viE '(staging|performance_schema|information_schema)'); do file_name="mysqldump-$db-$(date +%Y-%m-%d).gz"; mysqldump -h $host --user=$user --password=$passwd --events --log-error=mysql_dump.log --opt --single-transaction $db | gzip > $file_name; [ -s $file_name ] && res=Done || res=FAIL echo $db"|"$file_name"|"$res done | column -s "|" -t else file_name="mysqldump-$db-$(date +%Y-%m-%d).gz"; mysqldump -h $host --user=$user --password=$passwd --events --log-error=mysql_dump.log --opt --single-transaction $db | gzip > $file_name; [ -s $file_name ] && res=Done || res=FAIL echo $db"|"$file_name"|"$res fi | column -s "|" -t