We help IT Professionals succeed at work.

I can dd to a remote host, but how do I compress the data?

ibanja
ibanja asked
on
I need to make an image and send it to a remote host.  I also want to gzip it since 60% of the image is free space.

Here's what I can do:
sudo dd if=/dev/sdd1 |(ssh me@remote dd of=/home/frank/sdd1.img)

Heres what I want to do:
sudo dd if=/dev/sdd1 | [ somehow make it a gzip file] (ssh me@remote dd of=/home/frank/sdd1.img.gz)

Thanks,
Frank
Comment
Watch Question

SILVER EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
sudo dd if=/dev/sdd1 | gzip -c |(ssh me@remote gunzip -c |dd of=/home/frank/sdd1.img)
SILVER EXPERT
Most Valuable Expert 2013
Top Expert 2013
Commented:
Sorry, didn't read carefully enough. Seems that you want to store the compressed file!


sudo dd if=/dev/sdd1 | gzip -c |(ssh me@remote dd of=/home/frank/sdd1.img)

Author

Commented:
Ahh thanks.  I should have looked to compress on the local computer...  I was thinking I needed to do that on the remote machine.  

May I ask why you used the -c switch?  I tried it with and without and got two files that were the same size but with different md5sums.  
SILVER EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
The -c switch is used to write the compressed data to stdout, so we can pipe them to ssh.

I really thought that without this switch it shouldn't work at all!

Or maybe your gzip version automatically writes to stdout when the input comes from stdin ...
SILVER EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
OK, you're right, the -c switch is needed when a filename is specified, otherwise the file is compressed/uncompressed in place.

When there is no filename to compress/uncompress  (but rather stdin) stdout is the default output.

Author

Commented:
Great, I see, Thanks for the further explanation.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.