# Piping Tar datastream over SSH



## ulrik (May 5, 2002)

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!!!


----------



## blb (May 5, 2002)

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,

```
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.


----------



## ulrik (May 6, 2002)

Hmm...since you already solved this without a problem....I need the clarify myself. I need it exactly in the other direction  FROM the remote machine TO my machine...

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



thanx for the great help!!!


----------



## blb (May 6, 2002)

Simply reverse the logic:

```
ssh remote "cd /usr/local/stuff; tar cf - ." | tar xf -
```
will copy everything from /usr/local/stuff to your current directory.


----------



## ulrik (May 6, 2002)

Millions of thanx


----------



## scruffy (May 6, 2002)

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.


----------



## ulrik (May 14, 2002)

thanx!!!


----------

