mysqldump and cron

Hello all,

I've written the following shell command, and execute it without issue.

mysqldump -databasename -u username --password='dbpassword' > /backupdir/sitedbname/m-databasename=`date '+%d-%y'.sql

When I place the same command within my cron file - well, nothing happens. Of course, I want this command to execute, and create a sql backup.

I am wondering, do I need to place this command in a file?
If so, what naming convention should I use (i.e. filename.extension)?

Where should I place the file?

How do I call it from inside cron?

Naturally, cron presents only one solution for recurring calls, if there is a better solution that can run mysqldump, I'm very open.

Help?

(In the meantime I get to manually execute this script each day for all my client databases - phew, that's fun!)

MAC G4, Mac OS X (10.4.8)

Posted on Jun 6, 2007 5:03 AM

Reply
4 replies

Jun 6, 2007 6:28 AM in response to Scott SOSCS

Great Scott,

The problem with crontab is that it does not have a $PATH variable. As such, sh can NOT find the mysqldump command. As I see it, there are 2 ways around this problem.

1)Specify the full path to the executable. So instead of mysqldump, try /usr/local/mysql/bin/mysqldump

2)Instead of running the command from the crontab, you could have crontab launch a script. In the script make sure to set the $PATH variable to include the mysql directory.

Just so you know, crontab sends its output to mail. You can read the mail by typing:

$ mail

But mail is an old unix application. If you would like to send the mail to your mail account create a .forward file like this:

$ echo 'yourAccount@yourISP.com'>.forward

Then mail will send the output to your regular mail.

I hope this is of some help.

Your humble unix geek,




Kurt

Jun 6, 2007 8:27 AM in response to Kurt Sakaeda

Phew...

Perfect. I actually use a combination of solution 1 and 2. Here's why. I pushed the command into a script, and insured that cron was running - but still the *.sql files where empty.

I considered that path issue, and included the full path within the script.

/usr/local/mysql/bin/mysqldump

With both of these ideas incorporated - everything worked!

I can now remove myself from the corner of the room, and take off the dunce cap!

Thanks...

PS. I added the mail to my cron - very nice utility, a bonus!

Jun 6, 2007 9:29 PM in response to Kurt Sakaeda

But mail is an old unix application. If you would
like to send the mail to your mail account create a
.forward file like this:

$ echo 'yourAccount@yourISP.com '>.forward

Then mail will send the output to your regular mail.


And here's another handy crontab trick: you can also redirect the mail output to different accounts. Just add this line:

<pre class="command">MAILTO = name@domain.com</pre>before your cron jobs that you want to go to that email address. You can add a different email address later in the crontab before another set of jobs and the output from those jobs will go to the other email address.

charlie

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

mysqldump and cron

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.