Linux – compress remotely server folders and files and copy them to the local drive

bashlinux

I have a linux dedicate server with access using ssh and plesk. I don't have enough space on my server that I can zip my all folder and files and then scp them on my local computer.

Is there a bash command which can zip remote files on my local drive directly?

Best Answer

If your "local drive" is a linux client, you might just use a remote tar command to print the output to stdout (the default, an explicit option specification would be "-f -")and pipe it to a local tar that reads from stdin (explicit option "-f -" again) like that:

ssh your.dedicated.server 'tar -czf - /my/files/to/back/up' | tar -xzf -

When using the "-z" option, Tar will compress your data with gzip's default compression level (6). If you want a better compression rate and have CPU cycles to spare, you might use "-j" instead, but if it is an old/virtual machine with a fast link, you might end up with an overall lower transfer rate.

Oh, and as an edit: you might specify the -C (compress) option with SCP, this will use gzip as a compression algorithm as well, although the compression rates usually will be slightly lower than with a tar/gzip combination. It is less to type and you will get nifty progress indicators as a bonus.