[ # ] How to Automate your MySQL database backups

/* Posted May 5th, 2008 at 11:00am */
/* Filed under PHP, Programming */

mysql

for automating backups, you can use this: http://www.mysqldumper.de/en/

\or you can run this automatic script

Here’s an essential automatic script and a cron job you will need in order to keep your backup automatic.

Yes, if you get a dedicated server, don’t get their stupid extra $15/month for backing up your database. (All they do is make scripts like this one and charge you for it)

You can follow this example and go spend that money on junk food.

So all you have to do is FTP your backup files.

This is way better than going into your phpMyAdmin and downloading from the web interface since the file is already ready for you to download.

Here’s how you do it:

1) Make a new file called backup.sh in your home directory. 2) Use the following syntax:


mysqldump -u[USERNAME] -p[PASSWORD] –opt [DATABASE NAME]
> /root/backup/DATABASE1.sqlHere’s an example backup.sh file if you had 2 databases:

mysqldump -uUser1 -pPassword1 –opt Database1 > /root/backup/Database1.sql
mysqldump -uUser2 -pPassword2 –opt Database2 > /root/backup/Database2.sql
tar cvf /root/backup/sqlbackup.tar /root/backup/*You can test your script by typing this:

sh backup.sh(The mysqldump will overwrite the older file if you run this more than once)

3) If everything is working good, now you can put that script to be run once a day in your cron job.

For Fedora Core, you can edit this file /etc/cron.d/sa-update

Add the following line:

10 3 * * * root sh /root/backup/backup.shThis will execute the script once a day at 3:10AM.

Now simply download one tar ball file whenever you feel like backing up your database.

You can probably change this a little bit and use it for many other things like backing up all your files too. (which I do)

If you have multiple servers like me, you can also automate your scripts to download backup databases to each server. That keeps things real redundant in case of server failure.

  • Digg
  • del.icio.us
  • Propeller
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Mixx
  • NewsVine
  • Blogsvine
  • Facebook
  • Google
  • TwitThis


Related Posts

Leave a Reply


*


* (not published, used to display your gravatar)



(* required)

Anything Geeky Goes!

Highlights

Featured Wii

Featured iPhone

Featured PSP/PS3

Featured A/V

Related Links

Archives

Products Highlight


Featured Sites

Categories

Subscribe

Recent Posts

Commentors

Other Links