May 14, 2009

[useful] MySQL datbase backup script

Forums: 

Here is a script i use for backing my website up. Its a simple shell scipt that runs the mysql dump command.

mysqldump -udatabaseusername
-pdatabasepassword
databasename >$(date).sql

so a typical usage of this might be:

[code]
mysqldump -uroot -pajellydoghnut
database1 >$(date).sql
]/code]

Where root is the username, ajellydoughnut is
the password and database1 is the database i
want to backup.

The advantage to doing it this way is that i can
go ahead and add this script as a cron joob to be
executed say every Tuesday at 11am meaning
that my database is backed up automatically for
me and a backup of that database is downloaded
to wherever this script is stored in .sql format
(typically i put it in a folder of its own in my
home directory)

Another handy thing is that because
of >$(date).sql on the end the script automatically
sets the current date and time as the filename
meaning no more messing around looking
through the creation time, its just there in the
filename :)

Hope this helps someone.

-Lenswipe