Add date to mysqldump command

1.1k Views Asked by At

I want to have my db backed up and emailed to me (the size of my db is very small so email is not problem). I have the following mysqldump command in a cron running weekly and it is working perfectly.

mysqldump -e --user=username --password=password database | gzip | uuencode database_name.gz | mail [email protected]

All I want to do is add the current date of the backup to the gzip filename so each backup filename is unique. I have searched here for the answer and found this:

mysqldump -e --user=username --password=password database | gzip | uuencode $(date +%Y-%m-%d)-database_name.gz | mail [email protected]

But I get this error: unexpected EOF while looking for matching `)'

I tried a different version too:

mysqldump -e --user=username --password=password database | gzip | uuencode `date +'%Y%m%d'`-database.gz | mail -s "`date +'%Y%m%d'`-database.gz mysqldump backup"  [email protected]

But this also results in an error: unexpected EOF while looking for matching ``'

Any suggested solutions would be welcome.

1

There are 1 best solutions below

0
On BEST ANSWER

For those interested I found the solution:

mysqldump -e --user=username --password=pswd database | gzip | uuencode my-dbbackup.`date +"\%Y-\%m-\%d"`.gz | mail [email protected]