我如何在Debian上使用Cron进行每月备份(带有过期的文件名)?

我无法将date添加到备份文件的文件名。 这里是Cron命令(用于testing): */2 * * * tar -zcf /var/backups/www-(back tick)date +%Y%m%d(back tick).tgz /var/www/

它应该每2分钟运行一次,并创build一个名为www-20120212.tgz的备份文件,但是有一些错误。

“man crontab”说:

  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 

您需要使用\转义%字符,因为它会被cron不同地解释:

 */2 * * * tar -zcf /var/backups/www-`date +\%Y\%m\%d`.tgz /var/www/