0

Let say i want to :

Create a tar ball from a directory on server A

Scp this tarball to a server B

Untar the in the server B

ssh root@serverB   " scp  root@serverA:/var/www/dirs.tar.gz  /var/www/dirs.tar.gz && tar -xvf  /var/www/dirs.tar.gz 

I want to avoid repeating the path using a pipe. How to write it properly with a PIPE to get the second argument ?

Thanks

2

Just tarring a directory, copying it to a remote server, where it is untarred? Then scp -r directory ..., rsync -r directory ... or sftp are much better.

If you want to copy the tar file to the remote server and also unpack it, try

tar -cf - mydir | ssh root@192.168.1.248 'bash -c "tee archive.tar | tar -xf -"'

The tee is key here: It puts a copy of the tar file into the remote filesystem and passes the tarfile to the tar command, which unpacks it.

Perhaps a less convoluted solution is to simply rsync the directory to the remote server, where you create a tar file from it.

0

We don't see how you create the tarball, and if that needs to be a separate step, but tar doesn't need to create/consume files, so something along these lines should work:

ssh serverA tar cz file… | tar xz

(for ease of understanding, I'm assuming you're already root@serverB and leaving out things like making sure you're in the right directory.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.