I am EXTREMELY paranoid. Read that again: EXTREMELY paranoid. I tend to back up important data two or three times to multiple locations. It’s just not worth the headache of losing it. So kids, here is a quick and dirty bash script to dump all of your MySQL databases and compress them into individual archives. I know it’s not rocket science, but can it, it works.
#!/bin/bash
password="mysqlrootpassword"
backupdir="/home/backup/mysqldumps/"
cd $backupdir
for database in $(mysql --password=$password -e "show databases" | grep "^\|" | grep -v Database);
do
mysqldump --password=$password $database | bzip2 > $database.sql.bz2;
done
chmod 600 $backupdir/*
Please excuse the ugly spacing, the wordpress theme seems to have chopped it up a bit.