0

I use the following command successfully

rsync -e 'ssh' -avr [email protected]:/home/mikrotik /bck/mikrotik/

How can I add date filter to this command? I would like to sync only files that are newer than n days from remote dir [email protected]:/home/mikrotik to local dir /bck/mikrotik/

3
  • 2
    I don't think that is easily doable with rsync alone. BTW, you don't need -e ssh as SSH is the default. And -r is already activated by -a, so you can drop that as well.
    – Kusalananda
    May 7 at 15:01
  • 2
    Unless you intentionally delete files periodically from /bck/mikrotik that are still present on the source system, or you have many thousands of files and you're seeing a time impact while rsync skips the files it's already transferred, your date filter shouldn't be necessary
    – roaima
    May 7 at 17:14
  • 1
    If you want to limit the process to files newer than n days (and there are older files in the source that are absent in the target), you can use for example find -mtime -7 as a filter before the copy process to get files created/modified during the last 7 days.
    – sudodus
    May 7 at 19:25

1 Answer 1

2

Unless you intentionally delete files periodically from /bck/mikrotik that are still present on the source system, or you have many thousands of files and you're seeing a time impact while rsync skips the files it's already transferred, your date filter shouldn't be necessary.

However, having said that you can use find to generate the set of candidate files for transfer. Here we're considering only files that have been created/modified within the last seven days:

ssh -n [email protected] 'cd /home/mikrotik && find . -type f -mtime -7 -print0' |
    rsync -av --files-from='-' --from0 [email protected]:/home/mikrotik /bck/mikrotik/

If you don't have a version of find that supports -print0, replace it with -print and remove --from0 from the rsync. The difference is that you then won't be able to copy files containing an embedded newline in their name

2
  • Thank you @sudodus fixed
    – roaima
    May 8 at 10:12
  • It works perfectly. Thank you @roaima. That's exactly what I needed.
    – mikia
    May 17 at 20:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .