0

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.

Linksku
  • 1
  • 1
  • 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

2 Answers2

3

'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
NoNoNo
  • 1,963
  • 14
  • 20
1

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/
Sven
  • 98,649
  • 14
  • 180
  • 226