Ubuntu – Confusion about cron and anacron (setting up backup schedule for rsnapshot)

16.04anacroncronschedule

I am trying to set up a not too complicated backup schedule with rsnapshot on a laptop running Ubuntu 16.04 LTS. The plan is to retain two daily backups and 24 hourly backups. I think this is the first time that I am ever having to do anything with cron or anacron. So I have not only one but several questions that I am confused about and would be very happy to get some answers to, since I found some seemingly contradictory information about certain points and was not able to find any clear resolutions to them.

Since I am really confused about quite a few things I had to be rather longwinded to make my questions clear. I hope you can bear with me here. For the TL;DR folks, I have highlighted the actual questions in bold typesetting.

My crontab looks like this:

    # m h dom mon dow user  command
    17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
    25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
    52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
    #

and the anacrontab looks like this:

    # These replace cron's entries
    1   5   cron.daily  run-parts --report /etc/cron.daily
    7   10  cron.weekly run-parts --report /etc/cron.weekly
    @monthly    15  cron.monthly    run-parts --report /etc/cron.monthly

That is the standard after a clean install of Ubuntu 16.04 Desktop version.

Since I suppose the system normally has a bunch of other cron and anacron jobs set up I figure I should better not mess with this standard configuration.

However, I am slightly confused about the way the two work together, and about possible complications with their working together with my planned backup schedule.

First of all, I understand that cron is a daemon that runs its tasks exactly as scheduled in the crontab if the computer is running at the specified time. Otherwise the job cannot be done. Okay. Simple.

Then there is anacron about which I have read some seemingly contradictory information. The most simplistic information out there is that "anacron can do scheduled tasks even if the computer is not turned on at the specified time. They will then be carried out whenever the computer is actually turned on again. So it is suited for desktops that do not run 24/7." Okay. Sounds nice. Seems like that's what I want.

Some places I've read that anacron is a "daemon", then at other places (like here on askubuntu.com) it is pointed out that anacron is actually run as a cronjob (as demonstrated by the standard crontab above). Or can it be both according to different setups? And how can I know?

Then there is the information that "anacron does not do hourly jobs, or anything in periods of less than a day". This seems to fit with this standard setup of the crontab and anacrontab above after a clean install of Ubuntu 16.04 where only the daily, hourly and monthly jobs are relayed to anacron, and /etc/cron.hourly is handled directly by cron, and as I have read that the first two tabs in each anacrontab entry specify the period of the scheduled task in days (1 day for /etc/cron.daily in this case, for example, and 7 days for /etc/cron.weekly – seems to fit well) and the waiting period in minutes after the first system startup of the day (or I guess rather after anacron startup; so 5 minutes for cron.daily, and 10 minutes for cron.weekly), this would make sense as well. Okay.

However, on a German Ubuntu Wiki (wiki.ubuntuusers.de) I read that anacron now can do hourly jobs as of Ubuntu 14.04. But there is no description of how to do it, and I have not found any statements to that extent anywhere else, and I don't see how one should specify an hourly job in the anacrontab. So another question is: Can anacron "as of Ubuntu version 14.04" be used to do hourly jobs? If so, how?

The first really mystifying question that arises here for me is: If cronjobs are run only at the specified time, and there are these different cronjobs set up for running anacron to carry out the tasks in /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly, at 6:25, 6:47 and 6:52 respectively – then what if the computer is never actually turned on that early in the morning? Then anacron is never actually run or what? How can anacron "do better than cron" in some sense (i.e., doing tasks later than scheduled if the computer was shut down in between) if anacron relies on cron?

So these are my questions about cron and anacron.

Then I have also questions about rsnapshot proper which I guess I should better relay to a new question topic.

Thanks for reading, and any clear answers are very much appreciated.

Best Answer

As far as I understand it .... anacron is not a daemon and is ran by cron. cron runs at boot and runs anacron. anacron checks to see if something its programmed with has missed its schedule and runs it.

Since this is the way I see it ... it would seem that you would want the daily job set in anacron. As for hourly in anacron .. I also haven't seen anything on how it can be setup so I would put the hourly backup in cron.

I know this doesn't explain it that well but ... I guess it confuses me too. I'm sure someone here can come up with a better, more satisfying answer but I figured I would generalize it.