Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

2 Answers

'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
add comment

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
add comment

Your Answer

 
discard

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.