Linux Backup use of dd

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值