MySQL Backup All Databases


#!/bin/bash
USER=”Mysql_username”
PASSWORD=”Mysql_password”
DATE=$(date +%F)
mkdir -p /home/mysql_backup/$DATE
BKPDIR=”/home/mysql_backup/$DATE”
databases=mysql --user=$USER --password=$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database
for db in $databases; do
if [[ “$db” != “information_schema” ]] && [[ “$db” != _* ]] && [[ “$db” != “performance_schema” ]]; then
echo “Dumping database: $db” >> dump.log
mysqldump –force –opt –user=$USER –password=$PASSWORD –databases $db > $BKPDIR/date +%Y%m%d.$db.sql
gzip $BKPDIR/date +%Y%m%d.$db.sql
fi
done
echo “Backup Seucessfully created on $date” >> dump.log

Path Details
/home/mysql_backup/2015-09-23/20150923.mysql.sql.gz

Output Details
chaitanya-GA-78LMT-S2 home # ls
chaitanya  Chaitu  mysql_backup
chaitanya-GA-78LMT-S2 home # cd mysql_backup/
chaitanya-GA-78LMT-S2 mysql_backup # ls
2015-09-23
chaitanya-GA-78LMT-S2 mysql_backup # cd 2015-09-23/
chaitanya-GA-78LMT-S2 2015-09-23 # ls
20150923.mysql.sql.gz
chaitanya-GA-78LMT-S2 2015-09-23 # vim 20150923.mysql.sql.gz

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s