How to use tee to send a btrfs subvol to two drives in one pass?

btrfs send sdd4/ro.rec/Pics-20210529T1829/ | tee >(btrfs receive sdb1/ro.rec/) | btrfs receive sdc1/ro.rec/

Is the above the correct way?

I read the above discussion, one comment said:


Not a concern with pbcopy, but worth mentioning in general: whatever the process substitution outputs is also seen by the next pipe segment, after the original input; e.g.: seq 3 | tee >(cat -n) | cat -e (cat -n numbers the input lines, cat -e marks newlines with $; you'll see that cat -e is applied to both the original input (first) and (then) the output from cat -n). Output from multiple process substitutions will arrive in non-deterministic order. – mklement0 Dec 9 '14 at 4:47

Why would you try that. Tee is designed to send what you see on the screen to a file at the same time, not designed for the way you want to use it.

From the man page for tee:

 tee - read from standard input and write to standard output and files 

What would be wrong with just doing the send twice, once to each destination. If you know the source filesystem is static then there would be no differences in the results.

It is because btrfs send is exactly sending to standard output.

https://man7.org/linux/man-pages/man8/btrfs-send.8.html

-f <outfile>
           output is normally written to standard output so it can be,
           for example, piped to btrfs receive. Use this option to write
           it to a file instead.

Sending twice will need more time, I guess.

1 Like