Creating an automatic backup script for mysql

Ok this is really step by step. There’s nothing complicated

1. Created a backup folder as ROOT

> sudo su
enter password
> cd /
> mkdir backup
> cd backup

now create a shell script I use NANO to do this. (don’t forget to change the username and password to match yours)

> nano backup.sh

cd /backup
mysqldump -u username -ppassword --all-databases>backup`date +%a`.sql

Save the file. backup.sh

Now edit the cron table

> crontab -e
01 02 * * *  /backup/backup.sh

and save.

This will cause your backup to happen every morning at 2am.

It’s a good idea to test your backup routine sh backup.sh before leaving it to cron to do the work.

 

Advertisements

About Paul C

I am a Senior Java programmer/Web Technologies, Play in a band called Mandolin Monday, I have a cat and I live on a boat.

Posted on August 23, 2012, in Howto. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: