10 July 2008

Rake task parameters

A stupid mistake I did and I'd like to share so people don't waste their time.

Don't use PATH or N as environment variables you want to use as parameters for your rake tasks.

I am creating a plugin to backup mysql databases with a crontab and I wanted to make things as simple as possible for the end user to use the plugin. I first came up with the following command

rake mysql_db:backup PATH=/tmp/pouet N=1

It was not working, giving error messages such as:

sh: mysqldump: not found
sh: gzip: not found

Writing this post, I reckon it is quite obvious I should not have used PATH as a parameter for a rake task .... No wonder it could not find gzip .... But I did not think about it in the first place and started looking at rake and ruby code!

So now the command is:
rake mysql_db:backup PATH_BACKUP=/tmp/pouet NUMBER_OF_DUMPS=1

By the way, is there more *elegant* way than environement variables to pass parameters to a rake task???

I am thinking I could use a prompt !

No comments: