3

I'm renting a couple of VPS with Ubuntu, and I've managed to fill-up one of them. Here I've got several directories with lots of files I'd like to put into an archive. Unfortunately, I don't have room enough to create such an archive (not even as root).

I was therefor wondering if it's possible to use tar (preferred) or cpio to create the archive on the other VPS? I'll want to compress the archive, so either calling tar with the j-option (bzip2) or piping the file to bzip2 at some point (preferably before sending it over the network) - any suggestions as to how I best can compress the file?

Finally, both VPS got ssh and sshd installed, so I was thinking of using it for the transmission of the file.

+++

Unfortunately I'm not an expert in using tar/cpio or ssh in this way, so I'm a bit out of my depth as to something like this can (best) be accomplished. How should I use ssh? Like tunnel or pipe, like ftp, like scp? How should I use tar? Have tar running on both VPS, with a ssh-tunnel between them? Run tar on the source-VPS, tunnel the result and redirect the result to a file on the destination-VPS?

So how can I do this?

Are there other - better - way to do something like this? Some special-purpose package? Using network-sockets? Something else?

  • sshfs is the first thing that comes to my mind – Arkadiusz Drabczyk Aug 26 '15 at 10:39
4

piping should be enough. Doing just:

tar -cvj /path/to/your/files | ssh remote "cat > file.tar.bz2"

(if you have set up passwordless log in using keys)

Later on the other machine you can decompress the received file using tar -xvf path.tar.bz2 -C ./

2

You could use something like this to archive and copy through ssh:

tar zcvf - stuff/ | ssh alex@localhost 'cat - > /tmp/stuff.tar.gz'

Here you are creating a tar.gz archive but instead of saving it to some file you are using - which is standard output. The standard output - is then piped to ssh and from there on you cat from standard output cat - > and redirect to your file on the second machine.

The suggestion form user Arkadiusz Drabczyk in the comments is also good, because once set up you could use mv to move from one machine to the other. If you want to use sshfs you have to install it first and after that:

sudo sshfs root@xxx.xxx.xxx.xxx:/ /mnt/droplet
0

I would always use rsync for cases like this. It makes the whole process more flexible and reliable. For example the whole process will be restartable and can continue where it stopped / failed / was interrupted.

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.