Proper format for a mysqldump dynamic filename in a cron?

12,113

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 ^^)

Share:
12,113
Young L.
Author by

Young L.

PHP and Mysql Sharepoint :( Asp.net MVC in VB and C#

Updated on June 04, 2022

Comments

  • Young L.
    Young L. almost 2 years

    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!