Wednesday, 23 October 2013

Backup of Linux Using dd command on Linux.

In some cases critical data loss will have a financial impact on companies. In my this blog i am updating 4 examples for using dd command to backup the Linux system. dd is a powerful Unix utility, Which is used by the Linux kernel to make boot images. dd command can only run by the root user or superuser. 

Warning: Please be careful while using dd command, If you don't know what you are doing, You will loss your data.

Example 1. - Hard Disk Backup (disk to disk)
We can use dd command to backup entire copy of a hard disk to another hard disk connected to the same system. run the dd command as shown below. In below example, the name of the source hard disk is /dev/sda and the name of the target hard disk is /dev/sdb.

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

* Here "if" represents input file and "of " represents to output file, So the backup copy of /dev/sda will be available in /dev/sdb.
* If there are any errors, the above command will fail. Add the parameter "conv=noerror"
* Input file and Output file should be mentioned very carefully.

In the copy of hard disk to hard disk using dd command given below, sync option allows you to copy everything.

# dd if=/dev/sda of=/dev/sdb conv=noerror,sync

Example 2. - Create an Image of a Hard Disk
Instead of taking a backup of the hard disk, We can create an image file of the hard disk and save it. There are many advantages to backing up data to a disk image, This method is faster than other types of backups, and enabling you to quickly restore data.

# dd if=/dev/sda of=~/sdadisk.img

Example 3. - Restore Using Image Backup
To restore Image backup file on another hard disk, use the following dd command:

# dd if=sdadisk.img of=/dev/sdb

The image file sdadisk.img file, is the image of a /dev/sda, So the above command will restore the backup of /dev/sda to /dev/sdb.

Example 4. - Backup a Partition
We can use the device name of a partition in the input file, and in the output file we can specify target path or image file as shown in the below example:

# dd if=/dev/sda1 of=~/partition1.img

For any query please feel free to contact me my email ID is sashwatkatore@gmail.com.

No comments:

Post a Comment