I currently managed to get a simple rsync setup on ubuntu server 18.04, which does the following:

  • copies all directory structure from /data on server-1 to /data on server-2
  • does not delete anything at all

What I would like to have it do is

  • copies all directory structure from /data on server-1 to /data on server-2
  • delete files\folders on server-2 if they have been missing from server-1 for 90 days

I am unable to find a way to do this, only instant deletion on destination if missing at source.

current rsync command is: rsync -e 'ssh -p 22' -apv --info=progress2 /data/* server-2:/data

basically looking for a retention period in the rsync options when I make a backup.

  • 1
    rsync doesn't have any way to tell how long ago a file was deleted, since it doesn't keep any history. All it knows is that the file doesn't exist now. If you want something like this, you need to do some sort of history tracking (i.e. when files were deleted) outside of rsync. – Gordon Davisson Aug 10 '19 at 21:36

To delete files on the remote directory use rsync command with the option "--delete," but you can't specify the time for delete periods.

rsync -avu --delete -e ssh /home/satish/test/a/ satish@

If you want to delete the file which is not available on the source but again wants to create a file when it available on the source, use cron to run same rsync command. Check here various examples of rsync.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.