This nice command will allow you to create a tar archive remotely rather than having to create the tarball locally and then copying it somewhere else.

This could be helpful if you don't have enough space locally to create the tar file.

tar zcvf - <source> | ssh user@destination dd of=<path>/backup.tgz

The trick is to tell tar to pipe into stdout (f -) and use dd on the remote host to capture the stdin into the backup.tgz file.

Example:

# create a sample structure to backup
$ for f in `seq 1 4`; do mkdir directory$f ; for s in `seq 1 4`; do  touch directory$f/file$s ; done ; done

$ tar zcvf - directory* | ssh remoteserver dd of=backup.tgz
a directory1
a directory1/file3
a directory1/file4
a directory1/file2
a directory1/file1
a directory2
a directory2/file3
a directory2/file4
a directory2/file2
a directory2/file1
a directory3
a directory3/file3
a directory3/file4
a directory3/file2
a directory3/file1
a directory4
a directory4/file3
a directory4/file4
a directory4/file2
a directory4/file1

20+0 records in
20+0 records out
10240 bytes (10 kB) copied, 0.0187702 s, 546 kB/s

$ ssh remoteserver "tar ztvf backup.tgz"

drwxr-xr-x max.mongardini/wheel 0 2021-11-25 15:38 directory1/
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory1/file3
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory1/file4
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory1/file2
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory1/file1
drwxr-xr-x max.mongardini/wheel 0 2021-11-25 15:38 directory2/
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory2/file3
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory2/file4
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory2/file2
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory2/file1
drwxr-xr-x max.mongardini/wheel 0 2021-11-25 15:38 directory3/
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory3/file3
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory3/file4
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory3/file2
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory3/file1
drwxr-xr-x max.mongardini/wheel 0 2021-11-25 15:38 directory4/
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory4/file3
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory4/file4
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory4/file2
-rw-r--r-- max.mongardini/wheel 0 2021-11-25 15:38 directory4/file1