I would like to recreate the directory structure from a remote system to a local system and copy a sample of the files in each directory (e.g. copy only 5 files from each directory). There may be many levels of nested directories and many files in each directory.
My question is similar to this one, but with the added difficulty of the source directory being on a remote system: Copy directory structure with random number of files
I have tried to modify the solution mentioned in the above question by adding ssh commands, but I get confused managing the ssh commands through multiple pipes and I don't believe the last step with cpio can copy from remote systems:
find "$src" -type d -links 2 -exec \
sh -c 'find "$1" -type f -print0 | shuf -z -n "$2"' sh {} "$nfiles" \; | \
cpio -padmv0 "$dest"
I have investigated whether the filter rules in rsync can do this, but I don't believe they can as the files don't have a specific naming pattern that can be used.
Please let me know if there's a straightforward way to do this.
Edit: Solutions involving perl or python scripts are welcome. Please let me know what the best tools for the job are.