Backup and Restore
A hard disk can be composed of many things but essentially the only data it holds is a series of 0 (zero's) and 1 (ones) most of what is contained within a hard disk therefore is empty space ie a 0 (zero's) that being the case it should be possible to design an algorithm that takes advantage of this and save only the data needed, well we have news for you such an application is already available.
Now without going into it too much, compression utilities are very good at compressing empty space, take a look at any text file - look at it in the terms of the space it leaves behind. If you could delete all the blank spaces it may be unreadable to you, but think of all the space you would save, ok this is a very simplistic view but you can understand from this the principle that compression employs. Compression tools take advantage of this principle no matter who makes them or the type of algorithm it uses.
What has this to do with backup and restore well quite at lot really, when you backup up something you do you want to backup or restore empty space, well no ok course you don't. However when we recover from a disaster we need to restore the volume intact the data and the empty space, if this for any reason is missing it is possible the OS will fail to work properly due to lack of working space.
Let's look at some options based on generic installation scenarios and the problems that may arise when accomplishing a backup. Most people, not all will install an operating system without consideration for the data in comparison to the operating system installed. That is to say the data will resided on the same partition as that of the Operating System that will run it.
Usual or Standard Linux Configuration
Lets look at Ubuntu as an example, generally though this is true of almost any Linux distro, during the installation the user has the option of an automatic partition configuration or manual. The automatic configuration is what most people go for this consists of a primary partition to be used as a swap file and an extended partition that is bootable which holds the Operating System and the Personal Data all this on one volume partition no matter the size of the hard disk being installed to.
There are various, numerous was of backing up data but this is not quite what we want to do, we want to backup the system so we at any time can restore with the minimal amount of fuss. This means whatever method we decide to backup with it needs to have a small footprint so dependency on other system files are low or non existent. Most backups systems consider only data and not the quick recovery of an operating system from a catastrophic failure, such backups are possible but they are not simple and often require a base install to start with and the installation of the application, aside from this there is the recovery of the files with existing permissions this is very much an ongoing problem with existing backup applications, not so much the reading of the files but the writing back of the original permissions and there files but only as backup user, all permissions will be re-written as the user of the application backup-user or yourself.
On Linux your root file system consists of "/" or root "/boot", "/etc", "/var" and "/home" plus a few others not listed here. Your data where all of your data is saved to, the home directory and specifically you the user in the home directory. So if with wanted to backup to the home directory the contents of the entire system so we can restore it anytime later. We use a command called "dd" dd stands for Data Definition and perhaps something you would not normally consider using for purposes of a backup, however this is an extremely useful command it has no gui equivalent that we are aware of so can only be used from the command line. This command has loads of other uses but we are only interested at this time in the backing up of a drive.
If we accept the above configuration and we want to back up the entire drive we immediately hit a recursive data problem look at the following example.
Obviously you can call the file anything you like. (if=input file Reading or device of=output file or device Writing)
The command used above can be used with compression but this is useless as we still have the recursive problem, look at it this way because we are backing up the home directory in addition to the remainder of the file system then as restore_fs.bk grows then so does the files in the home directory grow this could mean that your backup may never exit until the limits of the hard disk are exceeded. The solution such as it is to build the restore file to another system however this is very impractical but possible using "netcat".
A better way is to build you partitions with consideration given for the Operating System the Booting partition and the Data or home directories each on a separate partitions. Its worth pointing out at this point that you never need to backup the swap partition even if it changes or gets deleted or corrupted, however from a restore you may need to recreate the swap partition depending if the original drive was damaged in any way.
Our Suggest Hard Disk Partitions Settings
We suggest you plan from the outset how you intend to partition your drive, we have some suggestions below which you might like to follow. If you use the suggested settings then the backup feature used in this tutorial will be very straight forward, if you choose to use your own partition management system then you will have to alter certain variables in order to accomplish the assigned task.
2Gb = /boot (Partition 1) referred to as /dev/hda1 or /dev/sda1 system dependent512Mb = swap (Partition 2) referred to as /dev/hda2 or /dev/sda2 system dependent
10Gb = / (Partition 3) referred to as /dev/hda3 or /dev/sda3 system dependent
20Gb or Greater = /home (Partition 4) referred to as /dev/hda4 or /dev/sda4 system dependent
The advantage of the above drive partition management clearly is that for the first time we can backup each drive partition independently of one another of course we still have a problem backing up the "/home" because of the recursive problem, but we can get around this using another method or a dependent backup application.
Because we are not backing up the home drive "/home" and it exists on another partition we can now easily write to our own data directory as a file without the occurrence of the recursive data writing using the following command.
Now we have a complete backup of the partition located "/dev/hda3" or sda3 whichever is relevant we know this because whatever the size of its contents on that partition the restore_fs.bk exactly matches the partition size created for that partition. this is where the compression comes in by using the following command. You need never worry about permissions as the drive is restored to its last saved state and the permission are retained intact whatever they may be.
Running this command compresses the file to less than twice it's original size (niffty a) now lets compound the statement into one command stitching the two commands together in effect.
Do not use sudo for any of the following statements rather we suggest you first switch to user "root" this can be achieved using the following command.
You will be asked for your password unless you are using a liveCD, you need to switch user as user root due to the devices you will be writing to.
You can substitute hda with sda dependent on your system now the file saved is a much more respectable size and provided you have a writable dvd drive and your file size is accommodating you can burn this file to a blank dvd disc. Now all you need do is write a script to run this backup utility on a set basis however bear in mind these are large files being created and will gobble up your data directory very quickly on an automated process.
Catastrophic Failure System Restoration
Here is the procedure with which you can recover from, it will of course depend on the state of the drive you wish to write to. But provided the drive is ok and it's failure is down to user error rather than system failure you can depend on the recovery using the commands below. To access this as the file system which won't be working, you will first need to use a liveCD gain access to the mounted volume that holds the image of the partition taken previously.
These pages have been created so you can just copy and paste the command directly you can use "sudo"/b> on some of the commands above but the commands themselves are distro independent so should work on any Linux system or liveCD for that mater.

