Does cron/anacron retry failed tasks?
I'm writing a backup script, and I'm wondering if there's a retry mechanism built into cron/anacron? If not, is there a good way to build that into a cron/anacron script?
|
I don't know of any retry mechanism. You could have your backup script itself retry. If you want the retry to take place after some delay, you can have the script submit itself for future execution using the at command. (Edit: make sure you include a mechanism to prevent multiple instances from running if you have repetitive failure.)
There's a variation on this where you could have crond submit the job more frequently than you really want to run it, but have the script keep track of whether to do anything. For example, suppose you want to backup daily. You could have the script run hourly and touch a particular file when it succeeds. At the start of the script, it checks to see if that file exists and has a timestamp from today. If it does, it immediately exits. There are endless variations on that to meet your particular requirements. |
This is a laptop, so I really didn't want to touch any files because if the system is off AC power, I don't want to do a backup (no use waking up the hard disk). Furthermore, if it is not connected to the backup drive, then the script will also fail. These are fairly common occurances with my laptop.
I was actually thinking of using the at command.... But does the at queue survive a reboot? For example, if I have a cron job scheduled for 12:00 Noon every day, then if it fails (probably for the above reasons), I'd like to reschedule it anywhere from 2 to 4 hours (I haven't decided yet). So my question(s) are: 1. Does the at queue survive a reboot 2. If the task expires while the system is down (eg. I scheduled something for an hour from now, but an hour from now the system was not on), what happens? |
Quote:
Quote:
the queue, never to complete. Cheers, Tink |
Quote:
Code:
EXIT STATUS Quote:
EDIT: I was wrong. It is anacron that I have seen configured not to start when on battery rather than atd. However, if your computer works with laptop-mode enabled (TMK, it still causes some computers to "hang"), you can use laptop mode to dissable crond and/or atd while on battery. (From your posts, it sounds like you have enough knowledge to make this decision.) Even if laptop-mode does not work with your computer, I think you could accomplish the same thing with a small amount of hacking the init scripts and utilizing the /etc/acpi/ac.d and /etc/acpip/batter.d directories. (Do your own search as I haven't done this myself. But I have suppressed crond with laptop-mode.) |
A combination of "AT" and "fcron" might do the trick. "Fcron" can schedule its jobs relative to the time since boot up and many more nice things...
http://fcron.free.fr/ |
Thanks for all the help.
I've decided to use at, and wrote a wrapper script so tasks can reschedule themselves. Quote:
As far as tasks rescheduling themselves too much, if at any time a backup process is initiated when one is already running, I've written my script in such a way that it does not reschedule itself, so if I get a bunch built up, in theory, on the next reschedule point, they should all empty out at once. Last question, about anacron & cron... If I have a cron job scheduled for a particular time (such as a weekly backup), and the system is off when that job is scheduled, what happens? Will the job simply not be executed, or does anacron automatically pick up cron's slack?? Or should I just do an experiment to test this?? [edit] In fact, I've decided for the time being to use at exclusively, and have tasks reschedule themselves based on whether or not the backup was successful. I'm still curious about the above cron/anacron questions, though. Thanks. |
Quote:
OK. In previewing my post, I see I slightly misread yours. What I said above about crond is to the best of my knowledge true. But you asked about anacron. Anacron is a different beast that is logically separate from crond. Based on its own configuration file (/etc/anacrontab), anacron will schedule tasks that have not been run within the prescribed number of days (based on its own timestamp files). Neither anacron nor crond directly reference what the other does. But distros frequently provide linkage between the two such as:
@JZL240I-U, Thanks for the heads up about fcron. Its the first I've heard of it. |
I use fcron in combination with rsnapshot for backups in my home used workstation. First backup will run 2 minutes after boot (presumably before I change too many files), then every hour. Else daily, weekly and monthly backups are run, all scheduled by fcron.
Nifty thing, fcron. But I never touched cron(d), not knowing where in the system it is used by default. Never repair a runnung system... |
All times are GMT -5. The time now is 07:08 AM. |