Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
I've updated my answer again. It looks like --include-from is not enough, as the default behavior is to include everything. You need to explicitly tell it to --exclude everything in order for it to act like a white list. –  SiegeX Jan 28 '12 at 2:25
add comment

2 Answers

up vote 7 down vote accepted

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

share|improve this answer
1  
rsync is a one way, unidirectional sync system. Use unison if two-way, bidirectional sync system is needed. –  Nikhil Mulley Jan 28 '12 at 12:03
add comment
#!/bin/sh
thefiles=/tmp/files.$$
LOCALDIR=/path/to/local/dir
REMOTEDIR=/path/to/remote/dir
REMOTEHOST=remote.host
changetime=24h

cd $LOCALDIR || { echo cd failed 1>&2; exit 1; }

trap 'rm -f $thefiles' 0

find . -type f -ctime -$changetime -print > $thefiles
rsync -v -n --archive --files-from=$thefiles . $REMOTEHOST:$REMOTEDIR

This script runs find in $LOCALDIR, dumping the results into a file, then tells rsync to use the file contents as a list of files to transfer to the directory $REMOTEDIR on the host $REMOTEHOST. The script chdir's into $LOCALDIR because the rsync command needs relative paths, not absolute ones. I left -v -n in the rsync args so you can see what this does without copying anything; remove -n when you're satisfied the script does what you want.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.