Background: I want to backup some files on my laptop on a daily basis, and there are times when the laptop is shut down for several days in a row.

I tried scheduling the backup as a cron job and using anacron to execute missed jobs, but was not sure about the way anacron works.

If, for example, I start the laptop after a 3-day shutdown, will anacron execute all 3 missed backup jobs? If this is true, what is the best way to stop anacron from executing jobs delayed for a certain length of time (> 1 day in this case)?

2 Answers 2


If you have an anacron job that runs a daily backup, and your system is down for three days, anacron will run the job once when the system comes online on the fourth day.

To elaborate, anacron allows you to specify commands to be repeated periodically with a frequency specified in days. When anacron is invoked (which can happen at boot time, and also during predefined hours of the day), it will read a list of jobs from the /etc/anacrontab configuration file. For each job, anacron checks if the job has been executed in last n days. For a daily job, this will be the last 1 day, i.e. today. If the job has not been run in this period, anacron executes the job.

Once the job runs to completion, anacron records the date of execution in a file, under /var/spool/anacron. This file is used to check the job's status when anacron is invoked the next day.

Since anacron only looks at the days elapsed since last execution and the configured frequency of execution, there is no problem of a job being executed multiple times.

A daily anacron job can be set up in the /etc/anacrontab configuration file using the following syntax:

1 15 backup-job /path/to/backup/script.sh

1 is the frequency of executing the command specified in days, 15 is a delay in minutes added to the execution of the job, 'backup-job' is an identifier, and '/path/to/backup/script.sh' is the command to be executed. You can take a look at man 8 anacron and man 5 anacrontab for more details.


In such way the best you can do is to create lock file when the backup is started and remove it on the end of the script. Of course before create you should check if lock file exist and just stop the script if yes. Be careful to check when script is killed from external party and lock file still exist.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .