Page 1 of 1

Create TAR over SSH

Posted: Tue Aug 24, 2021 11:14 pm
by peter_b
Tar works fine with pipes, so here's a copy of commandline recipes by Mickaël Bergem:

Execute this on the host that will receive the data from the source server:

Code: Select all

$ ssh user@source-server "tar czpf - /some/important/data /some/other/file/or/folder" | tar xzpf - -C /backup/destination/folder
Tar-gzips the listed folders/files, outputs them to stdout over SSH, which is then received by the local "tar" command which is ungzipping and extracting the received contents in the /backup/destination/folder.

Here's a modified version which skips the (gzip-)compression part (e.g. for LAN):

Code: Select all

$ ssh user@source-server "tar -cpf - /home/user/whatever" > backup.tar
On Mickaël's blog there's also a recipe for pushing (this was pull).