3

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.

T K
  • 133
  • 1
  • 5
  • 3
    Use an existing backup solution. No need to reinvent the wheel. – Gerald Schneider Sep 19 '19 at 18:04
  • Welcome to Serverfault! It sounds like you have space constraints on your source server, and can't create a tar file. Are you looking for a way to send a tar file to the remote server? Or just send the files over compressed? Perhaps you could re-word this a bit to help us understand your problem a bit better. – Mike Marseglia Sep 19 '19 at 18:06
  • @MikeMarseglia I've edited my question – T K Sep 19 '19 at 18:12
  • 1
    Can you elaborate on why sending the files and tar them on the backup server isn't a good solution from your point of view? It solves the only actual problem you've listed. It's the most straightforward and simple way to achieve what you're trying to do. You can find many tutorials on how to do it doing a google search for _remote tar backup_. You don't have to send all the files then create a tarball, you can create the tarball on the fly. Also, rsync is the wrong tool for the job if you don't intend to store the files exactly as they are on the source. –  Sep 19 '19 at 18:24
  • @TK while your question is interesting indeed, I would *really* recommend to use `rsync` (or, even better, `rsnapshot`) for such a backup job. – shodanshok Sep 19 '19 at 19:07
  • @shodanshok I know, with rsync I am able so only sync the changed files. But in my case I need to backup the whole directory every time, not just the changed files. thank you for you recommendation! :) – T K Sep 19 '19 at 19:44
  • 1
    @TK and this is *exactly* what `rsnapshot` provides (via a clever use of `rsync` and hardlinks). I would give it a try. – shodanshok Sep 19 '19 at 20:35

1 Answers1

6

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

Mike Marseglia
  • 913
  • 8
  • 18