Backup Your Server Using dd command

Valic —  April 17, 2011 — 1 Comment

dd is a common Unix program whose primary purpose is the low-level copying and conversion of raw data.

dd is used to copy a specified number of bytes or blocks, performing on-the-fly byte order conversions, as well as more esoteric EBCDIC to ASCII conversions. dd can also be used to copy regions of raw device files, e.g. backing up the boot sector of a hard disk, or to read fixed amounts of data from special files like /dev/zero or /dev/random.

In this article i will provide you some 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.

1. Backup Entire Harddisk

dd if=/dev/sda of=/dev/sdb

  • “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

2. Create an Image of a Hard Disk

 dd if=/dev/hda of=~/hdadisk.img

3. Restore using Hard Disk Image

To restore a hard disk with the image file of an another hard disk, use the following dd command example.

 dd if=hdadisk.img of=/dev/hdb

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.

4. Backup a Partition

dd if=/dev/hda1 of=~/partition1.img

5. CDROM Backup

dd command allows you to create an iso file from a source file. So we can insert the CD and enter dd command to create an iso file of a CD content.

 dd if=/dev/cdrom of=tgsservice.iso bs=2048

Valic

Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

Trackbacks and Pingbacks:

  1. maillot de foot vintage - June 8, 2013

    maillot de foot vintage…

    excellent submit, very informative. I wonder why the other specialists of this sector do not notice this. You must proceed your writing. I’m sure, you have a great readers’ base already!…

Leave a Reply