Currently viewing the tag: "mysql"

I now and again add/delete websites and their subsequent databases too my server(s).  I use the following script to backup the databases.  Using this I don’t have to worry about remembering to change the script to capture a database or to stop looking for a database.  The script (which runs as root) learns the databases from mysql just before doing the backups.

#!/bin/sh
cd backups/
for DB in `echo "show databases;" | mysql| grep -v ^Database`; do
mysqldump --add-drop-table $DB |bzip2 -c > $DB.`date -u +%Y%m%d-%H:%M:%S`.sql.bz2

done