Multiple Database Backup Script


#!/bin/bash
MySQL User
USER=’Username’
MySQL Password
PASSWORD=’Password’
Backup Directory
OUTPUT=”/home/backup”
TIMESTAMP=date +%Y%m%d_%H%M%S;
mkdir $OUTPUT/$TIMESTAMP;
cd $OUTPUT/$TIMESTAMP;
Starting MySQL Backup
echo 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” != _* ]] ; then
echo “Dumping database: $db”
mysqldump –force –opt –user=$USER –password=$PASSWORD –databases $db > $OUTPUT/dbbackup-$TIMESTAMP-$db.sql
gzip $OUTPUT/dbbackup-$TIMESTAMP-$db.sql
fi
done
Finished MySQL Backup
echo date;

Path Details
/home/backup/

Output Details
/home/backup/dbbackup-20150827_155251-mysql.sql.gz & dbbackup-20150827_155251-performance_schema.sql.gz

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