A Very Simple Backup Script

If you are in a situation where you need to get up and running a quick but "sofisticated" backup system which would allow you to easily restore your system to a specific point in time, you might want to give AVSBS a try.

AVSBS, itself is quite short. AVSBS brings the power of the commands cat, find, tar, cpio, gzip, rm, mv, mail and ssh together to give you a fairly secure and powerful backup system.

AVSBS is not meant to replace enterprise, "industrial strength" solutions such as Bacula or Amanda. If you need a highly complex backup system (centralized, network - based, fancy features ;-), etc...) you might want to look at these. However if you just want to backup a bunch of files on one / more servers and be able to restore the systems relatively easily, you might want to give AVSBS a try.


How AVSBS Works

AVSBS is comprised of two main awk scripts. One that does "incremental" backups and the other that does "full" backups. The incremental backup script is called "bk-incremental.awk" and the full backup script is called "bk-full.awk".

All you need to do is provide these two scripts (see Implementation Detail) with a list of files / directories to be backed up and you're ready to go.


Example

The typical operation of AVSBS is best explained with an example. Let's say you have a policy that says that you must maintain a full backup of the system, which is taken every month and you must be able to restore the system to it's state on any day of the month.

All you would need to do is configure the full backup script (bk-full.awk) to run as a cron job every month and configure the incremental backup script (bk-incremental.awk) to run as a cron job every day, and that's it!

All you would need to do, in order to restore your system to any particular day is - (a) Decide on which day (b) choose which month you wish to restore the system to (in the case where you have preferred to have multiple snapshots) (c) untar the full backup corresponding to that month (d) untar the incremental backups corresponding to that month, chronologically until the day you wish to restore the system to.


Implementation Detail

1.Open the file bk-full.awk and customize the variables. You will find the necessary instructions in this file.
 
2.Open the file bk-incremental.awk and customize it in the same way as above.
 
3.

Configure passwordless SSH between your server and the backup machine.

On the machine which you are going to run the backup scripts (the one set as the 'mother_host' parameter in the scripts), generate your public/private key pair (if you do not already have these).

beg_g@nemesis:~ > ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/beg_g/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/beg_g/.ssh/id_dsa.
Your public key has been saved in /home/beg_g/.ssh/id_dsa.pub.
The key fingerprint is:
84:78:49:ef:7f:71:5a:62:d6:8c:74:79:68:6e:cb:eb beg_g@nemesis.eahd.or.ug
beg_g@nemesis:~ >
 
Run the command ssh-keygen -t dsa
When prompted for the file, you may keep the default (press enter)
When prompted for the passphrase, press enter
When prompted to confirm the passphrase, press enter again

Your public key will have been stored in the file "id_dsa.pub" in the directory you specified during the key-generation stage (in the case above, this was /home/beg_g/.ssh/).

Next, copy your public key into a file on the remote machine (the machine where the backups will be sent) called "authorized_keys". This file should typically be saved in the ~/.ssh directory i.e the .ssh directory in your home directory (something like /home/user/.ssh).

It is important to ensure that the permissions of the following relevant files / directories are as follows:

.ssh should be 0700
.ssh/authorized_keys should be 0600

 
4.Set a cron job for bk-full.awk to run as dictated by your policy (see example above).
 
5.Set a cron job for bk-incremental.awk to run as dictated by your policy (see example above).
 

Download

Click Here to Download AVSBS


Author

Gerald Begumisa <gbegumisa@yo.co.ug>
Yo! Uganda Limited
www.yo.co.ug

This software was implemented while the author was working with Computer Frontiers International