Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use rsync to do backups of files and folder\

 rsync -avqz --stats --delete /media/server/ /media/Server2/

Now this deletes files while are not present on source and makes source exact copy of derstination

but my boss wants that i should delete the files only which are not present on source and are 1 week old something like

rsync -avqz --stats --delete(1 week old) /media/server/ /media/Server2/

Any ideas

share|improve this question

i would recommend to you and your boss to set up rsnapshot instead. it will give you snapshots as often and going back as far as you like.

share|improve this answer
+1 - I use a similar method (using rsync with a couple of scripts of my own based on the technique described in to maintain my backups and it works well. I keep weekly snapshots going back almost a year (and daily ones for a month) which take up surprisingly little space. I'd probably use rsnapshot but my scripts were started, some years ago, before that existed in a stable form. – David Spillett Oct 19 '10 at 10:47

Rsync does not support this behavior out of the box. You might find another tool such as rsnapshot such as Jaylen suggested to be a good move.

If you really do want to do exactly as you describe, here is what you can do.

  • First, run your rsync WITHOUT a delete. This will just copy everything over from your live data to your backup.
  • Next run the rsync again with the delete, but this time in TEST mode (-n). This will generate a list of files to BE deleted based on what has been deleted in your live data but not yet in your backups. Save this output to a file with the date.
  • Now keep those list of things to delete, but only process them a week later. Keep a queue and only process the deletion suggestions that have been in the queue for at least a week.

Alternatively, use the output of the rsync --delete -n but instead of queuing, use some other check such as the last modified date in the backup to make sure you only delete things that have not otherwise been edited inside of a week. This is not quite the behavior you asked for but would be easier to program and might suffice.

share|improve this answer

An alternative tool is rdiff-backup:, which keeps both a mirror and a configurable by date, incremental backup.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.