Bash – Sync Files Recursively Between Folders Less Than 24 Hours Old

bashfindrsyncscripting

I want to find all the files under a directory which are within 24 hours then rsync those files with another server.

There are some old files that I do not want to transfer, however if those old files are updated then I do.

I was thinking of writing a script with: find and the -ctime parameter and redirect that output to a file, but I don't know how to get rsync to effectively use that, or if there is a better way to transfer a set of files which have changed in the last 24 hours.

This process needs to be run very frequently, so am not looking for something too inefficient. (such as using ftp and sending everything each time).

Any ideas appreciated.

Best Answer

Try this:

cd /some/dir && rsync -av --files-from=<(find . -mtime 0 -printf "%p\n") <other stuff>

It uses Process Substitution <( ) to replace the find command with a named fifo and gives that fifo's name to rsync to read as what to include in the sync.

Update

In light of Kyle's answer, it definitely appears that --files-from is more appropriate than --include-from; although both will work. Answer updated

Related Question