The Backup Process
No matter what operating system you are using, or what sort of database you are administering, it is absolutely necessary to back up the server frequently. There are many software products you can download—some free and some for a fee—that will handle backups quite eloquently. However, there are also shell commands that will back up your drives for you. And, of course, you can always write these as a script (which we will be covering in Chapter 13, “Shell Scripting”) and then schedule that script, and thus create your own backup utility.
You can use the Linux dd command to create full or partial hard disk back-ups. The following example illustrates a full backup from the source disk, labeled /dev/hda, to another target disk, labeled /dev/hdb, on the same system.
dd if=/dev/hda of=/dev/hdb
The if represents inputfile and is not a logical if. The of represents output file. This code literally says to take hda as the input file and write it to hdb. It’s not the most elegant backup solution, but it’s really easy.
The dd command has other options. For example, you may want to make an image of a partition. This is very common in corporate environments where one gets one workstation configured as needed and then makes an image of that to install on additional workstations. It is also often a good idea if you need to set up a test server, to set up an actual image of the live machine, so you can ensure that the test server is a good match for the live server. Making an image, like copying the drive, is very easy to do, and it takes just one line of code:
dd if=/dev/hda of=~/hdadisk.img
You can also use the dd command to restore a hard disk image as follows:
dd if=hdadisk.img of=/dev/hdb
Now you may want to copy the partition to a drive on another machine. This is a bit more complicated, but not overly so.
The netcat command can be used to clone or copy a hard drive. The following is the general format of the netcat command:
nc -l -p <portnumber> | dd of=/dev/hda
Then on the source machine, you can send the contents of the disk to the target PC:
dd if=/dev/hda | nc <ipaddresstarget> <portnumber>
An example of these two commands is given here:
dd if=/dev/hda | nc 192.168.0.100 40
As you can see, backing up the hard drive is quite easy. There is really no excuse for administrators not to have their servers backed up at least daily. And high traffic database servers, such as one finds in ecommerce distributions, are often backed up hourly.