On 18/07/2024 18:18, Patrick O'Callaghan wrote:
On Thu, 2024-07-18 at 14:12 +0700, Frederic Muller wrote:
Hi!
Following up on a old question of mine about daily backup tools I did
follow the advice and am using borg successfully. So thank you for
that:
very easy to setup and works great.
However wanting to do that daily automatically from my laptop to a
local
network drive I looked for a way to start the backup like 10 minutes
after I switched on the PC and only once a day which led me to
anacron.
Installed it, set up the anacron job and the problems arrived.
Initially
tried to run it as my user but that didn't work.
@daily 10 daily-backup su fred -c
"/home/fred/dao2/tech/daily.sh"
Simplified the command to run as root but that also didn't work. It
seems anacron doesn't run.
@daily 10 daily-backup /home/fred/dao2/tech/daily.sh
Finally found one or two post saying you can add a cron job that runs
hourly and launch the anacron tasks.
I have this in my user crontab:
@hourly /usr/sbin/anacron -s -t $HOME/.anacron/etc/anacrontab -S
$HOME/.anacron/spool
This unfortunately get the task run randomly and definitely not once
per
day. I sometimes get it to run 3 or 4 times in the same day while
sometimes I feel it's does not run and so I run it manually.
So my question is how do I get anacron "fixed" and running once
daily?
Anacron probably isn't the right tool for this, since you don't want to
run the backup at a fixed time but "10 minutes after I switch on the PC
and only once per day". Unless you always switch on the PC at the same
time, you may be better triggering the job at boot time. You can
trigger something at boot by using the "@reboot" keyword (crontab(5)).
You'll want to run a script that a) checks if backup has already run,
and b) waits 10 minutes before running it. You can check if it has run
by adding a hook to your backup script that just logs the last time it
finished successfully.
BTW, I recommend using borgmatic for regular borg runs, but you still
have to take care of the timing yourself.
poc
I hear you. Now I went the anacron direction as the man page just says that:
"Description
Anacron is used to execute commands periodically, with a **frequency
specified in days**. Unlike cron(8), it does not assume that the machine
is running continuously. Hence, it can be used on machines that aren't
running 24 hours a day, to control regular jobs as daily, weekly, and
monthly jobs.
Anacron reads a list of jobs from a configuration file, /etc/anacrontab
(see anacrontab(5)). This file contains the list of jobs that Anacron
controls. Each job entry specifies a period in days, **a delay in
minutes**, a unique job identifier, and a shell command.
For each job, Anacron **checks whether this job has been executed** in
the last n days, where n is the period specified for that job. If not,
Anacron runs the job's shell command, after waiting for the number of
minutes specified as the delay parameter. "
So it runs daily, allow for a delay when starting and supposidely checks
whether the job has been executed... seems like what I was looking for no?
And arguably modifying my backup script to check if it ran today already
and then run it if not will probably be faster than troubleshooting
anacron at this point. ;-)
Thank you.
@Mike I also read that on systemd distro cron and anacron are things of
the past and we should be looking at systemd timers... so thank you for
that.
Fred
--
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue