1

I'm doing a cronjob task which creates a daily database backup. To desctinct the daily files, I name them as follows: dump- (the current date). The backup operation went well, but the date is not interpreted as it should be (dump-$(date '+%Y-%m-%d')) instead of dump-14-12-2018.

#filename=dump-$(date '+%Y-%m-%d')
#*/3 * * * * cd /bdd-backups/ && mysqldump --all-databases > 
$filename.sql -u xxx -pxxx

1 Answers1

2

It's hard to tell what your problem is, since you show us a file that's 80% commented out, but it looks like you are treating the crontab file as if it were a multi-line shell script.  It's not; each line is a self-contained, independent entity.  So you cannot assign a value to a variable on one line and use it on another line.

Either put everything on one line, or — and this is probably better in the long run — put the date, cd and mysqldump commands into a separate script file, and run the script from crontab.