Create an automatic backup using anacron

With cron, you schedule a job at a specific time and date. It assume that the machine is running continuously. But what if the machine is down? You have to wait until the next schedule and so on. This is where anacron can be useful. Using it you can schedule tasks on a daily, weekly or monthly basis. It is indeed an advanced cron.

Anacron can be used to execute commands periodically with a frequency specified in days. For each job, Anacron checks whether this job has been executed. If not, Anacron runs the job's shell command, after waiting for some minutes which is specified in the delay parameter. If there is no more job to be run anacron exits.

While cron  can be specified to run at any intervals as small as a minute. Anacron on the other hand can be run in intervals of days.

This won't be a problem if you are taking backups.

We will setup an rsync backup for a system.

[chia$]  su -c  'vim /etc/anacrontab'

Add the following line

1 10 backup rsync -auz -e "ssh -i /home/user/.ssh/rsync" /file username@ipaddress:~/backup

This means that the command will run every day(1st parameter) with a delay parameter of 10 minutes(2nd parameter) and identify the job in logs as 'backup' (3rd parameter)

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.