View Full Version : crontab schedule backup help

2nd December 2008, 04:23 AM
Hello everyone.

So I'm trying to schedule a backup with cron that runs every day but friday at 6:30. I also wanted it to be logged.

Here is what I put in the crontab 30 18 * * 1,2,3,4,5,6 tar -cpf /backup/databack.tar /data > /var/log/backlog.log

To test my command I used the same command but changed the time schedule to 2 * * * *. That should make the backup run every 2 minuets correct?

The problem is I don't see the backup file being created in the target directory nor is there a log file created.

Any help would be appreciated.

2nd December 2008, 05:15 AM
Some common things to check: Did you wait 1 minute for the crontab to reload? The cron will only look at the user crontabs every minute, so you have to wait 2 minutes for a test run to execute (unless you haven't made any changes to the crontab).
Do you have permissions to write to that file from the user who's crontab you're editing? ie, you should be root if you're writing to /var/log.
What happens when you run "tar -cpf /backup/databack.tar /data > /var/log/backlog.log" manually?
You should use the &> redirect so that stderr (error output) is also included in the log:
1,2,3,4,5,6 tar -cpf /backup/databack.tar /data &> /var/log/backlog.log
Make sure /backup exists before hand and the user has permissions to write to it, as I don't think tar will create /backup for you.


2nd December 2008, 05:26 AM
Ok, so If I run tar -cpf /backup/databack.tar /data > /var/log/backlog.log by itself the backup file is created, but yeah the user is blocked from creating the log file.

If cron is running it should still at least create the tar file correct?

2nd December 2008, 05:26 PM
Yeah, tar should still execute even though it can't write the output to /var/log/backlog.log...
Try this:

crontab -r
crontab -e
Now add the line back:

30 18 * * 1-6 tar -cpf /backup/databack.tar /data &> /tmp/backup.log
then exit the editor and run in the terminal again:

rm /backup/*.tar
Then wait until tonight at 6:30 and check /tmp/backup.log for any errors.

2nd December 2008, 06:43 PM
Ok, it actually is working. I had changed the crontab to 2 * * * * and was wrongly expecting it to run every 2 mins when it was in fact going to run every hour 2 mins in. Once I had figured that out I knew what as going on.

Thanks for the help Firewing1.

3rd December 2008, 02:49 AM
if you want it to run every two minutes do this:

*/2 * * * *

4th December 2008, 01:39 AM
if you want it to run every two minutes do this:

*/2 * * * *

Thanks, I'll try to keep that one in mind.