Username/Email:  Password: 
TwitterFacebookFlickrRSS

Tech Tip: Remote Mirroring Using nc and dd

 in

You can use the dd and nc commands for exact disk mirroring from one server to another. The following commands send data from Server1 to Server2:

Server2# nc -l 12345 | dd of=/dev/sdb
Server1# dd if=/dev/sda | nc server2 12345

Make sure that you issue Server2's command first so that it's listening on port 12345 when Server1 starts sending its data.

Unless you're sure that the disk is not being modified, it's better to boot Server1 from a RescueCD or LiveCD to do the copy.

______________________

################################# # Arun Maurya (अरुण मौर्य) # #################################

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

RSYNC!

Matt K's picture

Rsync doesnt do a block by block copy, hence it is not a valid solution for imaging an entire hdd.
*Rsync simply copies files and not drive structure partitions etc.
*Rsync is great for backing up data but if you want a complete copy of a drive its gotta be dd as it can copy everything.

RSYNC

VIKAS's picture

I would still prefer rsync

Very nice, short and sweet.

Anonymous's picture

Very nice, short and sweet. The comment trail is invaluable.

Tip means tip

Anonymous's picture

Netcat, also called "The TCP/IP Swiss Army Knife" is a utility that is able to write and read data across TCP and UDP network connections...and more you can read in man nc ..

Use rsync!

Lawrence D'Oliveiro's picture

rsync does it all, including updating your mirror for incremental changes without recopying the whole thing.

nc vs. ssh

Hans-Werner's picture

nc is short for netcat (and in some distributions it -- whatever variant of netcat "it" refers to -- has that name). nmap now brings ncat, too, which has basically the same property (and a lot more): It connects the stdin/-out w/ a TCP socket (or UDP in some versions). So it streams data back and forth through an TCP stream, allowing for "piping via the net".

Well, and then we have ssh. It's (arguably) easier to handle, and provides cryptography, something you might want, rather than streaming your precious data unencrypted:

on the client/source side of things:

dd if=/dev/blah | ssh user@server dd of=/dev/target

(and nothing on the server/target, so no port open for an attacker that wants to write to your block device, either.)

Hint for dd

Anonymous's picture

Also, sending a USR1 to the dd process will show the amount of data transferred without killing the process itself.

Great; a stub that doesn't

Anonymous's picture

Great; a stub that doesn't explain anything at all. How about educating users about what netcat and dd actually do, and the security implications of sending your hard drive contents bit-by-bit over a network? This looks like it was written in about 1 minute or less.

I used to tar files and

Anonymous's picture

I used to tar files and stream them over net with the same commands (dd <-> tar). This helps to minimise traffic.

Compress the stream with

MasterM's picture

Compress the stream with gzip. It would speed up things a bit.

Server2# nc -l 12345 | gzip -dc | dd of=/dev/sdb

Server1# dd if=/dev/sda | gzip | nc server2 12345

Don't be lazy. It's at your

Anonymous's picture

Don't be lazy. It's at your fingertips if you just man nc or even google it.

nc is netcat, a simple unix utility for reading and writing data across network connections. Instead of piping to STDIN, STDOUT or a file, you're piping the data stream to a network socket.

Can you please provide more

Anonymous's picture

Can you please provide more info about what these commands are actually doing? I've used dd before, but nc is completely new to me. Talk about a stub.