6 Examples To Backup Linux Using DD Command
6 Examples To Backup Linux Using DD Command
Data loss will be costly. At the very least, critical data loss will have a financial impact on companies of all sizes. In some cases, it can cost your job. Ive seen cases where sysadmins learned this in the hard way. There are several ways to backup a Linux system, including rsync and rsnapshot that we discussed a while back. This article provides 6 practical examples on using dd command to backup the Linux system. dd is a powerful UNIX utility, which is used by the Linux kernel makefiles to make boot images. It can also be used to copy data. Only superuser can execute dd command. Warning: While using dd command, if you are not careful, and if you dont know what you are doing, you will lose your data!
if represents inputfile, and of represents output file. So the exact copy of /dev/sda will be available in /dev/sdb. If there are any errors, the above command will fail. If you give the parameter conv=noerror then it will continue to copy if there are read errors. Input file and output file should be mentioned very carefully, if you mention source device in the target and vice versa, you might loss all your data.
In the copy of hard drive to hard drive using dd command given below, sync option allows you to copy everything using synchronized I/O.
# dd if=/dev/sda of=/dev/sdb conv=noerror,sync
The above creates the image of a harddisk /dev/hda. Refer our earlier article How to view initrd.image for more details.
The image file hdadisk.img file, is the image of a /dev/hda, so the above command will restore the image of /dev/hda to /dev/hdb.
# dd if=/dev/hda1 of=~/partition1.img
dd command reads one block of input and process it and writes it into an output file. You can specify the block size for input and output file. In the above dd command example, the parameter bs specifies the block size for the both the input and output file. So dd uses 2048bytes as a block size in the above command. Note: If CD is auto mounted, before creating an iso image using dd command, its always good if you unmount the CD device to avoid any unnecessary access to the CD ROM.