totally g33koid request…

Just wondering  -those of a g33ky p3rsu410n, is there an easy way to backup a MySQL database automatically – ie. not me doing it manually, and emailing or FTPing the files to me?

Or at minimum on the same webspace, but off-server would be better.

I guess it’s a ‘CRON job’ (and yes I can run those, so get scripts to run automagically) but scared I could do some damage not knowing what I’m doing…not knowing any CGI/Perl type gubbins, or how to set up CRON properly.
Not seen much simple guides about this, and would prefer a tested script…


  1. April 26

    You want to use “mysqldump” in a cron. It’s impossible to fuck up your DB using mysqldump because it only outputs data.

    The syntax for your command that you want in cron is mysqldump -u -p -h > backup.sql

    That dumps the entire DB to backup.sql

    I guess you could have it a bit more complex using some bash or perl script to call that which puts the data into a dated file, but that’s the basics.

    To set up a cron job, run “crontab e” which then will most likely put you into the incredibly user-friendly “vi”, which is a nightmare if you’ve never used it before. You’ll want to google the format of crontab before you start editing, but it’s basically the frequency and time that you want to run a command seperated by spaces, followed by that command.

  2. April 26

    The comments thing stripped out a lot of how I wrote that command!

    It’s: mysqldump -u [username] -p[password with no space before it] -h [host if not localhost] > backup.sql

  3. April 26

    Mail me if you need more help on that – I’m guessing you can see my email address from this form…

  4. April 26

    yeah it strips out ‘malicious code’ so it’s probably not the best for posting code snippets (maybe in the tag?)

    I'll give you an email - do you know any scripts to do date order and maybe email or FTP it? Or is that something I do my end?

  5. April 27

    There are probably scripts out there that do that kind of thing in bash, perl, PHP or whatever. I’m not going to insult your intelligence by googling “mysql backup script” and posting the first 3 links that appear though 😉

    Getting a script to zip up the DB and mail it out or FTP it is pretty straightforward too. *nix based systems (unix, linux, OSX, BSD) all have command-line zip, the “mail” command and a scriptable command-line FTP client built in.

    You’ll end up calling the bash script itself from the cron job as opposed to writting the job all into one line inside crontab.

  6. April 27

    thanks that’s a great help. Still scares me though…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.