Using date to add filename to database backups made by cron
I want to maintain multiple dated backups via cron, but I can't figure out how to concatenate the filename in cron.
Currently I am just using the following:
/bin/mv /var/www/vhosts/mysite.org/dbBackups/today.sql /var/www/vhosts/mysite.org/dbBackups/yesterday.sql
/usr/bin/mysqldump --add-drop-table -u dbname -pmypass dbname > /var/www/vhosts/mysite.org/dbBackups/today.sql
What I tried was not good:
/usr/bin/mysqldump/mysqldump --add-drop-table -u dbname -pmypass dbname > '/var/www/vhosts/mysite.org/dbBackups/' . date +%Y%m%d . dbname.sql
So how can I concretize this line in cron?
+2
source to share
4 answers
Put the date command in back quotes and remove the spaces:
/usr/bin/mysqldump/mysqldump --add-drop-table -u dbname -pmypass dbname > /var/www/vhosts/mysite.org/dbBackups/`date +%Y%m%d`dbname.sql
In (at least) bash, you can also use the syntax $(some command)
instead of backquotes. Not sure if it will work for cron, but you can try if you prefer this style (one advantage of this style is that they can get up without any problem).
+1
source to share