Backup utility in linux

David david at kenpro.com.au
Sun Jul 10 05:29:16 UTC 2005


> 
> 2005/7/10, Stephen R Laniel <steve at laniels.org>:
> > On Sat, Jul 09, 2005 at 10:37:30PM -0400, C.B. wrote:
> > > Those of us new to Linux want to be able to hit the ground running.
> > > Finnessing the system can come later, but the learning curve is too
> > > much to try to do everything by CLI at first.

For my money, using linux without CLI is like driving a Ferrari in first 
gear. I run OSX and linux side by side. There are LOTS of things that i do 
even on OSX at the command line.. it's just plain quicker and easier and 
well worth the learning curve.

This is a cron script called backup_key_files.. I would be interested if 
those who actually know what they are doing think it works!

It might even be useful for someone, although I wouldn't guarantee it ;-)  
It's fully automated except for burning a dvd which I do manually. If you 
aren't into CLI, I've made some notes further down.

hostname:/etc/cron.weekly# cat backup_key_files
#!/bin/bash
# rsync /etc, /var/www, /var/cache/bind, /home /usr/local into /backup
# create a tar file in /tmp for burning to dvd
cd /backup
rsync -a --delete /var/www /backup 2> /dev/null
rsync -a /var/cache/bind /backup 2> /dev/null
rsync -a /etc /backup 2> /dev/null
rsync -a /home --delete 2> /dev/null
rsync -a /usr/local /backup 2> /dev/null
nice --adjust=19 tar -czf /tmp/`date +%y%m%d`.ns.tar /backup
touch `date +%y%m%d`
mail -s "backup ready to save" david at example.com < "." 1> /dev/null 
2> /dev/null

This is the breakdown of my intention:

hostname:/etc/cron.weekly# cat backup_key_files
 -- any executable placed in this directory will run once a week 
 -- for some reason it doesn't work if the script name contains dots!
#!/bin/bash
 -- you need this as the first line of a shell script
# rsync /etc, /var/www, /var/cache/bind, /home, /usr/local into /backup
# create a tar file in /tmp for burning to dvd
 -- this is just comment... these are the directories that i backup
cd /backup
 -- probably not necessary, but a good habit
rsync -a --delete /var/www /backup 2> /dev/null
 -- rsync is fantastic.. synchronises directories even on other hosts
 -- -a for archive, --delete to remove old files 2> to dump error messages
 -- this will maintain an exact copy of all my web pages in /backup
rsync -a /var/cache/bind /backup 2> /dev/null
rsync -a /etc /backup 2> /dev/null
rsync -a --delete /home /backup
rsync -a /usr/local /backup 2> /dev/null
nice --adjust=19 tar -czf /tmp/`date +%y%m%d`.ns.tar /backup
 -- create a single archive file of my backups
 -- you don't need "nice" ... you could just start at tar
 -- all nice does is give other tasks priority
 -- `date +%y%m%d` inserts todays date in the backup filename
 -- if you have lots of .jpg there's no point in the z - leave it out
touch `date +%y%m%d`
 -- I just do this for my own information, it's not necessary
mail -s "backup ready to save" david at example.com < "." 1> /dev/null 
2> /dev/null
 -- mail a reminder to myself to save to dvd.

the resulting single file is /tmp/050709.ns.tar which I then burn to a DVD 
or CD and put in my safe (in a different building to the computers!).

If there is a fire or my computers get stolen, or my system gets 
compromised, I've got all the critical data at hardly any cost or effort. 
Naturally, you are going to make your own decisions about which 
directories are worth saving. You could do the same thing daily if you 
thought it was a good idea. If I make a major change, I immediately 
manually run:

$sudo /etc/cron.weekly/backup_key_files

I finish up with a whole lot of old tar files in /tmp, and every now and 
then decide if they are just taking up space or whether I should delete 
them. After all, I've got them all on dvd anyway. 

The scenarios that worry me are:

a dead hard drive
a compromised system
theft
fire

I keep a log of all the software changes I've made to the base system in 
my /home and that's part of the backup. The last disaster I had was a dead 
hard drive, so I just built a new system from scratch, went through the 
software changes, then restored the data and config files from the backup 
cd. It wasn't pleasant, but it worked OK. As far as I can see, a dead hard 
drive and a compromised system are just about the same thing.

I think it's really important to keep your backups somewhere else. 

I used to have a hardware raid system on a server, but when one of the 
drives got partially corrupted, the raid dutifully copied the corruption 
onto the other drive! I'm not a sysadmin, so I'm not sure what should have 
happened, but that was not a pleasant experience. Plainly external backup 
is still necessary.

David.




More information about the ubuntu-users mailing list