Backup Your Mysql Databases

Joined: 11/28/2008

It's pretty easy to have your mysql databases automatically back up with a bash script, using cron (Unix or Linus servers). Using a text editor, copy and paste the following code into a new text file:

CODE
mysqldump -hinsert_host_name_here -uinsert_username_here -pinsert_password_here --opt insert_database_name_here > /insert_directory_path_here_for_file_placement/name_of_file.sql
#!mysqldump -hlocalhost -uroot -ppwd --opt db2 > var/www/bak/sqldata/db2.sql

Name the file anything you want as long as it doesn't have a space in the name, and you end it with .sh, such as dump.sh. Upload it to your server using ftp. Then, use your cron GUI or the bash commands to edit your crontabs to set it to automatically run at specified times, pointing cron to this file stored on your server. Do a Google search for Cron to get more details for your specific hosting package, or your particular server setup.

Joined: 11/28/2008
I would only add that you

I would only add that you would also want to pipe it to gzip and download it - when hard drives fail, sometimes the whole lot goes.

Keith, in the advent of a disaster, how would you suggest importing the mysql dump? (Assuming you don't have shell access which is rarer these days).

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified