4

I can transfer file /tmp/file using rsync to remote server:

rsync -R -av /tmp/file root@server:/

but how can I provide the list of files to be transfert from a pipe? I tried using the --files-from= option with /dev/stdin, but that does not work:

echo /tmp/file | rsync -R -av --files-from=/dev/stdin root@server:/

(neither does it work with regular file)

Hoe can I make rsync read from pipe, so that I can use output of find, for example?

Martin Vegter
  • 358
  • 75
  • 236
  • 411
  • 1
    You seem to have forgotten to include the error message. Also you seem to have forgotten the source argument in the invocation of rsync. – Kusalananda Jan 31 '21 at 11:08
  • If you know what will be there, you may use --exclude=file1 – Eng7 Jan 31 '21 at 11:11

2 Answers2

6

You still need to specify both source and target arguments to rsync, even when you're reading pathnames from a file:

echo /tmp/file | rsync -av --files-from=- / user@server:/

The pathnames read by rsync would be relative to the / source directory. The -R option is implied when using --files-from, and standard input may be specified with -.

See also

You may want to ask a separate question about your intention to pass output from find to rsync using --from-file. There is probably a much safer way of doing what you intend to do. For example, you may want to use -print0 with find and pair that up with -from0 with rsync. See the manuals for rsync and find on your system.

Kusalananda
  • 333,661
  • but what do you intend to process with -print0 and -from0? filenames having linebreak characters? – Mary Aug 24 '21 at 13:39
  • 2
    @Mary Yes. Filenames containing newlines are valid on Unix, so listing them in a text file is problematic. – Kusalananda Aug 24 '21 at 14:18
  • I also noticed, there's an explanation about -print0 in find manpage (indeed - possible newlines in filenames...) – Mary Aug 24 '21 at 19:49
  • Note the stray / in the middle: --files-from=- / user@server:/ — I missed initially. Also user@server:/ can of course be replaced with a local path. – user598527 Jun 10 '23 at 16:15
0

You could use -exec option together with find:

find -type f -name /tmp/file -exec rsync -R -av {} root@server:/ \;

The {} is the result from previous result, everything found before -exec. ; is indication the end of exec