MySQL Backup Script: Cron Hook

Now let’s take that simple script below and automate it via cron.

To create a crontab:
type crontab -e then type in

MAILTO="yourmail@domain.com"
0 0 1,7,14,28 * * ~/scripts/mysqlbackup

then hit CTRL O to save then CTRL X to exit the editor

What does it mean? cron will run the mysqlbackup script on midnight every seven days of every month. If any error occurs then you’ll receive an email. If you want it to go to a log file just replace the above where appropriate with the code below:

0 0 1,7,14,28 * * ~/scripts/mysqlbackup > ~/logs/cron/cron.log

For a cron primer please refer to this site

3 Responses to “MySQL Backup Script: Cron Hook”

  1. mike Says:

    you are such a flippin’ GEEK!

  2. X Says:

    Use absolute paths in all your scripts they will save you many headaches at 3am.

    #!/bin/sh
    #assign
    MY_UBER_SQL_BACKUPSCRIPT=/usr/local/scripts/mysqlbackup
    #call
    $MY_UBER_SQL_BACKUPSCRIT

    And it is more secure.
    -aC

  3. Steve Covell Says:

    That’s why you’re on top of the hero list. Super X to the rescue. Thanks X, I’ll definitely keep that in mind the next time.

Leave a Reply