msgbartop
A chronological documentation test project, nothing serious, really!
msgbarbottom

18 Nov 2007 Backup mysql databases into separate files

Posted by

This bach script makes separate backup files of all the databases in mysql and saves the result in the mysql_backup folder.

#!/bin/bash -v

USERNAME='yourusername'
PASSWORD='yourpassword'
HOSTNAME='yourhostname'
BackupFolder='/backup'

for i in $(echo 'SHOW DATABASES;' | mysql --user $USERNAME -p$PASSWORD -h $HOSTNAME | grep -v '^Database$' ); do
        mysqldump --user $USERNAME -p$PASSWORD -h $HOSTNAME --opt $i > $BackupFolder/$i.sql;
done;

Remember to change the -h, -p and -h switch according to your needs and avoid space between -p and the password variable.

Tags: , , , , ,

Comments are closed.