creating tar file naming by current date backup never run
cron, linux, tar
Solution
Character `%` has a special meaning in the crontab file. It denotes a newline. Escape the `%` characters and the command should work as expected.
So instead of:
0 0 * * * tar czf /var/backups/file_$(date +%Y-%m-%d).tar.gz /home/files
Use:
0 0 * * * tar czf /var/backups/file_$(date +\%Y-\%m-\%d).tar.gz /home/files
Most modern cron daemons will not pass the `\` on to the shell. In case that happens, you might need to put the backup command in a separate script and then call it from crontab (that way cron daemon doesn't interpret `%` characters).
So stick the following into `/usr/local/cronscipts/my-backup-script`:
#!/bin/sh
tar czf /var/backups/file_$(date +%Y-%m-%d).tar.gz /home/files
And then modify your cronjob to call that script:
0 0 * * * /usr/local/cronscripts/my-backup-script.
Filenames and paths here are examples only, of course. Use what suits you best and remember to give the script right permissions ie. 0700 at least.
Problem
im using the following command to do daily backup for my files ``` 0 0 * * * tar czf /var/backups/file_$(date +%Y-%m-%d).tar.gz /home/files ``` my cron logs shows Nov 26 11:00:01 CROND[16646]: (root) CMD (tar czf /var/backups/file_$(date +) and i never get my files backuped , what do i miss in my command here