Pull a backup from a remote host with ssh and tar

Sometimes you might need to copy a whole directory from a remote host, but the remote host does not have enough space to tar the whole thing up and then sftp it off. The solution is to tar/bzip the directory and stream it directly to your local host:

ssh root@remotehost 'tar cjf - /path/to/somedirectory' | pv -cN tar  > somedirectory.tar.bz2

Using pv (pipe viewer) gives you extra progress bar goodness:

tar:  176MB 0:09:14 [ 371kB/s] [                             <=>    ]

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *