0

I want to take tar from a logged in shell and take that tar file to a remote host and then extract the tar file over there. I've got below command but the tar itself is not creating.

time=`date`
timestamp=`date +%F_%H%M`
backpfilename=db${timestamp}.tar.gz

cd /home/aryan/ && tar -cvzf $backupfilename | ssh root@remoteserver 'cd /home/aryantest/ && tar -xvzf $backpfilename'
1
  • 1
    Google 'tar over ssh' Commented Sep 9, 2015 at 20:26

2 Answers 2

10

You can extract the tar file directly on the other side without writing it to disk:

tar czv <files>| ssh root@remoteserver 'cat | tar xz -C /remotedir'

You can use this even with netcat to copy files around.

If you want a progress bar you can use pv for this. It will print the speed to stdout so you can check how fast it is copying:

tar czv <files> | pv | ssh root@remoteserver 'cat | tar xz -C /remotedir'

If you already have that tar file, you can use pv to pipe it through ssh:

pv backupfile.tgz| ssh root@remoteserver 'cat | tar xz -C /remotedir'

1

Try this :

cd /home/aryan
tar cfvz /dev/stdout . |
    ssh root@remoteserver 'cat > file.tar.gz && tar zxvf file.tar.gz'

You just need to adapt it a bit

Note

/dev/stdout can be replaced by -.

The basic way to create compressed files with tar is : tar opts file.ext dir/. Here we explicitly replace the destination filename with STDOUT to be able to stream it via ssh.

1
  • Thanks.. I've made the necessary changes. Can you please let me know in detail about tar -cvzf - /home/aryan/db where usually tar command will be like tar -cvzf filename.tar.gz filename/ I am confused in this two tar commands. Both of them take tar
    – Aryan
    Commented Sep 9, 2015 at 21:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .