Piping Tar datastream over SSH

ulrik

Registered
Is it possible to pipe the output datastream of tar over an SSH connection?

Let's say I am logging in to a remote server via SSH and want to make a backup, taring some files before moving them to my computer. Is it possible to tell tar that it shouldn't create the archive on the remote host but on my machine, effectively creating some kind of pipe over the SSH connection???

Any help is greatly appreciated!!!
 
Absolutely, I've used this method for years (via rsh long ago, ssh now).
For example, to use tar to copy everything in /usr/local/stuff to remote's /backup,
Code:
cd /usr/local/stuff
tar cf - . | ssh remote "cd /backup; tar xf -"
Basically, you're telling tar to tar up everything in your current directory (.) and send it to -, which is standard out; this is piped to ssh, which (once logged in) will send it to standard input of the process it runs, in this case tar.
 
Hmm...since you already solved this without a problem....I need the clarify myself. I need it exactly in the other direction :D FROM the remote machine TO my machine...

how would the syntax for that machine look like???



thanx for the great help!!! :)
 
Simply reverse the logic:
Code:
ssh remote "cd /usr/local/stuff; tar cf - ." | tar xf -
will copy everything from /usr/local/stuff to your current directory.
 
You might want to use the -C flag with ssh (ssh -C remote "...). That turns on gzip compression of the ssh stream. If you have a slowish connection that could speed things up considerably.
 
Back
Top