Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper format for a mysqldump dynamic filename in a cron?

Tags:

cron

mysqldump

I have a crontab set up that errors out every time I attempt to do it. It works fine in the shell. It's the format I'm using when I attempt to automatically insert the date into the filename of the database backup. Does anyone know the syntax I need to use to get cron to let me insert the date into the filename?

mysqldump -hServer -uUser -pPassword Table | gzip > 
/home/directory/backups/table.$(date +"%Y-%m-%d").gz

Thanks in advance!

like image 971
Mobius Avatar asked Jul 20 '09 18:07

Mobius


1 Answers

What about something like this for the "command" part of the crontab :

mysqldump --host=HOST --user=USER --password=PASSWORD DATABASE TABLE | gzip > /tmp/table.`date +"\%Y-\%m-\%d"`.gz

What has changed from OP is the escaping of the date format :

date +"\%Y-\%m-\%d"

(And I used backticks -- but that should do much of a difference)

(Other solution would be to put your original command in a shell-script, and execute this one from the crontab, instead of the command -- would probably be easier to read/write ^^)

like image 96
Pascal MARTIN Avatar answered Nov 03 '22 14:11

Pascal MARTIN