rsync icon indicating copy to clipboard operation
rsync copied to clipboard

Feature: write to standard output for piping

Open neldredge opened this issue 4 years ago • 1 comments

It would be nice if one could rsync a single file from a remote host and write it to standard output, so that it could be used in a pipeline. Much like people often use curl.

I'd like to be able to do something like

rsync --write-to-stdout host:/path/to/file | process | process_some_more > output

The usual tricks like rsync host:/path/to/file /dev/fd/1 don't work either, because rsync insists on unlinking the destination if it is not a regular file, and aborts when it cannot. If it would just go ahead and write to the file anyway, this would just work.

neldredge avatar Dec 12 '21 05:12 neldredge

Dirty proof-of-concept at https://github.com/neldredge/rsync/tree/stdout if anyone is interested, based on seeing what --write-devices does. Adds the --write-always option which attempts to make rsync always write to the given output file without deleting, no matter if it is regular or device or fifo or whatever. You can do

rsync --write-always --inplace --whole-file host:/path/to/file /dev/fd/1 | filter ...

and it works at least in simple tests.

neldredge avatar Dec 12 '21 22:12 neldredge