anacron

Table of Contents

anacron is a program to schedule periodic task. Anacron assume your computer to not be running 24*7, and use timestamp to record last executed time of jobs. unlike cron, anacron will execute missed jobs.

1. Run user-level anacron

  1. Create a ~/etc/anacrontab and ~/var/spool/anacron to store jobs and timestamps.
  2. Then, put anacron -t ${HOME}/etc/anacrontab -S ${HOME}/var/spool/anacron in your ~/.bashrs or your crontab -e (which let you edit your user crontab), so that anacron is run at login time and/or every hour(as specified in your crontab)

cp /etc/anacrontab for template.

Backlinks

cron

(link)

see anacron

Here is a script using cron, anacron and rsync to backup my important files

0 *	* * *	linfeng	anacron -t ${HOME}/etc/anacrontab -S ${HOME}/var/spool/anacron

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin


1 0 /usr/bin/rsync -aAX --delete --exclude '*.Trash-1000' /home/linfeng/Dropbox/Notes/ /media/linfeng/backup/Notes/daily
7 10 /usr/bin/rsync -aAX --delete --exclude '*.Trash-1000' /home/linfeng/Dropbox/Notes/ /media/linfeng/backup/Notes/weekly
@monthly 15  /usr/bin/rsync -aAX --delete --exclude '*.Trash-1000' /home/linfeng/Dropbox/Notes/ /media/linfeng/backup/Notes/monthly_$(date +%Y%m%d)

Author: Linfeng He

Created: 2024-04-03 Wed 20:17