Search code examples
linuxscriptingbackuprsyncbsd

How can I use rsync to backup files changed within a recent period?


Is it possible to specify a time range so that rsync only operates on recently changed files.

I'm writing a script to backup recently added files over SSH and rsync seems like an efficient solution. My problem is that my source directories contain a huge backlog of older files which I have no interest in backing up.

The only solution I've come across so far is doing a find with ctime to generate a --files-from file. This works, but I have to deal with some old installations with versions of rsync that don't support --files-from. I'm considering generating --include-from patterns in the same way but would love to find something more elegant.


Solution

  • It looks like you can specify shell commands in the arguments to rsync (see Remote rsync executes arbitrary shell commands)

    so I have been able to successfully limit the files that rsync looks at by using:

    rsync -av remote_host:'$(find logs -type f -ctime -1)' local_dir
    

    This looks for any files changed in the last day (-ctime -1) and then rsyncs those into local_dir.

    I'm not sure if this feature is by design but I'm still digging into the documentation.