Backup to Remote Server and Create Tar on the Fly – Linux

linuxrsynctar

I would like to backup a directory from my production server to a backup server using rsync.

My current solution:

  1. tar directory
  2. on production server send to remote server via rsync

My Problem with this solution: there is not enough space to create the tar file + it needs to much resources while the tar is created. It should make as less as possible impact on the production server resources.

I would like to send the files into a tar file on the remote server. I simply could send the files and tar them on the backup server, but in my point of view, this would not be a good solution.

Best Answer

You could use a combination of pipes and STDOUT to send the tar file over the network to the remote server.

tar zcvf - /your/directory | ssh -i private.key backup-user@backupserver "cat > /backup/file.tgz"

The "-" character sends the tar to STDOUT which is piped to ssh and the contents written to a regular file using cat.

You'll need to use ssh with a private key file for "passwordless" authentication.

This doesn't use rsync but will get the tarfile to the remote server.

Reference: https://stackoverflow.com/questions/8045479/whats-the-magic-of-a-dash-in-command-line-parameters

Related Topic