«

»

Oct
27

Backing Up Mysql Databases On A Cron

With all the websites that I run, keeping backups is essentail.

I first wrote a bash script that I ran on a cron job whcih backed up each database and then zipped the sql file up:

#!/bin/sh
mysqldump -uroot -ppwd --opt db1 > /sqldata/db1.sql
mysqldump -uroot -ppwd --opt db2 > /sqldata/db2.sql

cd /sqldata/
tar -zcvf sqldata.tgz *.sql

This meant that I had to modify this backup script each time I added a database. I then found that you can use the ‘–all-databases’ option to backup all the databases at once:
#!/bin/sh
mysqldump -uroot -ppwd
–all-databases > /sqldata/data.sql

cd /sqldata/
tar -zcvf sqldata.tgz *.sql

This works perfectly.

After creating the Tar file I store it on the server where a secondary script runs copying thes backups off site and deleting fiels older than 21 days, meanind that I have a rolling 3 week backup both on the server and off the server.

Related posts:

  1. How To Check If You Are Ready For WordPress 3.2 If you have ready my previous post about a first view of WordPress 3.2, you will have noted that there are some significant requirements changes...

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>