How to delete files older than X on backup during sync?

Matthew Monaco dgbaley27 at
Sun Nov 9 08:18:46 GMT 2008

You can do something like

"rsync OPTIONS --rsync-path="find /root-dir/ -mtime +14 -delete ; rsync"

although, to be safe you'll probably want something like:

"rsync OPTIONS --rsync-path="find /root-dir/ -type f -mtime +14 -delete
; rsync" --prune-empty-dirs SRC DEST"

I'm not sure whether or not find would delete a directory that's not
empty, but this the safe bet.

Thomas von Eyben wrote:
> Hi list,
> I have been reading MAN pages and listarchives, but not found the
> answer to my question though I am sure it must be possible to acheive
> my wish.
> I wish to use rsync to create a backup BUT only keep the files for a
> limited period of time, EG two weeks.
> I have not yet been able to figure out how to do this inside rsync
> (while the backup is being performed) and my understanding of the
> "--delete" flag is not for this wish.
> My plan is - unless I find out that it indeed is possible with rsync -
> to make a cronjob removing files older than X in the folder containing
> the backups…
> BR,
> Thomas von Eyben

More information about the rsync mailing list