Header Ads

Header Ads

Linux - Clone HDD over Network using netcat

There is a common question, how to successfully clone hard disk drive over TCP/IP Network (or internet) using only basic GNU/Linux utilities ? The short answer is to use Netcat and dd. ;-)

Today we will learn how to clone hdd over network using only basic Linux utilities netcat+dd, for this operation we will use Debian GNU/Linux distribution. So first of all we have two hosts A and B. We will use bzip2 compression to transmit compressed data over network, the operation will go much more faster. What is netcat ? Netcat is a simple Unix utility which reads and writes data across network connections, using TCP or UDP protocol. It is designed to be a reliable "back-end" tool that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and exploration tool, since it can create almost any kind of connection you would need and has several interesting built-in capabilities. Netcat, or "nc" as the actual program is named, should have been supplied long ago as another one of those cryptic but standard Unix tools.

A. - 192.168.1.1 Main machine from where we backup data.
B. - 192.168.1.2 Second machine, where we will restore hdd clone data.

Install netcat and bzip2:
apt-get install netcat
Run the following command on host B:
nc -l -p 666 | dd of=/dev/sdb bs=16M status=progress # not compressed
nc -l -p 666 | bzip2 -d > /dev/sdb # for compressed data
On the host A run the following:
dd if=/dev/sda bs=16M |nc 192.168.1.2 666 # not compressed
bzip2 -c /dev/sda | nc 192.168.1.2 666 # for compressed data

What all of this means?
666 : Specifies the source port netcat should use, subject to privilege restrictions and availability. Make sure port 666 is not used by another process.
-l : Used to specify that netcat should listen for an incoming connection rather than initiate a connection to a remote host.
bzip2 -d : Compresses image using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. This will speed up network transfer ( -d : force decompression mode)
dd of=/dev/sda : /dev/sda is your hard disk. You can also specify partition such as /dev/sda1
To copy100GB of data should take about an half-hour to 50min.



No comments:

Copyright (c) 2012-2013 Unix Master. Powered by Blogger.