Search code examples
bashshellrsyncpax

mirror to a transformed files' structure


I'd like to synchronize a files structure to another, but transformed one, eg:

filesStructureA/ --[transformation(T)]--> filesStructureB/

Is it possible doing this with rsync? I saw rsync accept a list of files as input (--files-from), but don't really know how to apply the transformation T for each of one...

In other words, is it possible with rsync to rename files on the fly ?

Thank you.

for an example, from src/ to dst/, suppress every bar/ occurences in the destination path, eg:

src/foo/hi.txt
src/foo/bar/hey.txt
src/foo/bar/bar/lorem/bar/hoy.txt

sed 's/bar\///'          <- [Transformation function]

dst/foo/hi.txt
dst/foo/hey.txt
dst/foo/lorem/hoy.txt

Solution

  • Answer is pax:

    cd src/
    find . -type -f -path '*bar/*' -print0 | pax -0 -rw -v -Y -Z -s '/\/bar//g' ../dst/
    cd ..