How to make rsync read SRC from STDIN?

I want to dump a MySQL database and do daily backups using rsync .

The first approach I came up with is something like mysqldump -ufoo -pbar baz > /var/tmp/baz.sql && rsync /var/tmp/baz.sql /backup/ && rm /var/tmp/baz.sql .

Then I started to wonder if it is possible to use the temporary file /var/tmp/baz.sql , but instead output the mysqldump output directly to rsync .

To be more specific, what I want is very similar to the command line we use to update the GPG key for apt in Ubuntu: gpg --export --armor CE49EC21 | sudo apt-key add - gpg --export --armor CE49EC21 | sudo apt-key add - where the channel receiver supports this argument - indicating it will read from stdin . I believe rsync does not have a similar argument. But I want to know if there is a workaround.

+6
source share
1 answer

This is correct, this does not work. This is because rsync transfers the complete file tree from A to B

Due to the way rsync works, it cannot work because rsync calculates several checksums before choosing to transfer a specific file (or parts of it) and do it in just 2 iterations (ping-pong steps).

This means that the file needs to be read several times. This would not work with a (potentially large) SQL dump, because somehow it would have to be buffered. And this buffering is up to the user.

In fact, saving a file should be the best way, especially if it is a file that receives only gradual differences.

+4
source

Source: https://habr.com/ru/post/958693/


All Articles