Gnuru.org
Productive Linux


Subscribe

 Subscribe via Feedburner in a reader

Enter your email address:

Delivered by FeedBurner


Login
Login:
Password:



Don't have an account?
Sign up to Gnuru.org
Forgot your password?

Backing up Mysql
5 March 2006 @ 00:23 GMT
by root

These days much stuff is stored in mysql databases and it is therefore quite important to back it all up regularly. The added bonus of this is because I'm still trying to get my head around shell scripting I looked around the internet to find a script.

I found a very simple one here. I've modified it slightly to store the various databases in their own directories:

#!/bin/bash

for DB in `mysql -B -e "show databases" | tail +2`; do
    DIR=/mnt/backup/mysql/$DB/
    mkdir -p $DIR
    mysqldump --opt $DB | bzip2 -c -9 > $DIR$DB.`date --iso-8601`.bz2
done

The other modification I've made is to use bzip2 rather than gzip because of the better compression acheived. The script is run as a cron job.

On a slightly different point, one interesting script I found backed up mysql databases to gmail. The script is here




Comments disabled