rsync remote to local only files older than certain time

0

I want to rsync from a remote to local files that are older (or newer) than a certain time.

I've seen answers that say find /src/path -mtime -1 | rsync ... but that only work if the dir is seen locally. Since it's remote it's not visible.

So how can I run the find on remote and rsync its results back to local?

Mike Dannyboy

Posted 2018-06-22T02:06:03.503

Reputation: 55

Answers

0

rsync has a --list-only option, which provides an index of the remote files, including timestamps:

$ rsync --list-only $REMOTE
drwx------            160 2018/09/04 12:55:12 .
-rw-r--r--          1,348 2018/09/04 12:52:33 .bash_profile
-rw-r--r--             55 2018/09/04 12:52:33 .bashrc
...

Filtering on this list to select only appropriate dates, and then feeding that into a subsequent rsync's --files-from argument (which can refer to stdin, by using --files-from=-) should do the job.

For example, the following will rsync files with an mtime between 2018-08-01 and 2018-08-07 to the local machine (with appropriate values of $REMOTE and $LOCAL_PATH; note $5 in the awk command refers to the fifth column - i.e. the filename - from the rsync output)

$ rsync --list-only $REMOTE | awk '/2018-08-0[1-7]/ {print $5}' | rsync --files-from=- $REMOTE $LOCAL_PATH

This doesn't answer the full problem of using find's -mtime-type specifiers, but further parsing of the date string (e.g. using date) could be done to extend this.

codedstructure

Posted 2018-06-22T02:06:03.503

Reputation: 278