Search code examples
rsync

rsync only *.php files


How can I rsync mirror only *.php files? This gives me a bunch of empty dirs too and I don't want those.

rsync -v -aze 'ssh ' \
--numeric-ids \
--delete \
--include '*/' \
--exclude '*' \
--include '*.php' \
[email protected]:/home/www/domain.com \
/Volumes/Servers/

Solution

  • The culprit here is the

    --include '*/'  
    

    When including a wildcard followed by the trailing forward-slash you're telling rsync to transfer all files ending with a '/' (that is, all directories).
    Thus,

    rsync -v -aze 'ssh ' \
    --numeric-ids \
    --delete \
    --exclude '*' \
    --include '*.php' \
    [email protected]:/home/www/domain.com \
    /Volumes/Servers/
    

    If you were using that because you intend to recursively find all .php files, you’d have to use the ** wildcard. That is, --include '**/*.php'

    Another way ( http://www.commandlinefu.com/commands/view/1481/rsync-find ) is pre-finding the target files and then using rsync,

    find source -name "*.php" -print0 | rsync -av --files-from=- --from0 ./ ./destination/