#!/bin/bash

# Script downloaded from thesoloadmin.com.
# Script v1.0

# Read user account
echo -n "MySQL User Name: "
read mysql_user
echo -n -e "\n"

# Read password
echo -n "MySQL User Password: "
read -s mysql_password
echo -n -e "\n\n"

# Assign variables
directory="./mysql_database_backups"
database_count=13
current_date=`date +%F`
databases=`mysql -u ${mysql_user} --password=${mysql_password} -e "show databases;" --batch | tail -${database_count}`

# Backup the databases
for database in ${databases} 
do
	mysqldump -u ${mysql_user} --password=${mysql_password} ${database} >> ${directory}/${database}_${current_date}.sql
	echo "Database ${database} backed up successfully."
done

# Exit successfully
exit 0
