I have a server that is 80G total size and has no more space so i cannot backup on the server. I found this command

ssh server2 "tar -zc -C /srcdir ./path" | tar -zx -C /destination

but it is not making sense. ./path refers to what? So I was thinking of doing this:

localserver:~$ ssh root@remoteserver "tar czvf / " | tar xzvf /mnt/backup

Compress root of remote server and uncompress in my backup directory. /mnt/backup is mounted on a 300G drive. Would this work? I have passwordless access to the remote server using public key.


It's a good start, but it has some issues

First, on the source server, you need to specify that you want to send the archive to stdout. This is done by providing - as the filename:

tar czf - /

You need to remove the -v parameter. Printing out the filenames along with the compressed archive will completely wreck it.

On the target side you need to specify the output directory with -C (or cd into it before you start, then you can leave it out):

tar xz -C /mnt/backup

You can leave the -v here if you want ... it will slow down the process, but it won't do any harm. No need to specify -f, since tar automatically detects the compressed stream from stdin.

The complete working command would be this:

ssh root@removeserver "tar cfz - /" |tar xz -C /mnt/backup

Note that you will get some error message when you do this on a running system, from files that are modified while tar reads it, socket files etc. This shouldn't hurt the process since they are printed to stderr, but it would be cleaner to boot the server from a rescue environment for the process.

  • 1
    Alternatively, take a look at rsync. It supports compression as well and has the advantage that you can continue if the connection drops. With tar you will have to start again. – Gerald Schneider May 17 at 12:38
  • I tried rsync --rsync-path="sudo rsync" -avzhe ssh user@remoteserver:/ /mnt/backup/ and i had error. Now that i added my pub key in root's authorized_keys, should i try rsync -avzhe ssh root@remoteserver:/ /mnt/backup/? – Vasiliki May 17 at 13:41
  • I don't know what went wrong but my disk kept filling. So, the server i needed to backup had only 80G in total. The process stopped because the 300G destination disk, run out of space. – Vasiliki May 17 at 15:58
  • Well, there are certain directories like /dev, /proc etc. that should be excluded. But this is covered in various other questions and answers on this site. – Gerald Schneider May 17 at 16:06

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.