Network tar using SSH

Never realized how easy it is to duplicate a directory tree from one machine to another through the network without building an intermediate tarball and finding room for it and the original files all at the same time. Simply pipe the tar command through ssh and untar it on the fly.

For example, suppose we have direcotry “pictures” on SRC_HOST machine and I want to replicate it over to DST_HOST, do this from the SRC_HOST machine:

tar cvf – pictures | ssh user@DST_HOST “cat | tar xf -”

Or, if you just wanted to create a compressed archive of “pictures” on DST_HOST:

tar czvf – pictures | ssh user@DST_HOST “cat > pictures.tar.gz”

I’m ashamed to admit how many times I’ve jumped through hoops to find the free space on both machines due to making a compressed tarball, copying it over, unpacking it, then deleting the tarball.

Update: While the above is functional, it’s all rather academic. Not but a few days after writing this, I stumbled across ‘rsync‘. Yeaeh, this is a little easier:

rsync -avz user@DST_HOST:pictures pictures

And how to do it on a Mac and get all the resource forks to transfer to a non-HFS file system requires extra care and a better version of rsync than Apple delivers.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>