need to add current date in filename

i have a small shell script that backs up my databases. i want to change it so it adds the dats (YYYY-MM-DD) to the beggining of the filename, here it is.

#EXPORT TABLES
/usr/local/bin/mysqldump --opt --compress -hHOST -uUSER -pPASSWORD ldww_db TABLENAME >> backups/database/TABLENAME.dat.sql    

so basically it should be
backups/database/YYYY-MM-DD-TABLENAME.dat.sql

how do it do that? thanks!
qwertqAsked:
Who is Participating?
 
knollbertCommented:
/usr/local/bin/mysqldump --opt --compress -hHOST -uUSER -pPASSWORD ldww_db TABLENAME >> backups/database/$(date +%F).dat.sql
0
 
yuzhCommented:
use the following as the file name:

`date +%Y-%m-%d`.dat.sql

eg:

/usr/local/bin/mysqldump --opt --compress -hHOST -uUSER -pPASSWORD ldww_db TABLENAME >> backups/database/`date +%Y-%m-%d`.dat.sql


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.