Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having trouble adding the date to the backup file's filename. Here's the Cron command (for testing): */2 * * * tar -zcf /var/backups/www-(back tick)date +%Y%m%d(back tick).tgz /var/www/

It should run every 2 minutes and create a backup file called www-20120212.tgz, but there's something wrong.

share|improve this question
This is probably a typo, but you don't have enough fields at the start of your line. You probably want to put another * in before the tar command. – Daniel Lawson Feb 12 '12 at 20:12

'man crontab' says:

 The sixth field of a line in a crontab file is a string that
 is  executed  by the shell at the specified times. A percent
 character in this field (unless escaped by \) is  translated
 to a NEWLINE character
share|improve this answer

You need to escape the % character with an \, as it will be interpreted differently by cron:

*/2 * * * tar -zcf /var/backups/www-`date +\%Y\%m\%d`.tgz /var/www/
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.