LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Piping archive to remote host (https://www.linuxquestions.org/questions/linux-networking-3/piping-archive-to-remote-host-413141/)

michaelsanford 02-08-2006 03:27 PM

Piping archive to remote host
 
I wanted to do something like this:
Take a local directory,
- tar gzip/bzip2 it
- ssh + cat it to a remote machine

The only problem is, the only guide I found on the 'net was
Code:

Backup with local compression and remote storage

tar cf - dirname | gzip -c | ssh remotehost "cat > ${TMPFILE}.tar.gz"

which seems to require a temp file. Or am I misinterpreting this, and that ${TMPFILE} is the name of the file to be created on the remote machine? (It is an environment variable in the guide).

I can't use a local temp file expressly because the resulting tgz > free space.

Sorry for the banal question, I've never been really good with piping. *blush*

oneandoneis2 02-08-2006 03:51 PM

I assume you're using the Linux.com article as your guide?

I'd imagine that using "tar cjf" would work - the "j" flag adds bzip2 compression, as shown in the tar man page. . . Altho I believe the example you show is indeed making the TMPFILE file at the remote site. Just swapping "gzip" for "bzip2" would probably work

born4linux 02-08-2006 06:54 PM

try something like this:

tar cvf - localdir/ | ssh user1@remotehost "gzip -c > backup.tgz"

(note: not all systems has the compress option - i'm doing this on AIX so the gzip redicrection :)

tredegar 02-09-2006 08:44 AM

For moving directories (and subdirectories) between computers, I like to use scp , like this:
scp -pr /path/to/directory hostname:/path/to/destination
Or, if you just want to move one file:
scp -p /path/to/file hostname:/path/to/destination
Hope this helps.

satinet 02-09-2006 10:40 AM

yes, why not just use scp? it uses the same authentication as the any other ssh connection (e.g. ssh-ageant works)....

michaelsanford 02-10-2006 06:41 PM

tredegar, satinet, thanks for your replies but you probably glanced over my original post a little quickly :) I needed a way to pipe a local folder to a tar.gz on a remote machine, like oneandoneis2 and born4linux mentioned.

Thanks to all who replied, of course!

PS For other things, I love scp, it's great, too bad it doesn't compress inline.

satinet 02-11-2006 02:01 PM

this code wont work:

tar cf - dirname | gzip -c | ssh remotehost "cat > ${TMPFILE}.tar.gz"

how are you defining TMPFILE? what are you cating? i'm not sure that gzip produces an output as such to pipe into ssh.

i dont understand where cat comes into this. are you wanting to create an archive or expand it at the other end??

if you want to tar accross a network you would using something like:

tar cf - dirname | ssh remotehost '( tar xfB - )'

or are you wanting to create a gzip at the other end? how can you cat and archive or tar ball??


All times are GMT -5. The time now is 12:21 AM.