anacron + backup

Larry Grover lgrover at zoominternet.net
Tue Aug 23 13:39:17 UTC 2005


Martin Ericsson wrote:
> 
> Hi,
> I want to do a daily backup of my home directory onto a partition on 
> another HD and save the last seven backups.
> 
> Question 1:
> How do I make a script to perform that kind of backup?


I've been using "rsnapshot" (in the universe respository, I believe) 
to do this.  There's a nice article on rsnapshot that should get you 
going here:
http://enterprise.linux.com/enterprise/05/04/26/1921236.shtml

Also take a look at the rsnapshot home page, it has some very helpful 
documentation:
http://www.rsnapshot.org/

I really like rsnapshot, but it's fun to create your own solution. 
You can do this with cron (anacron, too, if your system is not up 24 
hr/day) and your scripting language of choice:

(1) write a script which uses some type of backup/archive tool (cp, 
tar, rsync, scp, etc) to copy/archive specific files/directories
(2) create a script in /etc/cron.daily which executes the script you 
wrote in (1)
(3) make sure both scripts are executable


> Question 2:
> I've noticed that both anacron and cron are installed on my hoary 
> system. Since I don't have my computer running 24/7 I don't see the need 
> for cron, but it's marked as suggested (or recommended, don't remember) 
> by anacron.
> 
> Running ps ax | grep cron just gives me cron, so I guess that anacron 
> uses cron somehow? But I can't figure out just how. anacrontab says:
> 
> 1       5       cron.daily       nice run-parts --report /etc/cron.daily
> 7       10      cron.weekly      nice run-parts --report /etc/cron.weekly
> @monthly        15      cron.monthly nice run-parts --report 
> /etc/cron.monthly
> 
> and in i.e. cron.daily there's a file called 0anacron. So it seems like 
> anacron calls cron which calls anacron? Could somebody explain the setup 
> to me so I know where to but my scripts?


Here's how I understand it:

Anacron is run when your system starts up (look at /etc/init.d/anacron 
to see how this works).  Anacron looks in it's config file 
(/etc/anacrontab) to see which jobs it needs to monitor.  If the job 
has been run within the interval specified in /etc/anacrontab, then 
the job is skipped, otherwise anacron executes the job.

Anacron is typically set up so that it monitiors the same jobs as 
cron.  The lines in your anacrontab which include "run-parts" tell it 
to monitor and execute if necessary all the scripts inside the 
specified directory (see the man page for run-parts for a more 
detailed explanation).  Anacron is set up this way to make sure that 
the jobs specified in the configuration files for cron 
(/etc/cron.daily, /etc/cron.weekly) are run even if the system is down 
when cron would normally run those jobs (usually sometime in the early 
AM).  So anacron is not actually running cron, instead it is using 
cron's configuration files.

Anacron doesn't have to be set up this way, but it is very useful to 
use it in this way to make sure that the system maintenance jobs which 
are normally run by cron are run on systems which normally are not up 
24 hr/day (like laptops and desktops used as personal computers).

Regards,
Larry




More information about the ubuntu-users mailing list