I'm trying to automate a nightly backup with the following cron jobs (IPs and password redacted. of course):
[root@katexic ktxc]# crontab -l
30 3 * * * /bin/tar -czf /backup/ktxc/ktxc-`date '+%m%d%y'`.tar.gz /var/www/ktxc.to;scp -i /root/.ssh/id_rsa /backup/ktxc/ktxc-`date '+%m%d%y'`.tar.gz backup@111.22.33.44:/home/backup/backups
45 3 * * * /bin/tar -czf /backup/katexic/katexic-`date '+%m%d%y'`.tar.gz /var/www/katexic.com;scp -i /root/.ssh/id_rsa /backup/katexic/katexic-`date '+%m%d%y'`.tar.gz backup@111.22.33.44:/home/backup/backups
00 4 * * * /usr/bin/mysqldump -u ktxc_yourls -pxxxpasswordxxx ktxc_yourls | gzip > /backup/ktxc/ktxc-mysql-`date +\%m\%d\%y`.sql.gz;scp -i /root/.ssh/id_rsa /backup/ktxc/ktxc-mysql-`date '+%m%d%y'`.sql.gz backup@111.22.33.44:/home/backup/backups
These work fine from the command line, but not when the cron daemon tries to run them. In the /var/log/cron
I see messages like:
Jun 10 03:30:01 katexic CROND[7437]: (root) CMD (/bin/tar -czf /backup/ktxc/ktxc-`date '+)
Jun 10 03:45:01 katexic CROND[7445]: (root) CMD (/bin/tar -czf /backup/katexic/katexic-`date '+)
I assume that there's some problem with the +
sign in my commands? How do I fix these so they run properly as cron jobs?
This isn't solved by the troubleshooting in Why is my crontab not working, and how can I troubleshoot it? because that doesn't, afaict, cover special characters and the like and the error in the log is the same as cron sends to my email.