↑ ↓ select, Enter open, Esc close

Stream a tar backup directly to another server over SSH

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
user@server
tar -czf - -C /var/www/vhosts/example.com/httpdocs . | ssh webuser@backup.example.com 'cat > /home/webuser/backup/example.com-httpdocs.tar.gz'

tar writes the compressed archive to standard output (-f -), SSH pipes the stream to the target server, where cat writes it to a file. No local space is needed for the archive. Exactly right when the disk is already full and you need a backup before cleaning up.

Note: An existing target file is overwritten. After the transfer, check with ssh BENUTZER@HOST 'tar -tzf ZIEL > /dev/null' that the archive is fully readable.

Also searched as

  • tar over ssh to remote server
  • backup when disk is full
  • create archive without local copy
  • back up directly to backup server

Related one-liners

All in rsync and backup

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.