All Linux HowTo's Scripting HowTo's Security HowTo's

Dump and Backup all MySQL Databases into their own files

This article demonstrates how to backup all MySQL databases into their own files and then tar the lot including system files.

#!/bin/bash

TO="/root"
FROM="/etc /var/www/html /var/backups"
DBUSER="root"
DBPASS='MyPassword'
THISHOST=`hostname`

DBLIST=`echo "show databases;" | mysql --password=$DBPASS -u $DBUSER | egrep -v '^Database$|^information_schema$|^mysql$'`

for DBLOOP in `echo $DBLIST`
do
        mysqldump -u $DBUSER --password=$DBPASS $DBLOOP > /var/backups/mysql-$DBLOOP-$THISHOST-$(date +%w).sql
done

tar -czf $TO/files-web-$DBN-$(date +%w).tgz $FROM

The above backup script will dump each MySQL database into its own file and then Tar the dumps along with the system files (etc and web files).

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.