Data loss will be costly. At the very least, critical data loss will have a financial impact on companies of all sizes.
The ‘ dd ‘ command is one of the original Unix utilities and should be in everyone’s tool box. It can strip headers, extract parts of binary files and write into the middle of floppy disks; it is used by the Linux kernel Makefiles to make boot images. It can be used to copy and convert magnetic tape formats, convert between ASCII and EBCDIC, swap bytes, and force to upper and lowercase.
Backup Entire Hard drive
To backup an entire copy of a hard disk to another hard disk connected to the same system, execute the dd command. The UNIX device name of the source hard drive is /dev/sda, and device name of the target hard disk is /dev/sdb.
# dd if=/dev/sda of=/dev/sdb
In the copy of hard drive to hard drive using dd command, sync option allows to copy everything using synchronized I/O.
# dd if=/dev/sda of=/dev/sdb conv=noerror,sync
Backup a Partition
You can use the device name of a partition in the input file, and in the output either you can specify your target path or image file as shown in the dd command example below.
# dd if=/dev/sda1 of=~/part1.img
dd command allows to create an ISO file from a source file.
We can insert the CD/DVD and enter dd command to create an ISO file of a CD/DVD content.
# dd if=/dev/cdrom of=rhel7.iso bs=2048
Create an Image of a Hard Drive
Instead of taking a backup of the hard disk, you can create an image file of the hard disk and save it in other storage devices.There are many advantages to backing up your data to a disk image, one being the ease of use. This method is typically faster than other types of backups, enabling you to quickly restore data following an unexpected catastrophe.
# dd if=/dev/sda of=~/sda_disk.img
Restore using Hard Drive Image
To restore a hard disk with the image file of an another hard disk, use the following dd command example.
# dd if=sda_disk.img of=/dev/sdc
Creating a Floppy Image
Using dd command, you can create a copy of the floppy image very quickly. In input file, give the floppy device location, and in the output file, give the name of your floppy image file
# dd if=/dev/fd0 of=floppy0.img
In order to backup only the first few bytes containing the MBR and the partition table you can use dd as well.
dd if=/dev/vda of=/path/to/image count=1 bs=512
dd if=/path/to/image of=/dev/vda
Add “count=1 bs=446” to exclude the partition table from being written to disk. You can manually restore the table.