I want to make a cron job that creates a tar of my web directory.
I have this job in place
* * * * * tar -zcvfp /disk1/archives/websites/`date +%Y-%m-%d_%I-%M-%S-%p`/`date +%Y-%m-%d_%I:%M:%S:%p`.tar.gz /web
this job SHOULD (but doesn't) create a tar file to my /disk1... directory. so I'm stumped on that one.
another thing that has been on my mind is, is it possible to make all backup tar file get dumped into a date +%Y-%m-%d
and have all files that were created on that same day be placed there?
So an output would look like
/disk1/archives/websites/2012-02-05/2012-02-05_5:25:04.tar.gz
I have made this job run every minute for test purposes.
Is there anything wrong with my syntax?
cron
does not know whattar
ordate
is because it doesn't have environment variables. Reffer to the binaries using their full path.If you don't know the full path, use
which
to get it.Ex:
This would make your cron-line this:
Put your tar inside a shell script, say,
/usr/local/bin/backup.sh
. Then call that script from cron.The trick is that cron is not a shell, so things that work in shell expansion may not work in crontabs. It's much, much safer and easier to debug to put your commands into a script, and then call that script (by it's full path).