A message for Linux.com registered users: We are in the process of making changes to the Linux forums. Starting Monday, 8/13/18 at 6:00 PM PT, you will be unable to access the forums. They will re-launch as soon as possible on Wednesday, 8/15/18 with new features and improved functionality. Thank you for your patience and stay tuned for the new improved forums.

May 14, 2009

[useful] MySQL datbase backup script


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

mysqldump -udatabaseusername
databasename >$(date).sql

so a typical usage of this might be:

mysqldump -uroot -pajellydoghnut
database1 >$(date).sql

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.


Click Here!