Can rsync delete files on destination if no longer on source for X period of time?

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

1 Answer

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@10.10.10.10:/home/satish/test/z/

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.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like