Linux – How to have rsync delete destination files 6 months after they have been deleted at source

backupdeletinglinux

Working on Debian 10. Seeing that rdiff-backup has stopped development for quite some time, I'd like to move on my backup-needs to rsync. However, there is one feature of rdiff-backup that I am not prepared to give up:

--remove-older-than 6M

That option will delete files from destination if they have not existed in the source for longer than 6 months.

Is there either

  • a way to do this in rsync? Or
  • some other more modern, scriptable backup-tool for Linux that offers that function?

Best Answer

I strongly suggest using an rsync based tool called rsnapshot: it supports defining specific retention policies, with automatic rotation and deletion.

If you want to use rsync only, you need to find and delete files older than 6 months via the find utility - ie: something as find /your/dir -mtime +180 -daystart -delete.

DISCLAIMER: Before using the -delete subcommand, be sure to test your find command to triple-check it does not select unwanted files.